spaCy के साथ Natural Language Processing
Azadeh Mobasher
Principal Data Scientist
spaCy पहले टेक्स्ट को tokenize करके एक Doc ऑब्जेक्ट बनाता हैDoc को कई चरणों वाली processing pipeline में प्रोसेस किया जाता है
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp(example_text)
spaCy की NER पाइपलाइन:print([ent.text for ent in doc.ents])
sentencizer: वाक्य segmentation के लिए spaCy पाइपलाइन कंपोनेंट.text = " ".join(["This is a test sentence."]*10000)en_core_sm_nlp = spacy.load("en_core_web_sm") start_time = time.time() doc = en_core_sm_nlp(text)print(f"Finished processing with en_core_web_sm model in {round((time.time() - start_time)/60.0 , 5)} minutes")
>>> Finished processing with en_core_web_sm model in 0.09332 minutes
sentencizer पाइप जोड़ें:blank_nlp = spacy.blank("en")blank_nlp.add_pipe("sentencizer")start_time = time.time() doc = blank_nlp(text) print(f"Finished processing with blank model in {round((time.time() - start_time)/60.0 , 5)} minutes")
>>> Finished processing with blank model in 0.00091 minutes
nlp.analyze_pipes() किसी spaCy पाइपलाइन का विश्लेषण करता है ताकि पता चले:
pretty को True करने पर structured data लौटाने के बजाय एक टेबल प्रिंट होगी।import spacy
nlp = spacy.load("en_core_web_sm")
analysis = nlp.analyze_pipes(pretty=True)
spaCy के साथ Natural Language Processing