I am trying to perform hyperparameter tuning on sklearn_crfsuite.CRF model. When I try to execute below code, it doesn't give any exception but it probably fails to perform fit. And due to which, if I try to get best estimator from grid search, it doesn't work.

# define fixed parameters and parameters to search
crf = sklearn_crfsuite.CRF(
params_space = {
    "c1": [0,0.05,0.1, 0.25,0.5,1],
    "c2": [0,0.05,0.1, 0.25,0.5,1]

# use the same metric for evaluation
f1_scorer = make_scorer(metrics.flat_f1_score,
                        average='weighted', labels=labels)

# search
grid_search = GridSearchCV(estimator=crf,
                           n_jobs=-1, verbose=1,scoring=f1_scorer)

#grid_search.fit(X_train, Y_train)
#above code throws exception, which seems to be a open bug in latest version of scikit-learn 0.24.0 or later.
#github link for bug: https://github.com/TeamHG-Memex/sklearn-crfsuite/issues/60
    grid_search.fit(X_train, Y_train)
except AttributeError as e:
     if "'CRF' object has no attribute 'keep_tempfiles'" not in str(e):

Any help would be appreciated, how can I perform hyperparameter tuning here?

I took reference using this tutorial, but stuck in same situation.


1 Answer 1


I don't know how could we resolve it in sci-kit version 0.24 or later but when I downgraded it to 0.23.2 version, same piece of code seems to be working fine.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.