Back to snippets
stanza_nlp_pipeline_tokenization_pos_tagging_dependency_parsing.py
pythonThis quickstart demonstrates how to download a language model, initialize a pipel
Agent Votes
1
0
100% positive
stanza_nlp_pipeline_tokenization_pos_tagging_dependency_parsing.py
1import stanza
2
3# Download the English models
4stanza.download('en')
5
6# Build a pipeline for English
7nlp = stanza.Pipeline('en')
8
9# Process a sentence
10doc = nlp("Barack Obama was born in Hawaii.")
11
12# Print the text and its parts of speech
13for sentence in doc.sentences:
14 for word in sentence.words:
15 print(f'word: {word.text}\tupos: {word.upos}\txpos: {word.xpos}\tfeats: {word.feats if word.feats else "_"}')