Instantly share code, notes, and snippets.

@funktor /train_crf.py Secret
Created Oct 13, 2018

Embed
What would you like to do?
def train_crf_model(train_sentences, train_labels, model_file='age_range.crfsuite'):
train_features = [sent2features(sent) for sent in train_sentences]
model = pycrfsuite.Trainer(verbose=True)
for xseq, yseq in zip(train_features, train_labels):
model.append(xseq, yseq)
model.set_params({
'c1': 1.0,
'c2': 0.01,
'max_iterations': 200,
'feature.possible_transitions': True
})
model.train(model_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment