Spaces:
Sleeping
Sleeping
added get_tasks to the class
Browse files
model.py
CHANGED
|
@@ -210,40 +210,42 @@ class BertClassifier(LabelStudioMLBase):
|
|
| 210 |
# Extract training data
|
| 211 |
texts, labels = [], []
|
| 212 |
|
| 213 |
-
# Get annotations from Label Studio
|
| 214 |
try:
|
| 215 |
# Get interface info
|
| 216 |
from_name, to_name, value = self.label_interface.get_first_tag_occurence('Choices', 'Text')
|
| 217 |
|
| 218 |
# Get tasks from Label Studio
|
| 219 |
-
tasks = self.
|
| 220 |
logger.info(f"Found {len(tasks)} tasks")
|
| 221 |
|
| 222 |
for task in tasks:
|
| 223 |
try:
|
| 224 |
# Get text from task
|
| 225 |
-
text = task
|
| 226 |
if not text:
|
|
|
|
| 227 |
continue
|
| 228 |
|
| 229 |
# Get annotations
|
| 230 |
annotations = task.get('annotations', [])
|
| 231 |
if not annotations:
|
|
|
|
| 232 |
continue
|
| 233 |
|
| 234 |
for annotation in annotations:
|
| 235 |
try:
|
| 236 |
# Get choices from result
|
| 237 |
-
|
| 238 |
-
if not
|
|
|
|
| 239 |
continue
|
| 240 |
|
| 241 |
-
for
|
| 242 |
-
if
|
| 243 |
-
choices =
|
| 244 |
if choices:
|
| 245 |
label = choices[0]
|
| 246 |
-
logger.info(f"Successfully extracted: Text='{text}', Label='{label}'")
|
| 247 |
texts.append(text)
|
| 248 |
labels.append(label)
|
| 249 |
break
|
|
@@ -258,6 +260,7 @@ class BertClassifier(LabelStudioMLBase):
|
|
| 258 |
|
| 259 |
except Exception as e:
|
| 260 |
logger.error(f"Error getting tasks: {str(e)}")
|
|
|
|
| 261 |
|
| 262 |
logger.info(f"Prepared {len(texts)} examples for training")
|
| 263 |
|
|
|
|
| 210 |
# Extract training data
|
| 211 |
texts, labels = [], []
|
| 212 |
|
|
|
|
| 213 |
try:
|
| 214 |
# Get interface info
|
| 215 |
from_name, to_name, value = self.label_interface.get_first_tag_occurence('Choices', 'Text')
|
| 216 |
|
| 217 |
# Get tasks from Label Studio
|
| 218 |
+
tasks = self.get_tasks()
|
| 219 |
logger.info(f"Found {len(tasks)} tasks")
|
| 220 |
|
| 221 |
for task in tasks:
|
| 222 |
try:
|
| 223 |
# Get text from task
|
| 224 |
+
text = task['data'].get(value)
|
| 225 |
if not text:
|
| 226 |
+
logger.warning(f"No text found in task {task.get('id')}")
|
| 227 |
continue
|
| 228 |
|
| 229 |
# Get annotations
|
| 230 |
annotations = task.get('annotations', [])
|
| 231 |
if not annotations:
|
| 232 |
+
logger.warning(f"No annotations found for task {task.get('id')}")
|
| 233 |
continue
|
| 234 |
|
| 235 |
for annotation in annotations:
|
| 236 |
try:
|
| 237 |
# Get choices from result
|
| 238 |
+
results = annotation.get('result', [])
|
| 239 |
+
if not results:
|
| 240 |
+
logger.warning(f"No results found in annotation for task {task.get('id')}")
|
| 241 |
continue
|
| 242 |
|
| 243 |
+
for result in results:
|
| 244 |
+
if result.get('from_name') == from_name and result.get('to_name') == to_name:
|
| 245 |
+
choices = result.get('value', {}).get('choices', [])
|
| 246 |
if choices:
|
| 247 |
label = choices[0]
|
| 248 |
+
logger.info(f"Successfully extracted: Text='{text[:50]}...', Label='{label}'")
|
| 249 |
texts.append(text)
|
| 250 |
labels.append(label)
|
| 251 |
break
|
|
|
|
| 260 |
|
| 261 |
except Exception as e:
|
| 262 |
logger.error(f"Error getting tasks: {str(e)}")
|
| 263 |
+
logger.error("Full error details:", exc_info=True)
|
| 264 |
|
| 265 |
logger.info(f"Prepared {len(texts)} examples for training")
|
| 266 |
|