0Pricing
NLP Academy · Lesson

Extracting Phrases by Tag Pattern

Pull out noun chunks and verbs.

Extracting Phrases by Tag Pattern is a free NLP Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the NLP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

From Tags to Phrases

Single tags are useful, but meaning often lives in groups of words. Tag patterns let you pull out whole phrases instead of lone tokens. 🧩

What Is a Noun Chunk?

A noun chunk is a noun plus the words describing it, like the fluffy cat. These chunks usually name the key things a sentence is about.

Get Noun Chunks Free

spaCy finds noun chunks for you. Iterate over doc.noun_chunks to grab each one as a span without writing any rules.

for chunk in doc.noun_chunks:
    print(chunk.text)

Chunks Are Spans

Each noun chunk is a Span, a slice of the Doc. A span knows its text, start, and end, so you can reuse it like any other token group.

chunk = list(doc.noun_chunks)[0]
print(chunk.start, chunk.end)

Pull Out Every Verb

To collect actions, keep tokens whose pos_ is VERB. A list comprehension gathers them all in a single readable line.

verbs = [t.text for t in doc if t.pos_ == "VERB"]

Match Custom Patterns

For your own rules, use the Matcher. You describe a sequence of token attributes, and spaCy finds every place that sequence appears.

from spacy.matcher import Matcher
matcher = Matcher(nlp.vocab)

Define a Tag Sequence

A pattern is a list of dictionaries, one per token. This one matches an adjective followed by a noun, like fluffy cat.

pattern = [{"POS": "ADJ"}, {"POS": "NOUN"}]

Add the Pattern

Register your pattern under a name with matcher.add(). The name lets you group related rules and identify matches later.

matcher.add("ADJ_NOUN", [pattern])

Run the Matcher

Call the matcher on a Doc to get matches. Each result is a tuple of a match id plus the start and end token positions.

matches = matcher(doc)

Read Each Match

Slice the Doc with the start and end to turn a match into readable text. That slice is the phrase your pattern captured.

for mid, start, end in matches:
    print(doc[start:end].text)

Patterns Beat Regex Here

Tag patterns understand grammar, so they catch phrases regex would miss. Matching on POS is far cleaner than chasing exact letters.

Quick Check

Think about how to extract grouped nouns.

Recap

You extracted phrases two ways: built-in noun_chunks and custom tag patterns with the Matcher. Now you can mine grammar, not just words. 🎉

Frequently asked questions

Is the “Extracting Phrases by Tag Pattern” lesson free?

Yes — the full text of “Extracting Phrases by Tag Pattern” is free to read here on the web, and the NLP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the NLP Academy course, upgrade to CoddyKit PRO.

What will I learn in “Extracting Phrases by Tag Pattern”?

Pull out noun chunks and verbs. You practise NLP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start NLP Academy?

No prior experience is required. NLP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Extracting Phrases by Tag Pattern” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this NLP Academy lesson?

Yes. Every NLP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Nouns, Verbs, and Why Tags Matter
  2. Tagging Words With spaCy
  3. Extracting Phrases by Tag Pattern
  4. Dependency Parsing Basics
← Back to NLP Academy