Label Studio ML Backend

raw JSON →
1.0.9 verified Mon Apr 27 auth: no python

Label Studio ML backend library for building, training, and deploying machine learning models with Label Studio. Version 1.0.9 supports Python >=3.6, released irregularly. Integrates with Label Studio for interactive labeling with model predictions.

pip install label-studio-ml
error ModuleNotFoundError: No module named 'label_studio_ml'
cause Package not installed or installed as 'label-studio-ml' but imported with wrong name.
fix
Run pip install label-studio-ml and import as 'label_studio_ml'.
error TypeError: predict() missing 1 required positional argument: 'tasks'
cause Method signature mismatch: predict(tasks, **kwargs) is required.
fix
Define predict(self, tasks, **kwargs) returning list of dicts.
gotcha LabelStudioMLBase is the correct base class; avoid custom inheritance from sklearn-like classes directly. Predictions must be a list of dicts with 'result' key.
fix Ensure predict() returns a list of dictionaries, each containing 'result' (list of annotation results).
deprecated The old config system using label_config.xml is deprecated; use XML or JSON config from project settings.
fix Use Label Studio web interface to generate config, or pass a LabelConfig string via label_config in init.

Basic skeleton for a Label Studio ML backend model.

from label_studio_ml.model import LabelStudioMLBase
from label_studio_ml.utils import get_local_path

class MyModel(LabelStudioMLBase):
    def predict(self, tasks, context, **kwargs):
        return [{"result": []}]

    def fit(self, completions, workdir=None, **kwargs):
        pass