Last active
May 19, 2021 08:11
-
-
Save suryavanshi/c4596e233e872fbb2d8bb5faa4b963e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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