How to convert a token span into a character span with Spacy

Viewed 87

How do I get the character span in the original string from a token level span in a Spacy doc?


N = spacy.load('en_core_web_md')
text = 'Joe Biden is president of the US'
doc = N(text)
e = doc.ents[0]

# ??? get the character span, [0:9] in this case, from the token span (e.start==0, e.end==2) for a named entity
# so that text[ <<character-span>> ] == e.text

1 Answers
Related