Skip to content

About

Binärgewitter Talk Sentiment Detection

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

bgt-sentiment

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:

  1. Chunk — group transcript segments by speaker, split into LLM-sized blocks (token budget per chunk).
  2. Score — one LLM call per chunk returns a JSON object with a number 0..10 per axis.
  3. Aggregate — per-host editorial weighting: short interjections boosted, long neutral monologues de-weighted (5 is "boring").
  4. 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 the claude CLI (subscription quota, not the API).
  • llamacpp — POSTs to any OpenAI-compatible endpoint (llama.cpp, vLLM, …).

Quick start (Nix)

# 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 develop

nix flake check runs ruff format, ruff check, ty check, pytest, plus the package build.

Pretty-print a sidecar

nix run .#summary -- speech/2019-03-28.Binaergewitter.Talk.227-sentiment.json
nix run .#summary -- speech/2019-03-28.Binaergewitter.Talk.227-sentiment.json --bar

Resolves 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.

Quick start (pip)

pip install -e .
bgt-sentiment speech/*.json --backend claude

Python 3.13 required.

CLI

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.

Configuration

sentiments.yaml

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.

config.toml

  • [backend] — pick claude or llamacpp, 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) get interjection_boost; long neutral monologues (n_words > monologue_min_words AND |score-5| < middle_penalty_window) get monologue_neutral_decay. Multiplicative.
  • [overall] — which overall methods to compute (weighted_mean and/or llm_pass). host_weights lets 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_calls hard safety cap, concurrency, retries.

Input format (*-speech.json)

JSON array of diarized segments:

[
  {"speaker": "Ingo", "text": "Hallo zusammen.", "start": 0.0, "end": 1.0},
  ...
]

confidence, track, newpara are tolerated and ignored.

Output format (*-sentiment.json)

{
  "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.

Layout

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)

License

MIT.

About

Binärgewitter Talk Sentiment Detection

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages