Skip to content

Instantly share code, notes, and snippets.

@funktor funktor/ Secret
Last active Oct 14, 2018

What would you like to do?
def extract_phrase(test_sentence, tagger):
test_features = sent2features(test_sentence)
pred_labels, phrase_chunks = tagger.tag(test_features), []
start, end = 0, 0
for idx in range(len(pred_labels)):
if pred_labels[idx] == 'B':
start = idx
elif pred_labels[idx] == 'E':
end = idx
phrase_chunks.append((start, end))
if end < start:
phrase_chunks.append((start, len(pred_labels)-1))
return [test_sentence[start:end+1] for start, end in phrase_chunks]
def extract_phrase_chunks(test_sentences, tagger):
output = [extract_phrase(sent, tagger) for sent in test_sentences]
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.