-
Notifications
You must be signed in to change notification settings - Fork 858
Closed
Labels
Description
Issue description
I wanted to save a label model trained within a jupyter notebook and use it in standalone python scripts elsewhere.
I used snorkel.labeling.LabelModel.save() method to save the model. Then, I loaded the model using the snorkel.labeling.LabelModel.load() method and it throws the following error:
AttributeError: 'LabelModel' object has no attribute 'c_tree'
Code example/repro steps
import numpy as np
import snorkel.labeling
L_train = np.random.randint(-1, 2, size=(10**6, 10), dtype=np.int8)
lm = snorkel.labeling.LabelModel()
lm.fit(L_train)
lm.save('label_mode.pt') # open this file and you will see the aforementioned error
lm2 = snorkel.labeling.LabelModel()
lm2.load('label_model.pt')
lm2.predict(L_train) # throws AttributeError: 'LabelModel' object has no attribute 'c_tree'
Error stack trace
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-57-39ae7bf111ea> in <module>
1 lm2 = snorkel.labeling.LabelModel()
2 lm2.load('label_model.pt')
----> 3 lm2.predict(L_train)
~\AppData\Local\Continuum\anaconda3\envs\snorkel\lib\site-packages\snorkel\labeling\model\label_model.py in predict(self, L, return_probs, tie_break_policy)
429 array([0, 1, 0])
430 """
--> 431 Y_probs = self.predict_proba(L)
432 Y_p = probs_to_preds(Y_probs, tie_break_policy)
433 if return_probs:
~\AppData\Local\Continuum\anaconda3\envs\snorkel\lib\site-packages\snorkel\labeling\model\label_model.py in predict_proba(self, L)
377 L_shift = L + 1 # convert to {0, 1, ..., k}
378 self._set_constants(L_shift)
--> 379 L_aug = self._get_augmented_label_matrix(L_shift)
380 mu = np.clip(self.mu.detach().clone().numpy(), 0.01, 0.99)
381 jtm = np.ones(L_aug.shape[1])
~\AppData\Local\Continuum\anaconda3\envs\snorkel\lib\site-packages\snorkel\labeling\model\label_model.py in _get_augmented_label_matrix(self, L, higher_order)
178 [
179 j
--> 180 for j in self.c_tree.nodes()
181 if i in self.c_tree.node[j]["members"]
182 ]
~\AppData\Local\Continuum\anaconda3\envs\snorkel\lib\site-packages\torch\nn\modules\module.py in __getattr__(self, name)
537 return modules[name]
538 raise AttributeError("'{}' object has no attribute '{}'".format(
--> 539 type(self).__name__, name))
540
541 def __setattr__(self, name, value):
AttributeError: 'LabelModel' object has no attribute 'c_tree'
System info
- How you installed Snorkel (conda, pip, source):
conda
- OS:
Windows 10
- Python version:
3.7.4
- Snorkel version:
0.9.0
RicSpd