100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

spaCy Cheat Sheet

spaCy Cheat Sheet

spaCy reference covering pretrained pipelines, tokenization, part-of-speech tagging, dependency parsing, named entity recognition, and similarity scoring.

2 PagesIntermediateApr 5, 2026

Pipeline Basics

Load a pipeline and process text.

python
import spacynlp = spacy.load("en_core_web_sm")   # python -m spacy download en_core_web_smdoc = nlp("Apple is looking at buying a UK startup for $1 billion.")for token in doc:    print(token.text, token.pos_, token.dep_, token.lemma_)

Entities & Noun Chunks

Extract named entities and noun phrases.

python
for ent in doc.ents:    print(ent.text, ent.label_)   # e.g. "Apple" ORG, "UK" GPE, "$1 billion" MONEYfor chunk in doc.noun_chunks:    print(chunk.text, chunk.root.text)from spacy import displacydisplacy.render(doc, style="ent", jupyter=True)

Similarity & Custom Components

Compare documents and extend the pipeline.

python
doc1 = nlp("I like cats")doc2 = nlp("I like dogs")print(doc1.similarity(doc2))           # requires vectors (md/lg models)@spacy.Language.component("custom_component")def custom_component(doc):    print("Doc length:", len(doc))    return docnlp.add_pipe("custom_component", last=True)

Pipeline Components

Stages inside a spaCy nlp pipeline.

  • tokenizer- splits text into Token objects
  • tagger- assigns part-of-speech tags
  • parser- dependency parsing and sentence boundaries
  • ner- named entity recognition
  • lemmatizer- reduces words to their base form
  • textcat- text classification component
  • en_core_web_sm/md/lg- small/medium/large pretrained English pipelines (md/lg include word vectors)
Pro Tip

en_core_web_sm has no real word vectors (only context-dependent tensors), so Doc.similarity() scores are unreliable with it — install en_core_web_md or en_core_web_lg if you need meaningful similarity comparisons.

Was this cheat sheet helpful?

Explore Topics

#SpaCy#SpaCyCheatSheet#DataScience#Intermediate#PipelineBasics#EntitiesNounChunks#SimilarityCustomComponents#PipelineComponents#MachineLearning#DevOps#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Related Glossary Terms

Share this Cheat Sheet