python
18 lines · 1 tab
Dr. Elena Vasquez
Apr 2026
1 tab
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
model_name = 'distilbert-base-uncased-finetuned-sst-2-english'
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
classifier = pipeline(
task='text-classification',
model=model,
tokenizer=tokenizer,
truncation=True,
)
texts = [
'The checkout flow is fast and intuitive.',
'Customer support never replied to my ticket.',
]
print(classifier(texts))
1 file · python
Explain with highlit
I use transformers when the text task justifies contextual modeling and the serving budget can handle it. The fastest path to value is usually starting with pretrained checkpoints, measuring latency, and then deciding whether quantization, distillation, or simpler baselines are sufficient. Fancy models still need boring operational discipline.
Related snips
python
from gensim.models import Word2Vec
sentences = [
['customer', 'refund', 'payment', 'issue'],
['login', 'authentication', 'password', 'reset'],
['delivery', 'shipment', 'tracking', 'delay'],
Word embeddings with gensim for semantic similarity tasks
word-embeddings
gensim
nlp
by Dr. Elena Vasquez
1 tab
python
from datasets import Dataset
from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
model_name = 'distilbert-base-uncased'
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=3)
Fine tuning transformer models for domain text classification
hugging-face
fine-tuning
transformers
by Dr. Elena Vasquez
1 tab
python
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
from sklearn.metrics import classification_report
pipeline = Pipeline([
Text vectorization with TF-IDF for strong classical baselines
tf-idf
nlp
text-classification
by Dr. Elena Vasquez
1 tab
python
import spacy
from spacy.matcher import Matcher
nlp = spacy.load('en_core_web_sm')
matcher = Matcher(nlp.vocab)
matcher.add('INCIDENT_ID', [[{'TEXT': {'REGEX': '^INC-[0-9]{6}$'}}]])
Natural language processing with spaCy pipelines and custom rules
spacy
nlp
entity-extraction
by Dr. Elena Vasquez
1 tab
Share this code
Here's the card — post it anywhere.