Metadata-Version: 2.5
Name: vigie-claims-extract
Version: 0.1.1
Summary: Extract checkable claims from short videos and video-to-context records, for fact-checking.
Project-URL: Homepage, https://github.com/wani-ham/youtube-shorts-to-claims
Project-URL: Repository, https://github.com/wani-ham/youtube-shorts-to-claims
Project-URL: Issues, https://github.com/wani-ham/youtube-shorts-to-claims/issues
Author: Taewan Ham
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: claim-extraction,claims,fact-checking,llm,misinformation,video-to-text,youtube-shorts
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: <3.15,>=3.12
Requires-Dist: anthropic<3,>=2.12
Requires-Dist: openai<4,>=3.57
Requires-Dist: pydantic<3,>=2.14
Requires-Dist: python-dotenv<2,>=1.2
Requires-Dist: rapidfuzz<4,>=3.14
Provides-Extra: dev
Requires-Dist: pytest<10,>=9; extra == 'dev'
Provides-Extra: video
Requires-Dist: video-to-context<0.6,>=0.5.1; extra == 'video'
Description-Content-Type: text/markdown

# vigie-claims-extract: Extract Claims from Youtube Shorts

Extract claims from a [video-to-context](https://github.com/wani-ham/youtube-shorts-to-text-context) record (`record.json` or `record.md`). This repo is part of Vigie's fact-checking pipeline: this step finds claims from the text context of a youtube shorts.

## Contents

- [Example output](#example-output)
- [Install](#install)
- [Choose a model](#choose-a-model)
- [Usage](#usage)
- [How it works](#how-it-works)
- [Output: `claims.json`](#output-claimsjson)
- [Model](#model)
- [Development](#development)

## Example Output

A real Short posted by the channel "The Democrats": [youtube.com/shorts/erbY3vW7xtI](https://www.youtube.com/shorts/erbY3vW7xtI). Part of its record from video-to-context:

```text
[AUDIO 00:00–00:03] The question ultimately is do you want to drive on good roads or would you rather have a billionaire
[ON-SCREEN:HEADLINE 00:00–00:47] EL-SAYED EMBARRASSES FOX NEWS HOST OVER MIKE ROGERS DEBATE
[AUDIO 00:03–00:06] make a second billion? That's what Mike Rogers wants. That's what Donald Trump wants. Apparently
[ON-SCREEN 00:05–00:05] Mike Rogers wants.
[AUDIO 00:06–00:09] that's what you want. I think the people in Michigan want something different. They want
[AUDIO 00:09–00:15] good roads and good schools. So you're saying Beyonce who just became a billionaire. She has to
...
```

Part of the `claim_list.md` that `claude-haiku-5-5` produced from it (10 claims in all):

```markdown
### c1. El-Sayed appeared in a debate on Fox News against Mike Rogers' side.

- **Quote:** “EL-SAYED EMBARRASSES FOX NEWS HOST OVER MIKE ROGERS DEBATE”
- **Type:** `event`, explicit
- **Claimant:** The Democrats
- **Where:** on_screen:headline, 00:00–00:47 (units h1)
- **Entities:** El-Sayed (person), Fox News (organization), Mike Rogers (person)
- **Notes:** Claimant is the uploader, The Democrats, as the headline is on their video. ... Loaded word EMBARRASSES is left out of the claim.

### c2. Mike Rogers wants a billionaire to make a second billion.

- **Quote:** “That's what Mike Rogers wants”
- **Type:** `other`, explicit
- **Claimant:** unidentified speaker
- **Where:** audio, 00:04–00:05 (units a2)
- **Entities:** Mike Rogers (person)
- **Notes:** 'That's' resolved from a1: the billionaire making a second billion.

### c3. Donald Trump wants a billionaire to make a second billion.

- **Quote:** “That's what Donald Trump wants”
- **Where:** audio, 00:05–00:06 (units a3)
...

### c4. Beyonce has just become a billionaire.

- **Quote:** “Beyonce who just became a billionaire”
- **Type:** `event`, explicit
- **Claimant:** unidentified speaker
- **Where:** audio, 00:11–00:15 (units a7)
- **Entities:** Beyonce (person)

### c8. The speaker thinks Beyonce would be happy to contribute back to the public schools she attended.

- **Quote:** “Beyonce I think would be happy to be able to contribute back”
- **Type:** `other`, explicit, not checkable
- **Notes:** Expressed as the speaker's opinion ('I think') about another person's feelings; no evidence could settle her private happiness.
...
```

What the example shows:

- **References are resolved.** "That's what Mike Rogers wants" only makes sense with the sentence before it, so the claim spells out what "that" means.
- **Similar sentences stay separate.** c2 and c3 differ only in who is named, so they are kept as two claims, each with its own quote.
- **Framing is left out.** The headline's "EMBARRASSES" is a characterisation, not a fact, so the claim keeps only the event.
- **The claimant follows the source.** The headline is the uploader's, and the speakers are "unidentified speaker" because the record never names them on screen. Nobody is identified from how they look.
- **Opinions are marked.** c8 is kept but flagged as not checkable.
- **Repeated captions are dropped.** The on-screen "Mike Rogers wants." repeats the speech, so it gives no claim of its own.


## Install

You need Python 3.12–3.14. [uv](https://docs.astral.sh/uv/) is the easiest way:

```bash
uv tool install --python 3.12 vigie-claims-extract            # claims from record files
uv tool install --python 3.12 "vigie-claims-extract[video]"   # also from YouTube links (needs ffmpeg)
```

Or with pip, inside a Python 3.12+ environment:

```bash
pip install vigie-claims-extract
pip install "vigie-claims-extract[video]"
```

The `video` extra brings in [video-to-context](https://github.com/wani-ham/youtube-shorts-to-text-context), which needs **ffmpeg** (`brew install ffmpeg` on macOS) and about 5 GB of disk for Whisper and the video tools.

## Choose a model

Download the settings template and pick one option in it: Claude, Gemini, OpenAI, Mistral, OpenRouter, or Ollama on your own machine.

```bash
mkdir -p ~/.vigie-claims-extract
curl -o ~/.vigie-claims-extract/.env https://raw.githubusercontent.com/wani-ham/youtube-shorts-to-claims/main/.env.example
```

Settings are read from `./.env` first, then `~/.vigie-claims-extract/.env`. Real environment variables always win.

## Usage

```bash
# A YouTube video or Short (with the video extra)
vigie-claims-extract "https://www.youtube.com/shorts/VIDEO_ID"

# A record you already have from video-to-context
vigie-claims-extract store/<media_id>/record.json

# Segmentation only, no model call
vigie-claims-extract record.md --units-only

# Keep records somewhere else, or process a link again
vigie-claims-extract "https://youtu.be/VIDEO_ID" --store records --force
```

From a link, the video record is saved in `store/<media_id>/` and reused next time. `claims.json` and `claim_list.md` are written next to the record. Vision settings (`VISION_*`) for the video step are read from `./.env` or `~/.video-to-context/.env`, as in video-to-context itself. Model settings are checked before any download starts.

The command exits with `0` when every step succeeded, `1` when a model step failed but a partial result was written, and `2` for bad settings or input.

## How it works

| Step | Code or LLM | What it does |
| --- | --- | --- |
| 1. Load | code | Reads JSON or MD into one shape. (Result from [here](https://github.com/wani-ham/youtube-shorts-to-text-context)) |
| 2. Segment | code | Re-cuts speech into sentences (Whisper segments break at pauses). Drops burned-in captions that repeat the speech, keeps headlines and other on-screen text, keeps the lead of the post caption and sets channel boilerplate aside. Logos are context; `VISUAL` lines are never quotable. |
| 3. Select and type | LLM, low effort | Labels every unit: `factual_claim`, `mixed`, `opinion`, `call_to_action`, `other`. |
| 4. Decompose | LLM | For selected units only: resolves references, splits into atomic claims, writes each in the source language and English, with an exact quote, claim type, entities and claimant. Ambiguous units are returned as `cannot_disambiguate` instead of guessed. |
| 5. Implicit claims | LLM | What the video presents through framing: outlet branding, endorsements, setting. Each needs an observed basis (a unit, a logo, the uploader or sponsor); claims resting only on the vision model's interpretation are rejected. |
| 6. Validate | code | Rejects any claim whose quote is not in its source text, repairs wrong unit ids, flags entities not found in the record, merges duplicates (speech and caption saying the same thing), ranks by claim type and caps at 10. |

A failed LLM step is recorded in `errors` and the rest of the result is kept.

## Output: `claims.json`

`units` (what can be quoted), `dropped_text` (what was set aside and why), `unit_labels`, `claims`, `rejected` (with reasons) and `errors`. Each claim has `text`, `text_en`, `quote`, `unit_ids`, `source`, `start`/`end`, `explicit`, `claim_type`, `entities`, `claimant`, `checkable`, `priority`, `notes` and `warnings`. `claim_type` routes the claim to a verification method later.

A readable `claim_list.md` is written next to it, with each claim, its quote, type, claimant and time, then the rejected claims and errors.


## Model

Default `claude-haiku-5-5` through the Anthropic SDK, with structured outputs and the server-side refusal fallback enabled. Set `CLAIMS_BASE_URL` and `CLAIMS_MODEL` (and `CLAIMS_API_KEY` if needed) for any OpenAI-compatible server: Gemini, OpenAI, Mistral, OpenRouter, or Ollama on your own machine. `.env.example` has a preset for each. `CLAIMS_TIMEOUT_S` (default 180) sets how long to wait for each call, and `CLAIMS_REASONING_EFFORT` is passed through to OpenAI-compatible servers; slow local models usually need both.

## Development

```bash
git clone https://github.com/wani-ham/youtube-shorts-to-claims.git && cd youtube-shorts-to-claims
uv sync --extra dev --extra video
uv run pytest
```

To release: raise `__version__` in `vigie_claims_extract/__init__.py`, then `uv build` and `uv publish`.

Tests run on a real record (`tests/samples/fox_canon_law.*`) with a fake model, so they need no API key.
