Annotation API¶
Package Exports¶
Annotation module for human evaluation of proactive agent proposals.
Annotation
¶
Bases: BaseModel
A single annotation record.
Source code in pare/annotation/models.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
create(sample_id, annotator_id, human_decision, gather_context_rationale=None)
classmethod
¶
Create a new annotation record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_id
|
str
|
The sample being annotated. |
required |
annotator_id
|
str
|
The annotator's anonymous ID. |
required |
human_decision
|
TernaryDecision
|
The human's accept/reject/gather_context decision. |
required |
gather_context_rationale
|
str | None
|
Free-text rationale when decision is gather_context. |
None
|
Returns:
| Type | Description |
|---|---|
Annotation
|
A new Annotation instance. |
Source code in pare/annotation/models.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
csv_header()
classmethod
¶
Get CSV header row.
Source code in pare/annotation/models.py
279 280 281 282 | |
to_csv_row()
¶
Convert to CSV row string.
Source code in pare/annotation/models.py
265 266 267 268 269 270 271 272 273 274 275 276 277 | |
Sample
¶
Bases: BaseModel
A sample for annotation (loaded from parquet).
Source code in pare/annotation/models.py
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
to_api_response(progress_completed, progress_total)
¶
Convert to structured API response for the annotation UI.
Parses llm_input JSON, filters out non-renderable message types, formats observations and notifications for human readability, and returns a typed SampleResponse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_completed
|
int
|
Number of completed annotations. |
required |
progress_total
|
int
|
Total number of annotations. |
required |
Returns:
| Type | Description |
|---|---|
SampleResponse
|
SampleResponse with filtered, typed, formatted messages. |
Source code in pare/annotation/models.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
Data Models and Parsing¶
Data models for the annotation module.
Annotation
¶
Bases: BaseModel
A single annotation record.
Source code in pare/annotation/models.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
create(sample_id, annotator_id, human_decision, gather_context_rationale=None)
classmethod
¶
Create a new annotation record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_id
|
str
|
The sample being annotated. |
required |
annotator_id
|
str
|
The annotator's anonymous ID. |
required |
human_decision
|
TernaryDecision
|
The human's accept/reject/gather_context decision. |
required |
gather_context_rationale
|
str | None
|
Free-text rationale when decision is gather_context. |
None
|
Returns:
| Type | Description |
|---|---|
Annotation
|
A new Annotation instance. |
Source code in pare/annotation/models.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
csv_header()
classmethod
¶
Get CSV header row.
Source code in pare/annotation/models.py
279 280 281 282 | |
to_csv_row()
¶
Convert to CSV row string.
Source code in pare/annotation/models.py
265 266 267 268 269 270 271 272 273 274 275 276 277 | |
MessageType
¶
Bases: StrEnum
Classification of messages for UI rendering.
Source code in pare/annotation/models.py
18 19 20 21 22 23 24 | |
Sample
¶
Bases: BaseModel
A sample for annotation (loaded from parquet).
Source code in pare/annotation/models.py
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
to_api_response(progress_completed, progress_total)
¶
Convert to structured API response for the annotation UI.
Parses llm_input JSON, filters out non-renderable message types, formats observations and notifications for human readability, and returns a typed SampleResponse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_completed
|
int
|
Number of completed annotations. |
required |
progress_total
|
int
|
Total number of annotations. |
required |
Returns:
| Type | Description |
|---|---|
SampleResponse
|
SampleResponse with filtered, typed, formatted messages. |
Source code in pare/annotation/models.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
SampleResponse
¶
Bases: BaseModel
API response payload for a single annotation sample.
Source code in pare/annotation/models.py
35 36 37 38 39 40 41 42 43 | |
UIMessage
¶
Bases: BaseModel
A single renderable message for the annotation UI.
Source code in pare/annotation/models.py
27 28 29 30 31 32 | |
Proposal-centric trace parser for extracting decision points.
Single forward scan algorithm: 1. Identify agents by system prompt content 2. Truncate trace at first execute agent tool call 3. Pair proposals with accept/reject decisions 4. Classify: direct accept/reject vs gather_context 5. Extract and annotate llm_input at proposal point
extract_decision_points(trace_path, proactive_model_id, user_model_id='unknown')
¶
Extract all decision points from a trace file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace_path
|
Path
|
Path to the trace JSON file. |
required |
proactive_model_id
|
str
|
The proactive model identifier. |
required |
user_model_id
|
str
|
The user model identifier. |
'unknown'
|
Returns:
| Type | Description |
|---|---|
list[DecisionPoint]
|
List of DecisionPoint objects, one per valid proposal-decision pair. |
Source code in pare/trajectory/trace_parser.py
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
Observation formatter for converting raw tool observations to human-readable text.
Used by Sample.to_api_response() to format tool observations and notifications
for human annotators. A redesign using proper typed object parsing is tracked as a
separate feature (see observation-formatter-redesign feature doc).
This module provides formatters for all return types used in PARE apps.
ObservationFormatter
¶
Formats raw observations into human-readable displays.
Source code in pare/annotation/observation_formatter.py
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
format(tool_name, raw_observation, tool_args=None)
staticmethod
¶
Format an observation based on the tool that produced it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str
|
The name of the tool (e.g., "Emails__list_emails"). |
required |
raw_observation
|
Any
|
The raw observation data (usually a string repr of dataclass). |
required |
tool_args
|
dict[str, Any] | None
|
Optional dictionary of tool arguments for context. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A human-readable formatted string. |
Source code in pare/annotation/observation_formatter.py
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
format_notification(raw_notification, id_to_name_map=None)
¶
Format a notification to be human-readable.
Converts raw notifications like: '[2025-11-18 09:00:05] New message from 22c41f3ff12fe5f2a0a02c1da9d15b57 in conversation xyz: Hello!'
To: '[2025-11-18 09:00:05] New message: Hello!'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_notification
|
str
|
The raw notification string. |
required |
id_to_name_map
|
dict[str, str] | None
|
Optional mapping from IDs to human-readable names. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A cleaned notification string. |
Source code in pare/annotation/observation_formatter.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
Sampling and Server¶
Balanced sampler for annotation dataset creation.
balanced_sample_ternary(candidates, sample_size, seed=None)
¶
Sample decision points balanced by both decision type and proactive model.
Algorithm: For each proactive model, create three pools (accept, reject, gather_context). Cycle through models, and within each model cycle through decision type pools, drawing one sample per pool per cycle. If a pool is exhausted, skip it. Stop when target count reached or all pools across all models are empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidates
|
list[DecisionPoint]
|
List of candidate decision points. |
required |
sample_size
|
int
|
Number of samples to select. |
required |
seed
|
int | None
|
Random seed for reproducibility. |
None
|
Returns:
| Type | Description |
|---|---|
list[DecisionPoint]
|
List of selected TernaryDecisionPoint objects. |
Source code in pare/annotation/sampler.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
extract_all_decision_points_ternary(traces_dir, user_model_id, target_models=None)
¶
Extract ternary decision points from all trace files in a directory.
Walks the traces directory, identifies model subdirectories, and extracts decision points from each no-noise trace file using the ternary parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traces_dir
|
Path
|
Root directory containing model subdirectories with traces. |
required |
user_model_id
|
str
|
The user model that generated these traces. |
required |
target_models
|
list[str] | None
|
If provided, only extract from these proactive model IDs. |
None
|
Returns:
| Type | Description |
|---|---|
list[DecisionPoint]
|
List of TernaryDecisionPoint objects from all matching traces. |
Source code in pare/annotation/sampler.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
extract_model_id_from_dir(dir_name)
¶
Extract the proactive model ID from a trace subdirectory name.
Example: obs_gpt-5_exec_gpt-5_enmi_0_es_42_tfp_0.0 -> gpt-5
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dir_name
|
str
|
The subdirectory name. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The extracted proactive model ID. |
Source code in pare/annotation/sampler.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
is_no_noise_trace(dir_name)
¶
Check if a trace directory is a no-noise trace.
No-noise traces have enmi_0 (environment noise = 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dir_name
|
str
|
The directory name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if this is a no-noise trace. |
Source code in pare/annotation/sampler.py
38 39 40 41 42 43 44 45 46 47 48 49 | |
sample_new_datapoints_ternary(traces_dir, samples_file, user_model_id, sample_size, seed=None, target_models=None)
¶
Extract, sample, and save ternary decision points.
End-to-end function: extracts all ternary decision points from traces, deduplicates against existing samples, applies three-way balanced sampling, and saves the result to parquet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traces_dir
|
Path
|
Root directory containing model subdirectories with traces. |
required |
samples_file
|
Path
|
Path to the output parquet file (for dedup and save). |
required |
user_model_id
|
str
|
The user model that generated these traces. |
required |
sample_size
|
int
|
Number of new samples to select. |
required |
seed
|
int | None
|
Random seed for reproducibility. |
None
|
target_models
|
list[str] | None
|
If provided, only extract from these proactive model IDs. |
None
|
Returns:
| Type | Description |
|---|---|
list[DecisionPoint]
|
List of newly selected TernaryDecisionPoint objects. |
Source code in pare/annotation/sampler.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
save_samples_ternary(samples, output_file)
¶
Save ternary samples to parquet, checking schema compatibility.
If the output file already exists, validates that it uses the ternary schema (user_agent_decision as String, not Boolean). Raises SystemExit if an incompatible binary-schema parquet is found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
list[DecisionPoint]
|
List of TernaryDecisionPoint objects to save. |
required |
output_file
|
Path
|
Path to the output parquet file. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the samples file. |
Source code in pare/annotation/sampler.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
FastAPI server for the annotation interface.
AnnotationRequest
¶
Bases: BaseModel
Request body for submitting an annotation.
Source code in pare/annotation/server.py
24 25 26 27 28 29 | |
AnnotationServer
¶
Server for managing annotation state and serving samples.
Source code in pare/annotation/server.py
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
__init__(samples_file, annotations_file, annotators_per_sample=2)
¶
Initialize the annotation server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples_file
|
Path
|
Path to the samples parquet file. |
required |
annotations_file
|
Path
|
Path to the annotations CSV file (created if not exists). |
required |
annotators_per_sample
|
int
|
Number of annotations required per sample. |
2
|
Source code in pare/annotation/server.py
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 81 82 83 84 85 86 87 88 89 90 | |
get_next_sample(annotator_id)
¶
Get the next available real (non-tutorial) sample for an annotator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotator_id
|
str
|
The annotator's anonymous ID. |
required |
Returns:
| Type | Description |
|---|---|
Sample | None
|
The next real sample to annotate, or None if all done. |
Source code in pare/annotation/server.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
get_next_tutorial_sample(annotator_id)
¶
Get the next unanswered tutorial sample for an annotator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotator_id
|
str
|
The annotator's anonymous ID. |
required |
Returns:
| Type | Description |
|---|---|
Sample | None
|
Next tutorial Sample, or None if all done. |
Source code in pare/annotation/server.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
get_overall_stats()
¶
Get overall annotation statistics.
Source code in pare/annotation/server.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
get_progress(annotator_id)
¶
Get progress statistics for an annotator (real samples only).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotator_id
|
str
|
The annotator's anonymous ID. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Dictionary with completed and total counts. |
Source code in pare/annotation/server.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
get_sample(sample_id)
¶
Get a sample by ID (tutorial or real).
Source code in pare/annotation/server.py
141 142 143 | |
get_tutorial_summary(annotator_id)
¶
Get tutorial completion summary for an annotator.
Uses in-memory tutorial annotation data (no file I/O).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotator_id
|
str
|
The annotator's anonymous ID. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Summary dict with correct, scored_total, total, answered. |
Source code in pare/annotation/server.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
is_tutorial_completed(annotator_id)
¶
Check if annotator has completed all tutorial samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotator_id
|
str
|
The annotator's anonymous ID. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all tutorial samples answered or no tutorials configured. |
Source code in pare/annotation/server.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
record_annotation(sample_id, annotator_id, human_decision, gather_context_rationale=None)
¶
Record a real (non-tutorial) annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_id
|
str
|
The sample being annotated. |
required |
annotator_id
|
str
|
The annotator's anonymous ID. |
required |
human_decision
|
TernaryDecision
|
The human's accept/reject/gather_context decision. |
required |
gather_context_rationale
|
str | None
|
Free-text rationale when decision is gather_context. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if recorded successfully. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If sample not found or already annotated by this user. |
Source code in pare/annotation/server.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
record_tutorial_annotation(sample_id, annotator_id, human_decision, gather_context_rationale=None)
¶
Record a tutorial annotation and return feedback.
Writes to tutorial_annotations.csv (not annotations.csv).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_id
|
str
|
The tutorial sample being annotated. |
required |
annotator_id
|
str
|
The annotator's anonymous ID. |
required |
human_decision
|
TernaryDecision
|
The annotator's decision. |
required |
gather_context_rationale
|
str | None
|
Free-text rationale when decision is gather_context. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Feedback dict with correct, correct_decision, and explanation. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If sample not found in tutorial samples. |
Source code in pare/annotation/server.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
create_app(samples_file, annotations_file, annotators_per_sample=2)
¶
Create the FastAPI application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples_file
|
Path
|
Path to the samples parquet file. |
required |
annotations_file
|
Path
|
Path to the annotations CSV file. |
required |
annotators_per_sample
|
int
|
Number of annotations required per sample. |
2
|
Returns:
| Type | Description |
|---|---|
FastAPI
|
Configured FastAPI application. |
Source code in pare/annotation/server.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | |
run_server(samples_file, annotations_file, port=8000, annotators_per_sample=2)
¶
Run the annotation server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples_file
|
Path
|
Path to the samples parquet file. |
required |
annotations_file
|
Path
|
Path to the annotations CSV file. |
required |
port
|
int
|
Port to run the server on. |
8000
|
annotators_per_sample
|
int
|
Number of annotations required per sample. |
2
|
Source code in pare/annotation/server.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
Metrics and Configuration¶
Agreement metrics computation for annotation analysis.
Implements comprehensive metrics for measuring alignment between a ML model and multiple human annotators on binary prediction tasks.
Metrics included: 1. Agreement with Majority Vote (accuracy, F1, precision, recall, Cohen's kappa) 2. Soft Label Alignment (cross-entropy, MAE) 3. Average Pairwise Cohen's Kappa (model vs each human) 4. Krippendorff's Alpha (model as k+1 rater) 5. Fleiss' Kappa (human-only baseline) 6. Stratified Analysis by consensus level
argmax_with_tiebreak(counts, labels, seed_str)
¶
Argmax with deterministic tie-breaking using hash of seed string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
counts
|
list[int]
|
Vote counts per category. |
required |
labels
|
list[str]
|
Category labels corresponding to counts. |
required |
seed_str
|
str
|
String to use as tie-breaking seed (e.g., sample_id). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Label with highest count (ties broken by hash). |
Source code in pare/annotation/metrics.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | |
cohens_kappa_multiclass(y1, y2)
¶
Compute Cohen's Kappa between two raters for multiclass labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y1
|
list[str]
|
First rater's decisions (categorical labels). |
required |
y2
|
list[str]
|
Second rater's decisions (categorical labels). |
required |
Returns:
| Type | Description |
|---|---|
float | None
|
Cohen's Kappa value or None if computation not possible. |
Source code in pare/annotation/metrics.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 | |
compute_agreement_metrics(samples_df, annotations_df, n_annotators=2)
¶
Compute comprehensive agreement metrics.
.. deprecated::
Use compute_agreement_metrics_ternary for ternary decisions. Will be removed after UI update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples_df
|
DataFrame
|
DataFrame with sample data including user_agent_decision. |
required |
annotations_df
|
DataFrame
|
DataFrame with annotation data. |
required |
n_annotators
|
int
|
Number of top annotators to include (by completion count). |
2
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing all computed metrics. |
Source code in pare/annotation/metrics.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
compute_agreement_metrics_ternary(samples_df, annotations_df, n_annotators=2)
¶
Compute comprehensive agreement metrics for ternary decisions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples_df
|
DataFrame
|
DataFrame with sample data including user_agent_decision (str). |
required |
annotations_df
|
DataFrame
|
DataFrame with annotation data (ternary decisions). |
required |
n_annotators
|
int
|
Number of top annotators to include (by completion count). |
2
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing all computed metrics. |
Source code in pare/annotation/metrics.py
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 | |
compute_decision_entropy(soft_labels_df)
¶
Compute average entropy per user model across all samples.
Entropy measures decision consistency: low entropy = consistent decisions, high entropy = uncertain/variable decisions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
soft_labels_df
|
DataFrame
|
DataFrame from compute_soft_labels_ternary. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary mapping user_model_id to average entropy. |
Source code in pare/annotation/metrics.py
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | |
compute_fleiss_kappa_multiclass(df, *, include_model=False)
¶
Compute Fleiss' Kappa for multiple raters with arbitrary categories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with annotations. |
required |
include_model
|
bool
|
If True, treat model as an additional rater. |
False
|
Returns:
| Type | Description |
|---|---|
float | None
|
Fleiss' Kappa value or None if computation not possible. |
Source code in pare/annotation/metrics.py
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 | |
compute_kl_divergence(model_probs, human_probs)
¶
Compute KL divergence between model and human probability distributions.
KL(human || model) measures how much information is lost when using model distribution to approximate human distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_probs
|
list[float]
|
Model probability distribution [p_accept, p_reject, p_gather]. |
required |
human_probs
|
list[float]
|
Human probability distribution [p_accept, p_reject, p_gather]. |
required |
Returns:
| Type | Description |
|---|---|
float
|
KL divergence value (non-negative, 0 means identical distributions). |
Source code in pare/annotation/metrics.py
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 | |
compute_krippendorff_alpha_multiclass(df, *, include_model=True)
¶
Compute Krippendorff's Alpha for nominal data with arbitrary categories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with annotations. |
required |
include_model
|
bool
|
If True, treat model as an additional rater. |
True
|
Returns:
| Type | Description |
|---|---|
float | None
|
Krippendorff's Alpha value or None if computation not possible. |
Source code in pare/annotation/metrics.py
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 | |
compute_per_model_agreement_metrics(evaluations_df, annotations_df, n_annotators=2)
¶
Compute agreement metrics per user model from the evaluation dataframe.
.. deprecated::
Use compute_per_model_agreement_metrics_ternary for ternary decisions. Will be removed after UI update.
For each user_model_id in the evaluations, aggregates runs via majority vote and computes agreement metrics against human annotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations_df
|
DataFrame
|
DataFrame from |
required |
annotations_df
|
DataFrame
|
DataFrame with human annotation data. |
required |
n_annotators
|
int
|
Number of top annotators to include (by completion count). |
2
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Dictionary mapping user_model_id to agreement metrics dict. |
Source code in pare/annotation/metrics.py
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 | |
compute_per_model_agreement_metrics_ternary(evaluations_df, annotations_df, n_annotators=2)
¶
Compute agreement metrics per user model for ternary decisions.
For each user_model_id in the evaluations, aggregates runs via majority vote (argmax with deterministic tie-breaking) and computes agreement metrics against human annotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations_df
|
DataFrame
|
DataFrame with columns: sample_id, user_model_id, user_agent_decision (str), run, valid_response. |
required |
annotations_df
|
DataFrame
|
DataFrame with human annotation data (ternary decisions). |
required |
n_annotators
|
int
|
Number of top annotators to include (by completion count). |
2
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Dictionary mapping user_model_id to agreement metrics dict. |
Source code in pare/annotation/metrics.py
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 | |
compute_soft_labels_ternary(eval_df)
¶
Compute soft labels from ternary evaluation results.
Groups by (sample_id, user_model_id) and computes raw counts and probabilities for each decision category (accept, reject, gather_context).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eval_df
|
DataFrame
|
DataFrame with columns sample_id, user_model_id, user_agent_decision, valid_response. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: - sample_id - user_model_id - accept_count, reject_count, gather_context_count - accept_prob, reject_prob, gather_context_prob |
Source code in pare/annotation/metrics.py
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 | |
Configuration helpers for the annotation module.
ensure_extension(path, ext)
¶
Ensure a file path has the correct extension.
Strips any existing extension and replaces with the specified one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The file path. |
required |
ext
|
str
|
The desired extension (e.g., '.parquet', '.csv'). |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path with the correct extension. |
Source code in pare/annotation/config.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |