LLM-based sentiment analysis for the Binärgewitter
podcast. Reads diarized speech transcripts (*-speech.json), scores each host
on a configurable set of axes (e.g. lustig vs. ernst, AI gut vs. AI
schlecht), and writes a per-episode sidecar (*-sentiment.json) next to the
input.
The pipeline:
- Chunk — group transcript segments by speaker, split into LLM-sized blocks (token budget per chunk).
- Score — one LLM call per chunk returns a JSON object with a number
0..10per axis. - Aggregate — per-host editorial weighting: short interjections boosted, long neutral monologues de-weighted (5 is "boring").
- Overall — one extra LLM call per episode produces an episode-level score using the per-host aggregates plus a handful of original quotes.
Two backends ship today:
claude— shells out to theclaudeCLI (subscription quota, not the API).llamacpp— POSTs to any OpenAI-compatible endpoint (llama.cpp, vLLM, …).
# build
nix build .
# score a single episode with the claude CLI backend
nix run . -- speech/2019-03-28.Binaergewitter.Talk.227-speech.json --backend claude
# or all episodes in ./speech (default when no PATH given)
nix run .
# dev shell with ruff / ty / mypy / pytest
nix developnix flake check runs ruff format, ruff check, ty check, pytest, plus the
package build.
nix run .#summary -- speech/2019-03-28.Binaergewitter.Talk.227-sentiment.json
nix run .#summary -- speech/2019-03-28.Binaergewitter.Talk.227-sentiment.json --barResolves axis IDs to their low <-> high labels from sentiments.yaml. The
script is also installed via pip as bgt-sentiment-summary. PATH may be either
the *-sentiment.json sidecar or its matching *-speech.json.
pip install -e .
bgt-sentiment speech/*.json --backend claudePython 3.13 required.
bgt-sentiment [PATH ...] [options]
PATH is a *-speech.json file, a directory (recursed for *-speech.json), or a
shell glob. With no PATH, defaults to ./speech.
Options:
| flag | meaning |
|---|---|
--backend {claude,llamacpp} |
Override backend.default from config.toml |
--sentiments PATH |
Axis spec YAML (default sentiments.yaml) |
--config PATH |
App config TOML (default config.toml) |
--files GLOB ... |
Restrict to filenames matching one of these globs |
--axes id1,id2 |
Only score these axis IDs |
--update |
Only compute axes missing from the existing sidecar |
--force |
Overwrite existing sidecar entirely |
--dry-run |
Print plan, no LLM calls |
--update and --force are mutually exclusive.
Defines the scoring axes. Each axis has an id, a low and high label, and
a free-form description fed verbatim into the LLM rubric.
axes:
- id: lustig_ernst
low: Lustig
high: Ernst
description: |
Niedrig = Witze, Wortspiele, Lachen, ...
Hoch = nüchtern, faktisch, ...Add an axis here, then run with --update to backfill it on existing
sidecars without recomputing the rest.
[backend]— pickclaudeorllamacpp, set per-backend binary/URL/model.[chunking]—target_tokens_per_chunk,min_speaker_words(guest cameos below this are dropped).[aliases]— map garbled speaker labels onto real hosts with weights, e.g.IngoundFelix = [["Ingo", 0.5], ["Felix", 0.5]].[weights]— editorial weighting. Short interjections (avg < interjection_max_words) getinterjection_boost; long neutral monologues (n_words > monologue_min_wordsAND|score-5| < middle_penalty_window) getmonologue_neutral_decay. Multiplicative.[overall]— which overall methods to compute (weighted_meanand/orllm_pass).host_weightslets you override per-host weight in the weighted mean (default = total spoken words).[prompt.tone]— pre-prompt biasing the LLM towards opinionated scoring.[runtime]—max_callshard safety cap,concurrency,retries.
JSON array of diarized segments:
[
{"speaker": "Ingo", "text": "Hallo zusammen.", "start": 0.0, "end": 1.0},
...
]confidence, track, newpara are tolerated and ignored.
{
"schema_version": 1,
"episode": "2019-03-28.Binaergewitter.Talk.227",
"generated_at": "2026-06-20T20:00:00+00:00",
"backend": "claude",
"axes": {
"lustig_ernst": {
"hosts": {
"Ingo": {"score": 3.2, "n_words": 4123, "n_chunks": 2,
"raw": [3.0, 3.5], "chunk_weights": [...]},
"Felix": {...}
},
"overall_weighted_mean": 3.4,
"overall_llm_pass": 3.0
},
"ai_gut_ai_schlecht": { ... }
}
}Writes are atomic (temp file + os.replace). Re-running merges new axes into
the existing sidecar; --force overwrites.
bgt_sentiment/
cli.py # argparse entry point
pipeline.py # plan_episode + run_episode + run_pipeline
chunking.py # group_by_host + chunk_host
aggregate.py # editorial chunk_weight + weighted_mean
prompts.py # system/user/json-schema builders
io.py # speech loader + sidecar reader/writer/merger
config.py # pydantic models for sentiments.yaml + config.toml
backends/
_base.py # Backend ABC + BackendError
claude_cli.py
llamacpp.py
tests/ # pytest, see AGENTS.md
speech/ # fixture transcripts (28 MiB, excluded from the Nix build)
MIT.