Skip to content

Instantly share code, notes, and snippets.

@funktor
Last active October 14, 2018 09:03
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/49e82919efd5a8a8672661671fcdca93 to your computer and use it in GitHub Desktop.
Save funktor/49e82919efd5a8a8672661671fcdca93 to your computer and use it in GitHub Desktop.
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'
else:
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