Skip to content

[fix] Fix KeyError getting project id for HuggingFace and Sklearn bac… #790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ginic
Copy link

@ginic ginic commented Jun 26, 2025

This fixes a problem retrieving the project ID during the webhook for model training in the huggingface_ner, bert_classifier, and sklearn_text_classifier backends, resolving #768 and #745. There is also some trailing whitespace removed in the respective backend's model.py files to be consistent with PEP8.

I confirmed by rebuilding and running the backends in docker containers that I am now able to successfully complete training after triggering it in the "Model" section of project settings with huggingface_ner, bert_classifier, and sklearn_text_classifier backends.

Previously, when model training was triggered, a KeyError arose as follows:

bert_classifier  | [2025-06-25 16:28:19,504] [ERROR] [label_studio_ml.api::log_exception::875] Exception on /webhook [POST]
bert_classifier  | Traceback (most recent call last):
bert_classifier  |   File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1511, in wsgi_app
bert_classifier  |     response = self.full_dispatch_request()
bert_classifier  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bert_classifier  |   File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 919, in full_dispatch_request
bert_classifier  |     rv = self.handle_user_exception(e)
bert_classifier  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bert_classifier  |   File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 917, in full_dispatch_request
bert_classifier  |     rv = self.dispatch_request()
bert_classifier  |          ^^^^^^^^^^^^^^^^^^^^^^^
bert_classifier  |   File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 902, in dispatch_request
bert_classifier  |     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
bert_classifier  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bert_classifier  |   File "/usr/local/lib/python3.11/site-packages/label_studio_ml/api.py", line 126, in webhook
bert_classifier  |     result = model.fit(event, data)
bert_classifier  |              ^^^^^^^^^^^^^^^^^^^^^^
bert_classifier  |   File "/app/model.py", line 125, in fit
bert_classifier  |     project_id = data['annotation']['project']
bert_classifier  |                  ~~~~^^^^^^^^^^^^^^
bert_classifier  | KeyError: 'annotation'

…kends

Fixed string formatting in debug log

Tweaked debugging message for model fitting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant