Skip to content

Commit e8cafec

Browse files
authored
Merge pull request #34 from KRLabsOrg/code_hallucination
Code hallucination
2 parents b302fdb + 1d08224 commit e8cafec

63 files changed

Lines changed: 6847 additions & 268 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/docs.yml‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Deploy Documentation
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'docs/**'
8+
- 'mkdocs.yml'
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
pages: write
14+
id-token: write
15+
16+
concurrency:
17+
group: pages
18+
cancel-in-progress: false
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.12'
28+
- run: pip install mkdocs-material "mkdocstrings[python]>=0.24"
29+
- run: pip install -e .
30+
- run: mkdocs build
31+
- uses: actions/upload-pages-artifact@v3
32+
with:
33+
path: site/
34+
35+
deploy:
36+
needs: build
37+
runs-on: ubuntu-latest
38+
environment:
39+
name: github-pages
40+
url: ${{ steps.deployment.outputs.page_url }}
41+
steps:
42+
- id: deployment
43+
uses: actions/deploy-pages@v4

‎.github/workflows/python-tests.yml‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
name: Python Tests
22

33
on:
4+
push:
5+
branches: [main]
46
pull_request:
5-
branches: [ main ]
7+
branches: [main]
68

79
jobs:
810
test:
@@ -12,24 +14,24 @@ jobs:
1214
python-version: ["3.12"]
1315

1416
steps:
15-
- uses: actions/checkout@v3
16-
17+
- uses: actions/checkout@v4
18+
1719
- name: Set up Python ${{ matrix.python-version }}
18-
uses: actions/setup-python@v4
20+
uses: actions/setup-python@v5
1921
with:
2022
python-version: ${{ matrix.python-version }}
2123
cache: 'pip'
22-
24+
2325
- name: Install dependencies
2426
run: |
2527
python -m pip install --upgrade pip
2628
pip install -e ".[dev]"
27-
29+
2830
- name: Lint with ruff
2931
run: |
30-
ruff format --check --diff .
31-
ruff check --select I .
32-
32+
ruff format --check --diff lettucedetect/ tests/
33+
ruff check lettucedetect/ tests/ --extend-exclude lettucedetect/integrations/
34+
3335
- name: Test with pytest
3436
run: |
35-
pytest tests/test_inference_pytest.py -v
37+
pytest tests/test_inference_pytest.py -v

‎.gitignore‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ cython_debug/
170170
# PyPI configuration file
171171
.pypirc
172172

173+
# macOS
174+
.DS_Store
175+
173176
# data/
174177
data/
175178

@@ -178,4 +181,5 @@ output/
178181
temp/
179182

180183
# cache/
181-
lettucedetect/cache/
184+
lettucedetect/cache/
185+
testing/

‎docs/EUROBERT.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 🥬 LettuceDetect Goes Multilingual: Fine-tuning EuroBERT on Synthetic RAGTruth Translations
22

33
<p align="center">
4-
<img src="https://github.com/KRLabsOrg/LettuceDetect/blob/feature/cn_llm_eval/assets/lettuce_detective_multi.png?raw=true" alt="LettuceDetect Multilingual Task Force" width="520"/>
4+
<img src="https://github.com/KRLabsOrg/LettuceDetect/blob/main/assets/lettuce_detective_multi.png?raw=true" alt="LettuceDetect Multilingual Task Force" width="520"/>
55
<br>
66
<em>Expanding hallucination detection across languages for RAG pipelines.</em>
77
</p>

‎docs/EVALUATION.md‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎docs/api/datasets.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Datasets
2+
3+
## HallucinationSample
4+
5+
::: lettucedetect.datasets.hallucination_dataset.HallucinationSample
6+
7+
## HallucinationData
8+
9+
::: lettucedetect.datasets.hallucination_dataset.HallucinationData
10+
11+
## HallucinationDataset
12+
13+
::: lettucedetect.datasets.hallucination_dataset.HallucinationDataset

‎docs/api/detectors.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Detectors
2+
3+
## Factory
4+
5+
::: lettucedetect.detectors.factory.make_detector
6+
7+
## Base Detector
8+
9+
::: lettucedetect.detectors.base.BaseDetector
10+
11+
## Transformer Detector
12+
13+
::: lettucedetect.detectors.transformer.TransformerDetector

‎docs/api/inference.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Inference
2+
3+
The main entry point for hallucination detection.
4+
5+
::: lettucedetect.models.inference.HallucinationDetector

‎docs/api/training.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Training
2+
3+
## Trainer
4+
5+
::: lettucedetect.models.trainer.Trainer
6+
7+
## Evaluator
8+
9+
::: lettucedetect.models.evaluator

‎docs/benchmarks.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Benchmarks
2+
3+
## RAGTruth (English)
4+
5+
Evaluated on the [RAGTruth](https://aclanthology.org/2024.acl-long.585/) test set. This benchmark measures how well models detect hallucinations in LLM-generated text across QA, summarization, and data-to-text tasks.
6+
7+
### Example-Level Detection
8+
9+
Binary classification: does the answer contain any hallucination?
10+
11+
| Model | Type | Overall F1 |
12+
|-------|------|-----------|
13+
| GPT-4 | LLM (zero-shot) | 63.4% |
14+
| Luna | Encoder | 65.4% |
15+
| **lettucedetect-base-v1** | **Encoder (149M)** | **76.8%** |
16+
| Llama-2-13B (fine-tuned) | LLM | 78.7% |
17+
| **lettucedetect-large-v1** | **Encoder (395M)** | **79.2%** |
18+
| RAG-HAT (Llama-3-8B) | LLM | 83.9% |
19+
20+
### Span-Level Detection
21+
22+
LettuceDetect achieves state-of-the-art span-level results among models that report this metric, outperforming fine-tuned Llama-2-13B. Span-level evaluation measures how precisely the model can locate the exact hallucinated text within an answer.
23+
24+
## What These Numbers Mean
25+
26+
- **Example F1** — Can the model tell if an answer has *any* hallucination? Higher is better.
27+
- **Span F1** — Can the model point to *exactly which parts* are hallucinated? This is the harder task and where LettuceDetect excels relative to its size.
28+
29+
LettuceDetect models are 50-500x smaller than LLM-based detectors while achieving competitive or better accuracy.
30+
31+
## Citation
32+
33+
```bibtex
34+
@misc{Kovacs:2025,
35+
title={LettuceDetect: A Hallucination Detection Framework for RAG Applications},
36+
author={Ádám Kovács and Gábor Recski},
37+
year={2025},
38+
eprint={2502.17125},
39+
archivePrefix={arXiv},
40+
primaryClass={cs.CL},
41+
url={https://arxiv.org/abs/2502.17125},
42+
}
43+
```

0 commit comments

Comments
 (0)