NLTK Cheat Sheet
NLTK natural language toolkit reference covering tokenization, stopword removal, stemming, lemmatization, part-of-speech tagging, and named entity chunking.
2 PagesBeginnerApr 8, 2026
Tokenization
Split text into sentences and words.
python
import nltknltk.download("punkt")nltk.download("stopwords")nltk.download("averaged_perceptron_tagger")from nltk.tokenize import word_tokenize, sent_tokenizetext = "NLTK is a leading platform for building Python NLP programs."sentences = sent_tokenize(text)words = word_tokenize(text)
Stopwords, Stemming & Lemmatization
Normalize tokens for downstream tasks.
python
from nltk.corpus import stopwordsfrom nltk.stem import PorterStemmer, WordNetLemmatizerstop_words = set(stopwords.words("english"))filtered = [w for w in words if w.lower() not in stop_words]stemmer = PorterStemmer()stemmed = [stemmer.stem(w) for w in filtered] # e.g. "running" -> "run"lemmatizer = WordNetLemmatizer()lemmas = [lemmatizer.lemmatize(w) for w in filtered] # dictionary-form words
POS Tagging & Named Entities
Tag parts of speech and chunk entities.
python
from nltk import pos_tag, ne_chunktagged = pos_tag(word_tokenize("Apple is looking at buying a UK startup."))# [('Apple', 'NNP'), ('is', 'VBZ'), ('looking', 'VBG'), ...]tree = ne_chunk(tagged) # named entity chunks: PERSON, ORGANIZATION, GPEprint(tree)
Key Modules
Main areas of the NLTK library.
- nltk.tokenize- splits text into sentences/words
- nltk.corpus- built-in corpora and lexicons (stopwords, wordnet, movie_reviews)
- nltk.stem- PorterStemmer, SnowballStemmer, WordNetLemmatizer
- nltk.tag- part-of-speech tagging
- nltk.chunk- shallow parsing / named entity chunking
- nltk.classify- Naive Bayes and other text classifiers
- nltk.sentiment- VADER sentiment analyzer (SentimentIntensityAnalyzer)
Pro Tip
Call nltk.download() for each resource you use (punkt, stopwords, wordnet, etc.) once per environment before running tokenizers or taggers — NLTK ships as a thin library with its data downloaded separately, so a fresh install raises LookupError until resources are fetched.
Was this cheat sheet helpful?
Explore Topics
#NLTK#NLTKCheatSheet#DataScience#Beginner#Tokenization#StopwordsStemmingLemmatization#POS#Tagging#MachineLearning#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance