python
15 lines · 1 tab
Dr. Elena Vasquez
Apr 2026
1 tab
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}$'}}]])
text = 'Customer referenced INC-102301 and requested refund after a payment failure.'
doc = nlp(text)
entities = [(ent.text, ent.label_) for ent in doc.ents]
matches = [doc[start:end].text for _, start, end in matcher(doc)]
print(entities)
print(matches)
1 file · python
Explain with highlit
I like spaCy for production NLP because it balances performance, ergonomics, and deployability. It is especially good for entity extraction, rule-based matching, and clean token-level processing. I often pair learned models with explicit match patterns when the domain has stable language conventions.
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
ruby
# Basic matching
email = "user@example.com"
email =~ /@/ # => 4 (position of match)
email.match?(/@/) # => true
# Capture groups
Regular expressions for pattern matching
ruby
regex
regular-expressions
by Sarah Mitchell
3 tabs
python
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)
Using Hugging Face transformers for modern NLP inference
hugging-face
transformers
nlp
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 re
text = 'INC-102301 resolved on 2026-04-06 after payment failure for order ORD-99182.'
patterns = {
'incident_id': r'INC-[0-9]{6}',
Regular expressions for extracting structured entities from raw text
regex
text-processing
parsing
by Dr. Elena Vasquez
1 tab
Share this code
Here's the card — post it anywhere.