""" Annotate documents using Together AI or Claude Sonnet APIs. =========================================================== Actions: run, submit-claude, collect-claude, compare. Usage: # Run annotations via Together AI (sync, with optional concurrency) python annotate_openrouter.py run \ --documents ../audit_output/flagged_documents.csv.gz \ --sample 100000 \ --model meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8 \ --output ../audit_output/annotations_llama_100k.csv \ --label-prefix llama --concurrency 64 # Submit/collect Claude batch python annotate_openrouter.py submit-claude \ --documents ../audit_output/flagged_documents.csv.gz --sample 300 python annotate_openrouter.py collect-claude \ --documents ../audit_output/flagged_documents.csv.gz --sample 300 \ --batch-id --output ../audit_output/annotations_claude.csv # Compare two annotation files python annotate_openrouter.py compare \ --file-a annotations_a.csv --file-b annotations_b.csv Note: run/collect must use the same --documents, --sample, and seed to produce matching rows. Uses reservoir sampling for memory efficiency. """ import csv import gzip import os import re import random import argparse from collections import Counter csv.field_size_limit(10_000_000) # ── Config ──────────────────────────────────────────────────────────────────── LLAMA_MODEL = "meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8" CLAUDE_MODEL = "claude-sonnet-4-6" MAX_TEXT_CHARS = 10000 RANDOM_SEED = 42 CLASSES = [ "climate_denial", "health_misinfo", "pseudoscience", "hate_extremism", "conspiracy_propaganda", "benign", ] SYSTEM_PROMPT = """You are an expert in misinformation research and content analysis. Classify whether the following web document contains misinformation, propaganda, or other problematic content. The text may be truncated. Use exactly one of these labels: - climate_denial: denies or misrepresents climate change science - health_misinfo: health or medical misinformation (antivax, COVID denial, quack remedies, unproven supplement claims, alternative medicine promoted as replacement for evidence-based treatment) - pseudoscience: promotes non-medical unscientific claims (creationism, flat earth, ancient aliens, astrology, etc.) - hate_extremism: hate speech, Holocaust denial, white nationalism, racist pseudoscience, far-right extremism, or religiously-motivated content that incites hatred or violence against specific groups - conspiracy_propaganda: conspiracy theories (QAnon, chemtrails, etc.) or state-sponsored propaganda and disinformation - benign: legitimate content that is not misinformation, propaganda, or pseudoscience Important: only flag content that actively promotes or endorses misinformation. Use benign for: - low-quality, politically biased, or opinionated content that is not clearly misinformation - satirical, humorous, or fictional content - articles that discuss or critically examine a questionable topic without endorsing it - content with minor factual errors that is otherwise informational - speculative or futuristic science and engineering discussions - historical or archival documents that reflect outdated views or language Respond in exactly this format: LABEL: