Skip to content

Commit a5fa233

Browse files
authored
Merge pull request #16 from bacemtayeb/dev
Release: full pipeline + evaluation + dashboard (v0.1.0)
2 parents e16ee0e + 9128e12 commit a5fa233

21 files changed

Lines changed: 1686 additions & 65 deletions

README.md

Lines changed: 175 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,198 @@ potential hallucinations.
99

1010
> Course project · MICS · Principles of Software Development (S2 2025–26).
1111
12-
## Status
12+
---
1313

14-
Scaffold. Features land via pull requests — see the open issues and `docs/`.
14+
## Contents
1515

16-
## Documentation
16+
- [What SumLens does](#what-sumlens-does)
17+
- [Hardware requirements](#hardware-requirements)
18+
- [Installation](#installation)
19+
- [Running the app](#running-the-app)
20+
- [Usage walkthrough](#usage-walkthrough)
21+
- [Interpreting the results](#interpreting-the-results)
22+
- [Exporting results](#exporting-results)
23+
- [Development](#development)
1724

18-
- [`docs/requirements.md`](docs/requirements.md) — functional / non-functional requirements, MoSCoW, user stories, traceability.
19-
- [`docs/data-model.md`](docs/data-model.md) — canonical data types.
20-
- [`docs/research-plan.md`](docs/research-plan.md) — signals, fusion, evaluation methodology.
25+
---
2126

22-
## Development
27+
## What SumLens does
28+
29+
SumLens takes a text document (pasted or PDF) and:
30+
31+
1. Summarises it locally using BART (`facebook/bart-large-cnn`) — no external API.
32+
2. Scores each summary sentence against the source using three signals:
33+
- **Signal A — Classifier:** LettuceDetect flags hallucinated tokens.
34+
- **Signal B — NLI:** DeBERTa-v3 checks whether atomic claims are entailed by the source.
35+
- **Signal C — Attribution:** Inseq integrated gradients measure how much each source span influenced each summary sentence.
36+
3. Fuses the signals into a single grounding score (0 = hallucinated, 1 = grounded).
37+
4. Labels each sentence: **grounded**, **weakly grounded**, or **hallucinated**.
38+
5. Displays the result as a colour-coded summary with click-to-highlight source spans.
39+
40+
---
41+
42+
## Hardware requirements
43+
44+
The pipeline loads three large transformer models. Running on CPU is supported but
45+
can take several minutes per document.
2346

24-
Requires Python 3.11+.
47+
| Setup | RAM | VRAM | Expected time |
48+
|-------|-----|------|---------------|
49+
| GPU (recommended) | 16 GB | 8 GB+ | ~30–60 s |
50+
| CPU-only | 16 GB || 3–10 min |
51+
52+
Models are downloaded automatically from Hugging Face on first run (~4 GB total).
53+
No paid API key is required.
54+
55+
---
56+
57+
## Installation
58+
59+
Requires **Python 3.11+** and **Git**.
2560

2661
```bash
62+
git clone https://github.com/bacemtayeb/SumLens.git
63+
cd SumLens
2764
python3.11 -m venv .venv
65+
66+
# Windows
67+
.venv\Scripts\activate
68+
# macOS / Linux
2869
source .venv/bin/activate
70+
2971
pip install -e ".[dev]"
3072
python -m nltk.downloader punkt punkt_tab
3173
```
3274

33-
### Quality gate (CI enforces this on every PR)
75+
---
76+
77+
## Running the app
78+
79+
```bash
80+
python app.py
81+
```
82+
83+
Gradio prints a local URL, e.g.:
84+
85+
```
86+
Running on local URL: http://127.0.0.1:7860
87+
```
88+
89+
Open that URL in your browser. The app runs entirely on your machine — no data
90+
leaves your computer.
91+
92+
---
93+
94+
## Usage walkthrough
95+
96+
### Step 1 — Load a document
97+
98+
You have two options:
99+
100+
- **Paste text** — click the *Paste text* box and type or paste your document
101+
(up to 10 000 words).
102+
- **Upload a PDF** — click *or upload PDF* and select a file (up to 5 MB).
103+
104+
If you provide both, the PDF takes priority.
105+
106+
### Step 2 — Analyse
107+
108+
Click the **Analyse** button. The button is disabled while the pipeline runs
109+
(typically 30–60 s on GPU, longer on CPU). Both export buttons appear once
110+
analysis is complete.
111+
112+
### Step 3 — Read the summary
113+
114+
The right panel shows the summary with each sentence colour-coded:
115+
116+
| Colour | Label | Meaning |
117+
|--------|-------|---------|
118+
| Green | Grounded | Well-supported by the source |
119+
| Orange | Weakly grounded | Partial support; treat with caution |
120+
| Red | Hallucinated | Low support; likely fabricated or distorted |
121+
122+
### Step 4 — Trace a sentence to the source
123+
124+
Click any summary sentence. The left panel highlights (in yellow) the source
125+
sentences most strongly attributed to it by the model. Click a different summary
126+
sentence to switch the highlight.
127+
128+
### Step 5 — Adjust the thresholds (optional)
129+
130+
Two sliders let you change the decision boundaries without re-running the model:
131+
132+
- **τ hallucinated** (default 0.30) — sentences with a grounding score *below*
133+
this value are labelled hallucinated.
134+
- **τ grounded** (default 0.70) — sentences with a grounding score *above* this
135+
value are labelled grounded. Anything in between is weakly grounded.
136+
137+
Move either slider and the summary colours update instantly.
138+
139+
---
140+
141+
## Interpreting the results
142+
143+
- The **grounding score** (0–1) represents how strongly the model believes a
144+
summary sentence is supported by the source. It is not a probability in a strict
145+
statistical sense — treat it as a relative risk indicator.
146+
- A **hallucinated** label does not guarantee the sentence is wrong; it means the
147+
model could not find sufficient evidence in the source text. Always cross-check
148+
flagged sentences manually.
149+
- The **signal breakdown** (JSON export) shows the individual classifier, NLI, and
150+
attribution scores for each sentence, which can help diagnose *why* a sentence
151+
was flagged.
152+
153+
---
154+
155+
## Exporting results
156+
157+
Two download buttons appear after analysis:
158+
159+
- **Export JSON** — downloads the full `AnalysisResult` as a JSON file. The schema
160+
matches `sumlens/types.py` and round-trips via `AnalysisResult.model_validate()`.
161+
- **Export PDF** — downloads a human-readable PDF containing the colour-annotated
162+
summary, a legend, and a per-sentence signal-scores table.
163+
164+
---
165+
166+
## Development
167+
168+
### Quality gate (CI enforces on every PR)
34169

35170
```bash
36-
ruff check . && mypy sumlens tests && pytest -q --cov=sumlens --cov-fail-under=70
171+
ruff check . && mypy sumlens tests app.py && pytest -q --cov=sumlens --cov-fail-under=70
37172
```
38173

39-
Lint (ruff), type-check (mypy, strict), and tests with a ≥70% coverage gate must
40-
pass before any PR is merged to `main`.
174+
Lint (ruff), strict type-check (mypy), and tests with a ≥ 70 % coverage gate
175+
must pass before any PR is merged.
176+
177+
### Project layout
178+
179+
```
180+
sumlens/
181+
types.py # canonical data model (AnalysisResult, etc.)
182+
ingest.py # PDF / text → Document
183+
summarise.py # BART summarisation
184+
signals/
185+
classifier.py # Signal A — LettuceDetect
186+
nli.py # Signal B — DeBERTa NLI
187+
attribution.py # Signal C — Inseq attribution
188+
fuse.py # logistic-regression fusion + Platt calibration
189+
pipeline.py # orchestrates ingest → summarise → signals → fuse
190+
app.py # Gradio UI entry point
191+
tests/ # pytest suite (all models mocked)
192+
docs/ # requirements, data model, research plan
193+
```
194+
195+
### Documentation
196+
197+
- [`docs/requirements.md`](docs/requirements.md) — functional / non-functional requirements, MoSCoW, user stories, traceability.
198+
- [`docs/data-model.md`](docs/data-model.md) — canonical data types and JSON schema.
199+
- [`docs/research-plan.md`](docs/research-plan.md) — signals, fusion, evaluation methodology.
200+
- [`docs/mockup.html`](docs/mockup.html) — static HTML wireframe of the two-panel dashboard UI (open in any browser).
201+
- [`docs/use-case.puml`](docs/use-case.puml) — PlantUML use-case diagram (UC-01 "Verify a Summary").
202+
203+
---
41204

42205
## License
43206

0 commit comments

Comments
 (0)