Python Part-of-Speech Tagging Example PDF
Document Details
![SweetSerendipity2396](https://quizgecko.com/images/avatars/avatar-3.webp)
Uploaded by SweetSerendipity2396
Shrinithi S
Tags
Summary
This is a Python code snippet demonstrating part-of-speech (POS) tagging using the spaCy library. It shows how to load a spaCy model and use it to tag the parts of speech in a given sentence.
Full Transcript
## Shrinithi S 221501135 ```python import spacy nlp = spacy.load("en_core_web_sm") def pos_tagging(text): doc = nlp(text) print(f"{'word':<15} {'Coarse-Grained POS':<20} {'Fine-Grained POS':<20}") print("-" * 60) for token in doc: print(f"{token.text:<15} {token.pos_:<20} {token.tag_:...
## Shrinithi S 221501135 ```python import spacy nlp = spacy.load("en_core_web_sm") def pos_tagging(text): doc = nlp(text) print(f"{'word':<15} {'Coarse-Grained POS':<20} {'Fine-Grained POS':<20}") print("-" * 60) for token in doc: print(f"{token.text:<15} {token.pos_:<20} {token.tag_:<20}") text = "The quick brown fox jumps over the lazy dog." pos_tagging(text) ``` | Word | Coarse-Grained POS | Fine-Grained POS | |---|---|---| | The | DET | DT | | quick | ADJ | JJ | | brown | ADJ | JJ | | fox | NOUN | NN | | jumps | VERB | VBZ | | over | ADP | IN | | the | DET | DT | | lazy | ADJ | JJ | | dog | NOUN | NN | | . | PUNCT | . |