Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
LabelModel
✓ from snorkel.labeling.model import LabelModel
✗ from snorkel.labeling import LabelModel
LabelModel was moved to snorkel.labeling.model in v0.9.4, but still accessible via old path for backward compatibility.
LFAnalysis
✓ from snorkel.labeling import LFAnalysis
✗ from snorkel.labeling import LabelingFunction
LFAnalysis is in snorkel.labeling, not other submodules.
SnorkelClassifier
✓ from snorkel.classification import SnorkelClassifier
✗ from snorkel import SnorkelClassifier
Must import from snorkel.classification.
Basic Snorkel flow: define labeling functions, generate label matrix, train LabelModel.
from snorkel.labeling import labeling_function, LFAnalysis
from snorkel.labeling.model import LabelModel
import numpy as np
@labeling_function()
def lf_keyword(x):
# Return 1 if 'keyword' in text else 0
return 1 if 'keyword' in x else 0
# Example data
data = ['text with keyword', 'no match']
# Apply LFs (simulate L matrix)
L = np.array([[1, 0], [0, 0])
# Train LabelModel
label_model = LabelModel(cardinality=2, verbose=True)
label_model.fit(L_train=L, n_epochs=500, log_freq=100, seed=123)
predictions = label_model.predict(L=L)
Errors
Common errors & fixes
ValueError: Label model must be fit before calling predict.
Calling predict() without first calling fit() on LabelModel.
fixCall label_model.fit(...) before predict().
ModuleNotFoundError: No module named 'snorkel.labeling.model'
Installed snorkel version <0.9.4 where the model submodule did not exist.
fixUpgrade snorkel: pip install --upgrade snorkel. Or import from snorkel.labeling import LabelModel if using older version.
Upgrade
Version history
0.10.0latest on PyPI · released Feb 27, 2024
Audit
Dependencies
No dependency data recorded yet.