Learn spaCy

Industrial-strength NLP pipelines for tokenizing, tagging, parsing and entities

17 lessons · 3 hours · 4 levels · covers spaCy 3.8

spaCy is a fast, production-oriented NLP library. A trained pipeline turns text into a Doc with tokens, lemmas, part-of-speech tags, dependency parses, sentences and named entities, and you can add rule-based matchers, custom components or transformer models. It is a common choice for information extraction and text processing services.

Before you start

spaCy builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics5 lessons · 46 min in total
2. PracticalUse it productively at work, with the usual idioms10 lessons · 2 hours in total
3. AdvancedThe less common features, performance and trade-offs14 lessons · 3 hours in total
4. ExpertInternals and the edge cases experts know17 lessons · 3 hours in total

The spaCy tree

spaCyInstalling spaCy and loading pipelinesInstalling spaCy andloading pipelinesDoc, Token and SpanDoc, Token and SpanToken attributes: lemma, POS, stop wordsToken attributes:lemma, POS, stop…Sentences and noun chunksSentences and nounchunksNamed entity recognitionNamed entityrecognitionDependency parsingDependency parsingRule-based matching: Matcher and PhraseMatcherRule-basedmatching: Matcher…EntityRuler and span rulersEntityRuler and spanrulersPipelines: components and nlp.pipePipelines:components and nl…Word vectors and similarityWord vectors andsimilarityModules and importsModules and importsVirtual environments and pipVirtual environmentsand pipSlicing sequencesSlicing sequencesComprehensionsComprehensionsDefining functionsDefining functionsIterators and generatorsIterators andgeneratorsDecoratorsDecoratorsMemory: reference counting and the GCMemory: referencecounting and the GCThreads, processes and concurrent.futuresThreads, processesand concurrent.fut…
Essentials and Practical shown (10 of 17 lessons); the full list is below. Click a lesson to read it.

All 17 lessons, in order

Getting started

  1. Installing spaCy and loading pipelines · Essentials · 8 min

    Install spaCy, download a trained pipeline package, and load it with spacy.load or start empty with spacy.blank.

  2. Doc, Token and Span · Essentials · 10 min

    Understand the Doc container, Token views and Span slices, and how spaCy's tokenization preserves the original text.

Linguistic features

  1. Token attributes: lemma, POS, stop words · Essentials · 10 min

    Read lemma_, pos_, tag_, is_stop, is_alpha, like_num, shape_ and more, and know why attributes come in string and hash forms.

  2. Sentences and noun chunks · Essentials · 8 min

    Split text into sentences with doc.sents, extract base noun phrases with doc.noun_chunks, and pick a sentence segmenter.

  3. Named entity recognition · Essentials · 10 min

    Extract people, organisations, places, dates and money with doc.ents, read labels, and set entities yourself.

  4. Dependency parsing · Practical · 12 min

    Navigate the syntactic tree with dep_, head, children and subtree to find who did what to whom.

  5. Word vectors and similarity · Practical · 10 min

    Use the word vectors in md and lg pipelines for token, span and document similarity, and know their limits.

Rule-based matching

  1. Rule-based matching: Matcher and PhraseMatcher · Practical · 15 min

    Find token patterns with the Matcher using attributes and operators, and large term lists with the PhraseMatcher.

  2. EntityRuler and span rulers · Practical · 10 min

    Add rule-based entities to the pipeline with the entity_ruler, combine it with the statistical NER, and manage overlaps.

Pipelines and components

  1. Pipelines: components and nlp.pipe · Practical · 12 min

    Inspect and control pipeline components, disable what you don't need, and process many texts fast with nlp.pipe.

  2. Custom components and extension attributes · Advanced · 15 min

    Write your own pipeline components with @Language.component or factories, and attach custom data via ._ extensions.

  3. Customising the tokenizer · Advanced · 12 min

    Add special cases and change prefix, suffix and infix rules so domain text such as code, units or hashtags tokenizes correctly.

Training and models

  1. Training pipelines with configs and DocBin · Advanced · 20 min

    Prepare annotated data as DocBin files, generate a config, and train and evaluate a pipeline with the spacy train CLI.

  2. Transformer and LLM pipelines · Advanced · 12 min

    Use transformer-based pipelines such as en_core_web_trf, fine-tune with spacy-transformers, and know where spacy-llm fits.

Internals and scale

  1. The config system, registries and architectures · Expert · 15 min

    Read and extend spaCy's config: interpolation, registered functions, model architectures and the tok2vec listener pattern.

  2. Vocab, StringStore and hashes · Expert · 12 min

    Understand how spaCy stores strings as 64-bit hashes, what lives in the Vocab and Lexemes, and how this affects memory.

  3. Serialization and scaling out · Expert · 12 min

    Save pipelines and Docs efficiently, ship Docs between processes with DocBin, and run spaCy at scale with multiprocessing.