| name | nlp-pipeline-builder |
| description | Natural language processing ML pipelines for text classification, NER, sentiment analysis, text generation, and embeddings. Activates for "nlp", "text classification", "sentiment analysis", "named entity recognition", "BERT", "transformers", "text preprocessing", "tokenization", "word embeddings". Builds NLP pipelines with transformers, integrated with SpecWeave increments.
|
NLP Pipeline Builder
Overview
Specialized ML pipelines for natural language processing. Handles text preprocessing, tokenization, transformer models (BERT, RoBERTa, GPT), fine-tuning, and deployment for production NLP systems.
NLP Tasks Supported
1. Text Classification
from specweave import NLPPipeline
pipeline = NLPPipeline(
task="classification",
classes=["positive", "negative", "neutral"],
increment="0042"
)
pipeline.fit(train_texts, train_labels)
2. Named Entity Recognition (NER)
pipeline = NLPPipeline(
task="ner",
entities=["PERSON", "ORG", "LOC", "DATE"],
increment="0042"
)
3. Sentiment Analysis
pipeline = NLPPipeline(
task="sentiment",
increment="0042"
)
4. Text Generation
pipeline = NLPPipeline(
task="generation",
model="gpt2",
increment="0042"
)
Best Practices for NLP
Text Preprocessing
from specweave import TextPreprocessor
preprocessor = TextPreprocessor(increment="0042")
preprocessor.add_steps([
"lowercase",
"remove_html",
"remove_urls",
"remove_emails",
"remove_special_chars",
"remove_extra_whitespace"
])
preprocessor.add_advanced([
"spell_correction",
"lemmatization",
"stopword_removal"
])
Model Selection
Text Classification:
- Small datasets (<10K): DistilBERT (6x faster than BERT)
- Medium datasets (10K-100K): BERT-base
- Large datasets (>100K): RoBERTa-large
NER:
- General: BERT + CRF layer
- Domain-specific: Fine-tune BERT on domain corpus
Sentiment:
- Product reviews: DistilBERT fine-tuned on Amazon reviews
- Social media: RoBERTa fine-tuned on Twitter
Transfer Learning
pipeline = NLPPipeline(task="classification")
pipeline.use_pretrained("distilbert-base-uncased")
pipeline.use_pretrained_and_finetune(
model="bert-base-uncased",
epochs=3,
learning_rate=2e-5
)
Handling Long Text
pipeline = NLPPipeline(
task="classification",
max_length=512,
truncation_strategy="head_and_tail"
)
pipeline.use_model("longformer")
Integration with SpecWeave
.specweave/increments/0042-sentiment-classifier/
├── spec.md
├── data/
│ ├── train.csv
│ ├── val.csv
│ └── test.csv
├── models/
│ ├── tokenizer/
│ ├── model-epoch-1/
│ ├── model-epoch-2/
│ └── model-epoch-3/
├── experiments/
│ ├── distilbert-baseline/
│ ├── bert-base-finetuned/
│ └── roberta-large/
└── deployment/
├── model.onnx
└── inference.py
Commands
/ml:nlp-pipeline --task classification --model bert-base
/ml:nlp-evaluate 0042
/ml:nlp-deploy 0042
Quick setup for NLP projects with state-of-the-art transformer models.