TypeError: expected bytes, float found when I use crf.fit(X_train, y_train)

  python, python-crfsuite, scikit-learn

I try to implement CRF model to my NER application. I followed the tutorial in the official website from sklearn-crfsuite and generated the features using word2features function https://sklearn-crfsuite.readthedocs.io/en/latest/tutorial.html .
However, when I tried to fit the model with X, y using crf.fit(X_train, y_train), I got the TypeError:

C:ProgramDataAnaconda3libsite-packagessklearn_crfsuiteestimator.py in fit(self, X, y, X_dev, y_dev)
    312 
    313         for xseq, yseq in train_data:
--> 314             trainer.append(xseq, yseq)
    315 
    316         if self.verbose:

pycrfsuite_pycrfsuite.pyx in pycrfsuite._pycrfsuite.BaseTrainer.append()

C:ProgramDataAnaconda3libsite-packagespycrfsuite_pycrfsuite.cp38-win_amd64.pyd in vector.from_py.__pyx_convert_vector_from_py_std_3a__3a_string()

C:ProgramDataAnaconda3libsite-packagespycrfsuite_pycrfsuite.cp38-win_amd64.pyd in string.from_py.__pyx_convert_string_from_py_std__in_string()

TypeError: expected bytes, float found

One example of the input features X[1][2] :

X[1][2]

{'bias': 1.0,
 'word.lower()': 'zwiebelfliege',
 'word[-3:]': 'ege',
 'word[-2:]': 'ge',
 'word.isupper()': False,
 'word.istitle()': True,
 'word.isdigit()': False,
 'postag': 'NOUN',
 'postag[:2]': 'NO',
 '-1:word.lower()': 'die',
 '-1:word.istitle()': True,
 '-1:word.isupper()': False,
 '-1:postag': 'DET',
 '-1:postag[:2]': 'DE',
 '+1:word.lower()': '(',
 '+1:word.istitle()': False,
 '+1:word.isupper()': False,
 '+1:postag': 'PUNCT',
 '+1:postag[:2]': 'PU'}

Can someone give me a hint how to solve the error?

Source: Python Questions

LEAVE A COMMENT