Skip to content

Commit 414fc1d

Browse files
authored
add LF number check (#1428)
1 parent dc4331c commit 414fc1d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

snorkel/labeling/model/label_model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ def _set_class_balance(
547547

548548
def _set_constants(self, L: np.ndarray) -> None:
549549
self.n, self.m = L.shape
550+
if self.m < 3:
551+
raise ValueError(f"L_train should have at least 3 labeling functions")
550552
self.t = 1
551553

552554
def _create_tree(self) -> None:

test/labeling/model/test_label_model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def test_L_form(self):
3838
with self.assertRaisesRegex(ValueError, "L_train has cardinality"):
3939
label_model.fit(L, n_epochs=1)
4040

41+
L = np.array([[0], [1], [-1]])
42+
with self.assertRaisesRegex(ValueError, "L_train should have at least 3"):
43+
label_model.fit(L, n_epochs=1)
44+
4145
def test_class_balance(self):
4246
label_model = LabelModel(cardinality=2, verbose=False)
4347
# Test class balance

0 commit comments

Comments
 (0)