Skip to content

Instantly share code, notes, and snippets.

@funktor funktor/ Secret
Last active Oct 14, 2018

What would you like to do?
def get_sequence_labels(sentences, phrases):
labels = [['O' for word in sent] for sent in sentences]
for idx in range(len(sentences)):
sent, phrase = sentences[idx], phrases[idx]
for chunk in phrase:
n = len(chunk)
for start in range(len(sent)-n+1):
if sent[start:start+n] == chunk:
if n == 1:
labels[idx][start] = 'B'
labels[idx][start+1:start+n-1] = ['I']*(n-2)
labels[idx][start] = 'B'
labels[idx][start+n-1] = 'E'
return labels
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.