Skip to content

Instantly share code, notes, and snippets.

@funktor
Created October 13, 2018 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funktor/5ca2d673d67bf9099a06d5a88c01a97f to your computer and use it in GitHub Desktop.
Save funktor/5ca2d673d67bf9099a06d5a88c01a97f to your computer and use it in GitHub Desktop.
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