| name | stanza-1-11-1 |
| description | Stanford NLP Group's Python NLP library for 80+ languages providing tokenization, POS tagging, lemmatization, dependency parsing, and NER via a neural pipeline built on PyTorch. Includes a Python wrapper for the Java Stanford CoreNLP server. Use when building multilingual NLP pipelines, performing linguistic analysis across languages, training custom models, or integrating biomedical/clinical NER. |
Stanza 1.11.1
Overview
Stanza is the Stanford NLP Group's official Python natural language processing library. It provides a full neural network pipeline for robust text analytics across 80 human languages, using the Universal Dependencies formalism. Built on PyTorch, it supports tokenization, multi-word token expansion, lemmatization, part-of-speech tagging, morphological features, dependency parsing, named entity recognition, sentiment analysis, constituency parsing, coreference resolution, and language identification.
Stanza also includes an officially maintained Python interface to the Java Stanford CoreNLP package, providing access to additional functionality such as constituency parsing (via CoreNLP), coreference resolution, and linguistic pattern matching with Semgrex and Ssurgeon.
Key features:
- Native Python implementation — no Java dependency required for neural pipeline
- Pretrained neural models supporting 80 human languages
- GPU-accelerated processing via PyTorch
- Biomedical and clinical English model packages for domain-specific NER and syntactic analysis
- Trainable on custom annotated data (CoNLL-U format for UD tasks, BIOES for NER)
- Python wrapper for Stanford CoreNLP Java server
When to Use
- Building multilingual NLP pipelines that need tokenization, POS tagging, lemmatization, or dependency parsing across many languages
- Performing named entity recognition on text in 23+ supported languages
- Analyzing biomedical literature or clinical notes with domain-specific models
- Needing constituency parse trees for English, Chinese, Indonesian, Italian, Japanese, or Vietnamese
- Detecting the language of unknown text and routing to language-specific pipelines
- Resolving coreference chains in documents (English, Hebrew)
- Training custom NLP models on your own annotated data
- Integrating Stanford CoreNLP Java functionality from Python code
- Performing linguistic pattern matching on dependency trees with Semgrex/Ssurgeon
Installation / Setup
Install via pip:
pip install stanza
Or via conda:
conda install -c stanfordnlp stanza
Requires Python 3.9+. Dependencies include PyTorch (>=1.13.0), numpy, protobuf (>=3.15.0), networkx, tqdm, and others. GPU is optional but recommended for faster processing.
Models are stored in ~/stanza_resources by default. Override with the STANZA_RESOURCES_DIR environment variable or the model_dir parameter.
Core Concepts
- Pipeline: The central object that chains together processors. Built with
stanza.Pipeline(lang, processors=...). Takes raw text or a Document and returns an annotated Document.
- Processors: Individual NLP task units (tokenize, mwt, pos, lemma, depparse, ner, sentiment, constituency, coref). Each has dependencies on earlier processors.
- Document/Sentence/Token/Word: The data objects hierarchy. A Document contains Sentences, each Sentence contains Tokens, and each Token wraps one or more Words (for multi-word tokens).
- Universal Dependencies: The formalism Stanza follows for POS tags (UPOS), morphological features (UFeats), and dependency relations. Models trained on UD v2.12 treebanks.
- BIOES tagging: The format used by the NER processor for token-level entity labels.
Usage Examples
Basic Pipeline
import stanza
stanza.download('en')
nlp = stanza.Pipeline('en')
doc = nlp("Barack Obama was born in Hawaii. He was elected president in 2008.")
doc.sentences[0].print_dependencies()
Selective Processors
import stanza
nlp = stanza.Pipeline('en', processors='tokenize,ner')
doc = nlp("Chris Manning teaches at Stanford University.")
for ent in doc.ents:
print(f"entity: {ent.text} type: {ent.type}")
Multilingual Pipeline
import stanza
nlp = stanza.Pipeline('fr', processors='tokenize,mwt,pos,lemma,depparse')
doc = nlp("Nous avons atteint la fin du sentier.")
for word in doc.sentences[0].words:
head_text = doc.sentences[0].words[word.head - 1].text if word.head > 0 else "root"
print(f"{word.text} -> {head_text} ({word.deprel})")
Sentiment Analysis
import stanza
nlp = stanza.Pipeline('en', processors='tokenize,sentiment')
doc = nlp("I love this product!")
print(doc.sentences[0].sentiment)
Language Identification
from stanza.pipeline.core import Pipeline
stanza.download('multilingual')
nlp = Pipeline(lang="multilingual", processors="langid")
doc = nlp("Bonjour le monde")
print(doc.lang)
Advanced Topics
Pipeline and Processors: Detailed processor configuration, custom processor variants, pretagged documents → Pipeline and Processors
Data Objects and Annotations: Document, Sentence, Token, Word, Span, ParseTree — properties and methods → Data Objects and Annotations
Processor Reference: Complete reference for each processor with options and examples → Processor Reference
Models and Downloads: Available models, languages, packages, manual download → Models and Downloads
Training Custom Models: Training your own Stanza models on annotated data → Training Custom Models
CoreNLP Client: Python wrapper for Stanford CoreNLP Java server, Semgrex, Ssurgeon → CoreNLP Client