File tree 1 file changed +5
-6
lines changed
1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -355,6 +355,11 @@ def fit(
355
355
# extract features and labels
356
356
feats : List [Dict [str , bool ]] = extract_features (sequence )
357
357
labels : List [str ] = extract_labels (sequence )
358
+ if all (label == "0" for label in labels ):
359
+ raise ValueError (f"only negative labels found in sequence { sequence [0 ].source .id !r} " )
360
+ elif all (label == "1" for label in labels ):
361
+ raise ValueError (f"only positive labels found in sequence { sequence [0 ].source .id !r} " )
362
+
358
363
# check we have as many observations as we have labels
359
364
if len (feats ) != len (labels ):
360
365
raise ValueError ("different number of features and labels found, something is wrong" )
@@ -366,12 +371,6 @@ def fit(
366
371
training_features .append (feats [win ])
367
372
training_labels .append (labels [win ])
368
373
369
- # check labels
370
- if all (label == "1" for y in training_labels for label in y ):
371
- raise ValueError ("only positives labels found, something is wrong." )
372
- elif all (label == "0" for y in training_labels for label in y ):
373
- raise ValueError ("only negative labels found, something is wrong." )
374
-
375
374
# fit the model
376
375
self .model = model = sklearn_crfsuite .CRF (** self ._options )
377
376
model .fit (training_features , training_labels )
You can’t perform that action at this time.
0 commit comments