[Hindi]NLP 20# Parts of Speech Tagging |NLP|Python 3|Natural Language Processing|2019
Code:
# -*- coding: utf-8 -*-
"""NLP_Ex13.ipynb
Automatically generated by Colaboratory.
"""
import spacy
nlp = spacy.load('en_core_web_sm')
doc = nlp(u"The quick brown fox jumped over the lazy dog's back.")
print(doc.text)
print(doc[4])
print(doc[4].pos_)
print(doc[4].tag_)
for token in doc:
print(f"{token.text:{10}} {token.pos_:{10}} {token.tag_:{10}} {spacy.explain(token.tag_)}")
doc = nlp(u"I read books on NLP.")
word = doc[1]
word.text
for token in doc:
print(f"{token.text:{10}} {token.pos_:{10}} {token.tag_:{10}} {spacy.explain(token.tag_)}")
doc = nlp(u"I read a book on NLP.")
word = doc[1]
for token in doc:
print(f"{token.text:{10}} {token.pos_:{10}} {token.tag_:{10}} {spacy.explain(token.tag_)}")
doc = nlp(u"The quick brown fox jumped over the lazy dog's back.")
POS_counts = doc.count_by(spacy.attrs.POS)
POS_counts
doc.vocab[84].text
doc[2].pos_
for k,v in sorted(POS_counts.items()):
print(f"{k} {doc.vocab[k].text:{5}}{v}")
TAG_counts = doc.count_by(spacy.attrs.TAG)
for k,v in sorted(TAG_counts.items()):
print(f"{k} {doc.vocab[k].text:{5}}{v}")
"""NLP_Ex13.ipynb
Automatically generated by Colaboratory.
"""
import spacy
nlp = spacy.load('en_core_web_sm')
doc = nlp(u"The quick brown fox jumped over the lazy dog's back.")
print(doc.text)
print(doc[4])
print(doc[4].pos_)
print(doc[4].tag_)
for token in doc:
print(f"{token.text:{10}} {token.pos_:{10}} {token.tag_:{10}} {spacy.explain(token.tag_)}")
doc = nlp(u"I read books on NLP.")
word = doc[1]
word.text
for token in doc:
print(f"{token.text:{10}} {token.pos_:{10}} {token.tag_:{10}} {spacy.explain(token.tag_)}")
doc = nlp(u"I read a book on NLP.")
word = doc[1]
for token in doc:
print(f"{token.text:{10}} {token.pos_:{10}} {token.tag_:{10}} {spacy.explain(token.tag_)}")
doc = nlp(u"The quick brown fox jumped over the lazy dog's back.")
POS_counts = doc.count_by(spacy.attrs.POS)
POS_counts
doc.vocab[84].text
doc[2].pos_
for k,v in sorted(POS_counts.items()):
print(f"{k} {doc.vocab[k].text:{5}}{v}")
TAG_counts = doc.count_by(spacy.attrs.TAG)
for k,v in sorted(TAG_counts.items()):
print(f"{k} {doc.vocab[k].text:{5}}{v}")
0 Comments