Skip to content

Instantly share code, notes, and snippets.

@suryavanshi
Last active May 19, 2021 08:11
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 suryavanshi/c4596e233e872fbb2d8bb5faa4b963e7 to your computer and use it in GitHub Desktop.
Save suryavanshi/c4596e233e872fbb2d8bb5faa4b963e7 to your computer and use it in GitHub Desktop.
import spacy #Using Spacy version 2.2.3
nlp = spacy.load("en_core_web_lg")
inp_text = "My name is John Wick, I live in California"
doc = nlp(inp_text)
for ent in doc.ents:
print(ent.text, ent.start_char, ent.end_char, ent.label_)
new_tokens = []
for token in doc:
print("Text: "+ token.text + " Entity: "+ token.ent_type_ + token.ent_iob_)
if not token.ent_type_:
new_tokens.append(token.text)
else:
new_tokens.append('xxxx')
new_text = ' '.join(new_tokens)
print("new Text->", new_text) # My name is xxxx xxxx , I live in xxxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment