Add a decision-model detector backend (Vela 2.0 first): hallucination and safety in one call

Aperta
#118 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
32/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Start with the method dispatch in lettucedetect/detectors/factory.py (make_detector, lines 18-31), which currently rejects any method other than transformer, llm and rag_fact_checker. Then read how the existing detectors return spans so the Vela output {label, start, end, text, probability} can be mapped to start, end, text, confidence. Done means HallucinationDetector(method="vela") returns spans with offsets into the answer, the optional extra is wired up, and the 0.3B model reproduces Vela's reported F1 within ±0.01 on the test set.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement help wanted

Problem

Vela 2.0 (vLLM Semantic Router × KR Labs, Apache-2.0) is a family of decision models (0.3B encoder; 0.8B, 4B and 9B decoders) that answer typed questions about a request, a context and an answer in one call. One of those questions is a hallucination span question: "Which spans of the answer are not supported by the context?", returned as spans with character offsets and probabilities. The same call can also return PII spans, prompt-attack and safety scores, and routing decisions.

Vela's own evaluation reports hallucination results on the same 10,698-example test set and on RAGTruth that our models use (EVALUATION.md):

Model Hallucination, 10,698 examples (F1) RAGTruth (F1)
Vela 2.0 0.3B (encoder, runs on CPU) 0.848 0.706
Vela 2.0 4B 0.874 0.770
Vela 2.0 9B 0.885 0.774
lettucedect-v2-mmbert-base 0.869 0.743
lettucedect-v2-qwen-2b 0.921 0.817

LettuceDetect cannot use these models today. Supporting them gives users a detector that runs PII and safety checks in the same pass, and a CPU option (0.3B, 8,192 tokens) between the encoder and generative lines.

Current behavior

  • lettucedetect/detectors/factory.py:18-31: make_detector knows transformer, llm and rag_fact_checker; anything else raises ValueError.
  • Vela is loaded with AutoModel.from_pretrained(..., trust_remote_code=True) and called with m.system_one(state=..., questions=...), or served over HTTP as POST /v1/systemone by the vela2_serve.py script in each model repo. Its interface is the typed-question SystemOne format, so one backend can serve any model that speaks it.

Acceptance criteria

  • HallucinationDetector(method="vela", model_path="vllm-sr/Vela-2.0-0.3B") runs in-process; method="vela" with base_url= and an API key calls a SystemOne server instead.
  • predict(..., output_format="spans") returns LettuceDetect spans (start, end, text, confidence) mapped from Vela's {label, start, end, text, probability}, with offsets into the answer. min_confidence filters on that probability.
  • output_format="tokens" either works or raises a clear error that names the supported format.
  • No new required dependency: Vela's runtime needs (recent transformers, optional flash-linear-attention) sit behind an optional extra, consistent with #69.
  • A short evaluation note reproduces Vela's reported F1 on the 10,698-example test set with the 0.3B encoder within ±0.01, using LettuceDetect's own evaluator.
  • Docs: one section on when to choose Vela (one pass for hallucination plus PII and safety, CPU encoder) versus the LettuceDetect models (best hallucination F1, typed categories).

Follow-ups, not in this issue: a --vela-model mode for the Claude Code hook, and passing LettuceDetect taxonomy labels as Vela span criteria.

Start here

grep -n "method ==" lettucedetect/detectors/factory.py
python -c "from transformers import AutoModel; m = AutoModel.from_pretrained('vllm-sr/Vela-2.0-0.3B', trust_remote_code=True); print(m.system_one(state={'request': 'When does it ship?', 'source': 'Ships Friday.', 'answer': 'Ships Monday.'}, questions={'halu': {'type': 'span', 'instructions': 'Which spans of the answer are not supported by the context?', 'criteria': {'unsupported': 'a claim not supported by the context'}}}))"
Lingua principale
Python
Stelle
615
Fork
60
Merge medio
1g 8h
PR unite (30g)
10

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di KRLabsOrg/LettuceDetect

Tutte le issue di KRLabsOrg/LettuceDetect

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.