Subtext

YouTube comment sentiment analysis with Python and LLMs

Lexicon tools like VADER miss sarcasm, timestamps, and product names in YouTube comments, so they often mislabel half a thread. Feeding cleaned comments into an LLM alongside the video's transcript gives you grouped viewer questions, repeated objections, and sentiment that matches what the speaker actually said.

By Subtext ยท Updated December 2026

Get Subtext Transcript API Scrape YouTube comments Connect via MCP

Why comment sentiment needs the video transcript

A large share of useful YouTube comments refer to a timestamp or a claim in the video: "3:14 saved me 400 dollars", "the benchmark at 08:20 skipped cache warmup", or "does this work on M4 Macs?". Without the spoken text around those timestamps, a sentiment classifier can only guess whether the viewer is praising the creator, criticizing a product, or correcting a bug.

Subtext serves public YouTube transcripts as clean JSON segments with timestamps (it reads captions only, not comments). Fetch the transcript once before analyzing a video's comments:

export SUBTEXT_API_KEY=stx_...
curl -sS -H "Authorization: Bearer $SUBTEXT_API_KEY" \
  "https://subtextapi.com/api/v1/transcript?video=M7lc1UVf-VE&format=json" \
  > transcript.json

For manual research without writing code, grab the transcript on Subtext or read how to summarize a YouTube video in ChatGPT. Inside Claude Code or Cursor, connect the Subtext MCP server.

Step 1: Collect and clean the comments

Export the video's comments with YouTube Data API v3 or yt-dlp --write-comments (see scraping YouTube comments in Python for working scripts). Before sending anything to a model, clean the raw list so you do not spend tokens on spam:

Step 2: Classify sentiment, questions, and objections with an LLM

Instead of asking a model for a single vague score like "72% positive", ask for structured JSON that separates sentiment from actionable viewer intent:

You are analyzing viewer comments on a YouTube video.
Use the video transcript summary below to understand timestamps.

For each comment, return a JSON array of objects with:
- "id": comment id
- "sentiment": "positive" | "neutral" | "negative" | "mixed"
- "category": "question" | "objection" | "praise" |
              "correction" | "feature_request" | "spam"
- "topic": short 2 to 5 word topic label
- "timestamp_ref": timestamp mentioned in the comment, or null

Transcript summary:
[Paste transcript summary or key chapters here]

Comments:
[Paste JSON list of {"id", "likes", "text"} objects here]

Step 3: Aggregate recurring topics and top quotes in Python

Once the model returns the JSON array, group rows by category and topic and weight each cluster by both comment count and total likes:

from collections import Counter, defaultdict

def summarize_clusters(
    classified: list[dict], likes_by_id: dict[str, int]
):
    counts = Counter()
    weighted_likes = defaultdict(int)
    examples = defaultdict(list)
    for row in classified:
        if row["category"] == "spam":
            continue
        bucket = (row["category"], row["topic"].lower())
        counts[bucket] += 1
        likes = likes_by_id.get(row["id"], 0)
        weighted_likes[bucket] += likes
        examples[bucket].append((likes, row["id"]))
    return sorted(
        counts.items(),
        key=lambda item: (item[1], weighted_likes[item[0]]),
        reverse=True,
    )

Weighting by likes prevents one loud commenter from outranking a question that 400 viewers upvoted without typing a duplicate reply.

When a lightweight lexicon model still makes sense

Keep VADER, TextBlob, or a small local transformer when you need zero-cost offline scoring across 500,000+ historical comments to plot broad positivity trends over time. For product research, content planning, or competitive analysis on dozens of videos, an LLM paired with the video transcript produces far fewer misclassified jokes and gives you exact viewer questions ready to act on.

Next steps: how to scrape YouTube comments in Python, YouTube Comments API quotas and limits, copying YouTube comments manually or in bulk, and the Subtext Transcript API reference.