lettucedect-v2-taxonomy-head: span typing head for the encoder cascade
Browse files- .gitattributes +2 -0
- README.md +75 -0
- config.json +78 -0
- labels.json +22 -0
- lettuce_code.png +3 -0
- model.safetensors +3 -0
- tokenizer.json +3 -0
- tokenizer_config.json +25 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
lettuce_code.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
- de
|
| 6 |
+
- fr
|
| 7 |
+
- es
|
| 8 |
+
- it
|
| 9 |
+
- pl
|
| 10 |
+
- zh
|
| 11 |
+
tags:
|
| 12 |
+
- hallucination-detection
|
| 13 |
+
- span-classification
|
| 14 |
+
- taxonomy
|
| 15 |
+
- rag
|
| 16 |
+
- code
|
| 17 |
+
base_model: jhu-clsp/mmBERT-base
|
| 18 |
+
datasets:
|
| 19 |
+
- KRLabsOrg/lettucedetect-code-hallucination
|
| 20 |
+
- KRLabsOrg/lettucedetect-prose-hallucination
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+

|
| 24 |
+
|
| 25 |
+
# lettucedect-v2-taxonomy-head: Span Typing Head (encoder cascade)
|
| 26 |
+
|
| 27 |
+
## Overview
|
| 28 |
+
|
| 29 |
+
`lettucedect-v2-taxonomy-head` **types** a hallucinated span — it does not find spans. It is a
|
| 30 |
+
label-conditioned **mmBERT-base bi-encoder** that, given a span a binary detector already
|
| 31 |
+
located, assigns a hallucination **category** and **subcategory** by embedding the span and
|
| 32 |
+
taking the nearest taxonomy-label *description* (cosine). Paired with the binary encoder
|
| 33 |
+
`lettucedect-v2-mmbert-base`, it forms a **fully-encoder typed detector** — detection + typing
|
| 34 |
+
at encoder cost, no generative model.
|
| 35 |
+
|
| 36 |
+
- **Taxonomy:** 3 categories (contradiction, fabricated_reference, unsupported_addition) × 13 subcategories.
|
| 37 |
+
- **Stage-B only:** run a binary detector (e.g. `lettucedect-v2-mmbert-base`) first, then this head types each span.
|
| 38 |
+
- For detection **and** typing in a single pass, see the generative `lettucedect-v2-qwen-2b`.
|
| 39 |
+
|
| 40 |
+
## Usage (cascade, via lettucedetect)
|
| 41 |
+
|
| 42 |
+
```python
|
| 43 |
+
from lettucedetect.models.inference import HallucinationDetector
|
| 44 |
+
|
| 45 |
+
det = HallucinationDetector(
|
| 46 |
+
method="transformer",
|
| 47 |
+
model_path="KRLabsOrg/lettucedect-v2-mmbert-base", # binary detector (finds spans)
|
| 48 |
+
taxonomy_head="KRLabsOrg/lettucedect-v2-taxonomy-head", # this head (types them)
|
| 49 |
+
)
|
| 50 |
+
spans = det.predict(context=[context], question=question, answer=answer, output_format="spans")
|
| 51 |
+
# [{"start": ..., "end": ..., "text": "...", "category": "contradiction", "subcategory": "numerical"}]
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
## Performance
|
| 55 |
+
|
| 56 |
+
- **Typing accuracy (given gold spans):** category 0.82 / subcategory 0.64 (validation).
|
| 57 |
+
- **End-to-end cascade** (binary detector → this head), char-overlap typed-F1 on the unified
|
| 58 |
+
test set: **0.461** (subcategory-gated 0.315). The generative `lettucedect-v2-qwen-2b` is
|
| 59 |
+
higher (typed-F1 0.585 / 0.468) and types in one pass; this cascade is the option when you
|
| 60 |
+
want typed spans from a small, fast encoder stack.
|
| 61 |
+
|
| 62 |
+
**Scope note.** Typing is *supervised* over the taxonomy labels seen in training; the head does
|
| 63 |
+
**not** transfer zero-shot to a held-out subcategory from its description alone (binary-detection
|
| 64 |
+
AUC ≈ chance for an unseen label). Train it on every subcategory you intend to emit.
|
| 65 |
+
|
| 66 |
+
## Citing
|
| 67 |
+
|
| 68 |
+
```bibtex
|
| 69 |
+
@article{Kovacs2025LettuceDetect,
|
| 70 |
+
title={LettuceDetect: A Hallucination Detection Framework for RAG Applications},
|
| 71 |
+
author={Kovács, Ádám and Recski, Gábor},
|
| 72 |
+
journal={arXiv preprint arXiv:2502.17125},
|
| 73 |
+
year={2025}
|
| 74 |
+
}
|
| 75 |
+
```
|
config.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"ModernBertModel"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 2,
|
| 8 |
+
"classifier_activation": "gelu",
|
| 9 |
+
"classifier_bias": false,
|
| 10 |
+
"classifier_dropout": 0.0,
|
| 11 |
+
"classifier_pooling": "mean",
|
| 12 |
+
"cls_token_id": 1,
|
| 13 |
+
"decoder_bias": true,
|
| 14 |
+
"deterministic_flash_attn": false,
|
| 15 |
+
"dtype": "bfloat16",
|
| 16 |
+
"embedding_dropout": 0.0,
|
| 17 |
+
"eos_token_id": 1,
|
| 18 |
+
"global_attn_every_n_layers": 3,
|
| 19 |
+
"gradient_checkpointing": false,
|
| 20 |
+
"hidden_activation": "gelu",
|
| 21 |
+
"hidden_size": 768,
|
| 22 |
+
"initializer_cutoff_factor": 2.0,
|
| 23 |
+
"initializer_range": 0.02,
|
| 24 |
+
"intermediate_size": 1152,
|
| 25 |
+
"layer_norm_eps": 1e-05,
|
| 26 |
+
"layer_types": [
|
| 27 |
+
"full_attention",
|
| 28 |
+
"sliding_attention",
|
| 29 |
+
"sliding_attention",
|
| 30 |
+
"full_attention",
|
| 31 |
+
"sliding_attention",
|
| 32 |
+
"sliding_attention",
|
| 33 |
+
"full_attention",
|
| 34 |
+
"sliding_attention",
|
| 35 |
+
"sliding_attention",
|
| 36 |
+
"full_attention",
|
| 37 |
+
"sliding_attention",
|
| 38 |
+
"sliding_attention",
|
| 39 |
+
"full_attention",
|
| 40 |
+
"sliding_attention",
|
| 41 |
+
"sliding_attention",
|
| 42 |
+
"full_attention",
|
| 43 |
+
"sliding_attention",
|
| 44 |
+
"sliding_attention",
|
| 45 |
+
"full_attention",
|
| 46 |
+
"sliding_attention",
|
| 47 |
+
"sliding_attention",
|
| 48 |
+
"full_attention"
|
| 49 |
+
],
|
| 50 |
+
"local_attention": 128,
|
| 51 |
+
"mask_token_id": 4,
|
| 52 |
+
"max_position_embeddings": 8192,
|
| 53 |
+
"mlp_bias": false,
|
| 54 |
+
"mlp_dropout": 0.0,
|
| 55 |
+
"model_type": "modernbert",
|
| 56 |
+
"norm_bias": false,
|
| 57 |
+
"norm_eps": 1e-05,
|
| 58 |
+
"num_attention_heads": 12,
|
| 59 |
+
"num_hidden_layers": 22,
|
| 60 |
+
"pad_token_id": 0,
|
| 61 |
+
"position_embedding_type": "sans_pos",
|
| 62 |
+
"rope_parameters": {
|
| 63 |
+
"full_attention": {
|
| 64 |
+
"rope_theta": 160000,
|
| 65 |
+
"rope_type": "default"
|
| 66 |
+
},
|
| 67 |
+
"sliding_attention": {
|
| 68 |
+
"rope_theta": 160000,
|
| 69 |
+
"rope_type": "default"
|
| 70 |
+
}
|
| 71 |
+
},
|
| 72 |
+
"sep_token_id": 1,
|
| 73 |
+
"sparse_pred_ignore_index": -100,
|
| 74 |
+
"sparse_prediction": false,
|
| 75 |
+
"tie_word_embeddings": true,
|
| 76 |
+
"transformers_version": "5.12.0",
|
| 77 |
+
"vocab_size": 256000
|
| 78 |
+
}
|
labels.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"category": {
|
| 3 |
+
"contradiction": "conflicts with the context (a wrong value, number, date, name, or relationship)",
|
| 4 |
+
"fabricated_reference": "an entity, name, identifier, or section that is absent from the context",
|
| 5 |
+
"unsupported_addition": "a claim, detail, or behavior the context never states"
|
| 6 |
+
},
|
| 7 |
+
"subcategory": {
|
| 8 |
+
"entity": "a wrong or invented name, entity, or object",
|
| 9 |
+
"temporal": "an incorrect date, time, duration, or ordering",
|
| 10 |
+
"numerical": "an incorrect number, quantity, or amount",
|
| 11 |
+
"value": "a wrong value, setting, or attribute value",
|
| 12 |
+
"relational": "an incorrect relationship or association between things",
|
| 13 |
+
"identifier": "an invented identifier or name not found in the context",
|
| 14 |
+
"section": "a reference to a section, part, or location that does not exist",
|
| 15 |
+
"attribute": "an invented or incorrect attribute or property",
|
| 16 |
+
"claim": "an added factual claim the context does not support",
|
| 17 |
+
"behavior": "an added or changed action or behavior the context never states",
|
| 18 |
+
"elaboration": "extra detail or elaboration beyond what the context supports",
|
| 19 |
+
"subjective": "an unsupported subjective or evaluative statement",
|
| 20 |
+
"unspecified": "unsupported, with no more specific subtype"
|
| 21 |
+
}
|
| 22 |
+
}
|
lettuce_code.png
ADDED
|
Git LFS Details
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a700e36913f07495ce43b3d8c7c3c1a2f5e239ba9c78f7b35d9239e1f8b9e1fd
|
| 3 |
+
size 613892480
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:becd1e4f4de2611317d0a5d5366a7cf8b5e56560ebe43ccab753198318927bcf
|
| 3 |
+
size 34363442
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "<bos>",
|
| 4 |
+
"clean_up_tokenization_spaces": false,
|
| 5 |
+
"cls_token": "<bos>",
|
| 6 |
+
"eos_token": "<eos>",
|
| 7 |
+
"extra_special_tokens": [
|
| 8 |
+
"<start_of_turn>",
|
| 9 |
+
"<end_of_turn>"
|
| 10 |
+
],
|
| 11 |
+
"is_local": false,
|
| 12 |
+
"local_files_only": false,
|
| 13 |
+
"mask_token": "<mask>",
|
| 14 |
+
"model_input_names": [
|
| 15 |
+
"input_ids",
|
| 16 |
+
"attention_mask"
|
| 17 |
+
],
|
| 18 |
+
"model_max_length": 8192,
|
| 19 |
+
"pad_token": "<pad>",
|
| 20 |
+
"padding_side": "right",
|
| 21 |
+
"sep_token": "<eos>",
|
| 22 |
+
"spaces_between_special_tokens": false,
|
| 23 |
+
"tokenizer_class": "TokenizersBackend",
|
| 24 |
+
"unk_token": "<unk>"
|
| 25 |
+
}
|