labels.queue¶
Active labeling queue for prioritising windows that need human labels.
Overview¶
The queue tracks buckets flagged for labeling due to low model confidence or detected drift. A daily ask limit prevents user fatigue.
LabelRequest¶
Pydantic model representing a single labeling request:
| Field | Type | Description |
|---|---|---|
request_id |
str |
UUID |
user_id |
str |
User whose bucket needs labeling |
bucket_start_ts |
datetime |
Bucket start (UTC) |
bucket_end_ts |
datetime |
Bucket end (UTC, exclusive) |
reason |
"low_confidence" \| "drift" |
Why enqueued |
confidence |
float \| None |
Model confidence at enqueue time |
predicted_label |
str \| None |
Model prediction at enqueue time |
created_at |
datetime |
Creation timestamp (UTC) |
status |
"pending" \| "labeled" \| "skipped" |
Lifecycle state |
ActiveLabelingQueue¶
ActiveLabelingQueue is implemented as a slotted dataclass; constructor
parameters remain queue_path and max_asks_per_day.
from taskclf.labels.queue import ActiveLabelingQueue
queue = ActiveLabelingQueue(Path("data/processed/labels_v1/queue.json"))
queue.enqueue_low_confidence(predictions_df, threshold=0.55)
pending = queue.get_pending(user_id="u1", limit=10)
queue.mark_done(pending[0].request_id, status="labeled")
taskclf.labels.queue
¶
Active labeling queue: prioritise windows/blocks that need human labels.
The queue tracks buckets flagged for labeling (low model confidence or detected drift) and enforces a daily ask limit so users are not overwhelmed.
LabelRequest
¶
Bases: BaseModel
A single item in the active labeling queue.
Source code in src/taskclf/labels/queue.py
ActiveLabelingQueue
dataclass
¶
Manages a persisted queue of labeling requests.
State lives in a single JSON file; mutations are atomic (write-to-temp then rename).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
queue_path
|
Path
|
Path to the JSON file backing the queue. |
required |
max_asks_per_day
|
int
|
Upper bound on pending items served per calendar day (UTC). |
DEFAULT_LABEL_MAX_ASKS_PER_DAY
|
Source code in src/taskclf/labels/queue.py
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 | |
all_items
property
¶
All items currently in the queue (any status).
enqueue_low_confidence(predictions_df, threshold=DEFAULT_LABEL_CONFIDENCE_THRESHOLD)
¶
Add buckets whose model confidence is below threshold.
predictions_df must have columns: user_id,
bucket_start_ts, bucket_end_ts, confidence,
predicted_label.
Returns the number of newly enqueued items.
Source code in src/taskclf/labels/queue.py
enqueue_drift(buckets)
¶
Add drift-flagged buckets.
Each dict in buckets must contain user_id,
bucket_start_ts, bucket_end_ts, and optionally
predicted_label and confidence.
Returns the number of newly enqueued items.
Source code in src/taskclf/labels/queue.py
get_pending(user_id=None, limit=None)
¶
Return pending items, respecting the daily ask cap.
Items are sorted by confidence ascending (lowest first) so the most uncertain buckets surface first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str | None
|
Filter to a specific user ( |
None
|
limit
|
int | None
|
Maximum items to return (capped by daily limit). |
None
|
Returns:
| Type | Description |
|---|---|
list[LabelRequest]
|
List of pending |
Source code in src/taskclf/labels/queue.py
mark_done(request_id, status='labeled')
¶
Transition a request to status.
Returns the updated request, or None if request_id was
not found.