agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/ai-ml/nltk/SKILL.md

nltk

Skill15 starsChanged 44 days agoMITView on GitHub

Expert NLTK (Natural Language Toolkit) assistance covering tokenization, stemming, lemmatization, sentiment analysis, and POS tagging. Use when preprocessing text corpora and classical NLP tasks.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Prefer lemmatization over stemming (PorterStemmer) for human-readable root words.

    line 141
  2. Very specific:

    Call nltk.download() repeatedly on every request inside web handlers.

    line 148
  3. Distinctive:

    Use NLTK for high-throughput production tokenization.

    line 149
  4. Distinctive:

    Use WordNet lemmatizer without specifying POS tags if fine-grained verb/noun distinction is needed.

    line 150

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

NLTK

NLTK is the classic library for teaching and researching NLP. While slower than spaCy, it offers comprehensive linguistic data.

When to Use

  • Classical NLP & Linguistics: Tokenization, stemming, lemmatization, part-of-speech (POS) tagging, and syntactic parsing.
  • Rule-Based Sentiment Analysis: Quick heuristic sentiment scoring with VADER for social media texts.
  • Text Preprocessing for Classical ML: Cleaning corpus text for TF-IDF, Naive Bayes, and SVM models.
  • Educational & Linguistic Research: Analyzing word frequencies, collocations, and lexical dispersion across corpora.

Quick Start

import nltk
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords

nltk.download('punkt_tab')
nltk.download('stopwords')

text = "Natural Language Toolkit provides classical algorithms for text analysis."
tokens = word_tokenize(text)
stop_words = set(stopwords.words('english'))
filtered = [w for w in tokens if w.lower() not in stop_words and w.isalnum()]

print("Filtered tokens:", filtered)

Core Concepts

Tokenization, Stopwords & WordNet Lemmatization

Standard text normalization pipeline:

import nltk
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer
import string

# Ensure required corpora are downloaded
nltk.download('punkt_tab', quiet=True)
nltk.download('stopwords', quiet=True)
nltk.download('wordnet', quiet=True)

def preprocess_text(raw_text: str) -> list[str]:
    # 1. Lowercase and tokenize
    tokens = word_tokenize(raw_text.lower())

    # 2. Filter punctuation and English stopwords
    stop_words = set(stopwords.words('english'))
    filtered = [w for w in tokens if w.isalnum() and w not in stop_words]

    # 3. Lemmatize words to base dictionary form
    lemmatizer = WordNetLemmatizer()
    lemmatized = [lemmatizer.lemmatize(w) for w in filtered]

    return lemmatized

sample = "The distributed microservices were running exceptionally fast and scaling reliably!"
print("Cleaned Tokens:", preprocess_text(sample))

VADER Sentiment Analysis for Fast Heuristic Scoring

Rule-based sentiment intensity scoring:

from nltk.sentiment.vader import SentimentIntensityAnalyzer

nltk.download('vader_lexicon', quiet=True)
sia = SentimentIntensityAnalyzer()

reviews = [
    "Antigravity IDE is amazingly responsive and saves hours of tedious refactoring!",
    "The legacy codebase crashes constantly with unhelpful error messages.",
    "The software was delivered on Tuesday afternoon."
]

for review in reviews:
    scores = sia.polarity_scores(review)
    compound = scores['compound']
    sentiment = 'positive' if compound >= 0.05 else ('negative' if compound <= -0.05 else 'neutral')
    print(f"Sentiment: {sentiment:8s} (Score: {compound:+.2f}) | {review[:50]}...")

Part-of-Speech (POS) Tagging & Named Entity Chunking

Extracting grammatical structures from text:

nltk.download('averaged_perceptron_tagger_eng', quiet=True)
nltk.download('maxent_ne_chunker_tab', quiet=True)
nltk.download('words', quiet=True)

sentence = "Sundar Pichai announced new Gemini models at Google headquarters."
tokens = word_tokenize(sentence)
pos_tags = nltk.pos_tag(tokens)

# Extract named entities
chunks = nltk.ne_chunk(pos_tags)
for chunk in chunks:
    if hasattr(chunk, 'label'):
        print(f"Entity: {' '.join(c[0] for c in chunk)} [{chunk.label()}]")

Common Patterns

Lemmatization with POS (Part of Speech) Tagging

Problem: Simple stemmers truncate words unnaturally (running -> run, but better -> better).

Solution: Combine WordNetLemmatizer with POS tags:

from nltk.stem import WordNetLemmatizer
from nltk.corpus import wordnet
import nltk

nltk.download('averaged_perceptron_tagger_eng')
nltk.download('wordnet')

lemmatizer = WordNetLemmatizer()
# Lemmatize with explicit verb POS tag
print(lemmatizer.lemmatize("running", wordnet.VERB)) # Output: run
print(lemmatizer.lemmatize("better", wordnet.ADJ))   # Output: good

Best Practices

Do:

  • Prefer lemmatization over stemming (PorterStemmer) for human-readable root words.
  • Download specific corpora explicitly in setup scripts (nltk.download('punkt_tab')) to prevent runtime failures in Docker.
  • Leverage VADER for social media text where punctuation and capitalization convey sentiment.
  • Migrate to spaCy or Hugging Face transformers when semantic understanding or modern deep learning is required.

Don't:

  • Call nltk.download() repeatedly on every request inside web handlers; download once at build/container time.
  • Use NLTK for high-throughput production tokenization; use Hugging Face tokenizers or spaCy.
  • Use WordNet lemmatizer without specifying POS tags if fine-grained verb/noun distinction is needed.

Troubleshooting

ErrorCauseSolution
Resource punkt_tab not foundRequired NLTK dataset not downloaded locally.Add nltk.download('punkt_tab') before tokenization call.
LookupError: WordNet resource missingWordNet database not installed.Execute nltk.download('wordnet').
Slow tokenization on massive textNLTK regex tokenizers running single-threaded on millions of lines.Batch processing with multiprocessing or use Hugging Face tokenizers.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.