-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannotator.py
More file actions
80 lines (69 loc) · 2.88 KB
/
Copy pathannotator.py
File metadata and controls
80 lines (69 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
annotator.py — Structured annotation producer for LLM training data
Generates JSONL annotation records in the format used for:
- Supervised fine-tuning (SFT) datasets
- RLHF preference data
- Model evaluation benchmarks
Output format follows the OpenAI / Anthropic annotation convention:
{id, task_type, prompt, response, label, confidence, rubric_scores, notes}
"""
from __future__ import annotations
import json
import uuid
from datetime import datetime
import config
def make_annotation(
strategy: str,
prompt: str,
response: str,
label: str,
confidence: float,
dim_scores: dict[str, float],
notes: str = "",
) -> dict:
"""Build a single structured annotation record."""
return {
"id": str(uuid.uuid4())[:12],
"created_at": datetime.utcnow().isoformat(),
"task_type": "sentiment_classification",
"strategy": strategy,
"prompt": prompt,
"response": response,
"label": label,
"confidence": round(confidence, 4),
"rubric_scores":dim_scores,
"annotator": "sharath_chandra",
"notes": notes,
}
def save_annotations(annotations: list[dict], path: str = None) -> None:
"""Save annotations to a JSONL file (one JSON object per line)."""
path = path or config.ANNOTATION_FILE
with open(path, "w") as f:
for ann in annotations:
f.write(json.dumps(ann) + "\n")
print(f" {len(annotations)} annotations saved → {path}")
def load_annotations(path: str = None) -> list[dict]:
"""Load annotations from a JSONL file."""
path = path or config.ANNOTATION_FILE
with open(path) as f:
return [json.loads(line) for line in f if line.strip()]
# ── Demo responses ──────────────────────────────────────────────────────────────
DEMO_RESPONSES = {
"zero_shot":
"Neutral. Rate hikes signal inflation control — not directly bullish or bearish.",
"chain_of_thought":
"1. Subject: Central bank. 2. Signal: 'raises rates' and 'inflation' — "
"hawkish stance. 3. Impact: Typically negative for equities, mixed for bonds. "
"4. Sentiment: Neutral-to-Negative. Final: Neutral.",
"few_shot":
"Neutral",
"role_based":
"From a market-sentiment perspective this is a Neutral-to-Negative signal. "
"Rate hikes tighten liquidity conditions but were priced in by the market "
"given the inflation backdrop. Net sentiment: Neutral.",
"structured_output":
'{"sentiment":"Neutral","confidence":0.82,'
'"key_signal":"raises interest rates",'
'"reasoning":"Rate hikes are a standard inflation-control mechanism; '
'impact is mixed and market-conditional."}',
}