Desk2Mob

Desk2Mob

Desk2Mob

Getting Started with NLP and spaCy

Article 1: Getting Started with NLP and spaCy

Every time your phone finishes your sentence, your inbox sorts spam into its own folder, or a customer support bot responds sensibly to what you typed instead of asking you to "rephrase your query," there's a piece of software reading and processing human language. That's Natural Language Processing, or NLP for short, and it's a lot less mysterious than it sounds once you've built something with it yourself.

In this first article of the series, we'll cover what NLP actually is, why spaCy has become one of the go-to libraries for it in Python, and then write the first few lines of code together. No heavy theory, just enough to get you moving.

What exactly is NLP?

Computers are great with numbers and terrible with language. Human language is full of ambiguity. The word "bank," for example, can refer to a financial institution or the side of a river, and we rely on the surrounding words to decide which meaning applies. Humans do that without even thinking about it. Teaching a machine to get anywhere close is what NLP is about: taking messy, ambiguous, human-written text and turning it into something a program can actually work with.

That "something" could be as simple as counting how often a word shows up, or as involved as figuring out who did what to whom in a sentence. A few everyday examples:

Spam filters read the body of an email and decide whether it looks like a scam. Voice assistants turn "set a timer for ten minutes" into an actual action. Search engines figure out that "best pizza near me" and "top pizza places nearby" are asking the same question. None of that works on exact string matching alone - it works because the software can model, however roughly, what the words mean and how they relate to each other.

That's the job NLP does, and it's the foundation everything else in this series builds on.

Why spaCy?

If you have explored NLP in Python, you may have seen NLTK. It offers a broad collection of tools and is especially useful for learning individual NLP techniques. For this series, I chose spaCy because it provides a fast, consistent processing pipeline and a straightforward API for building applications. A lot of its core is written in Cython, and it offers trained pipelines that you can download, so you're not training anything from scratch just to get started.

spaCy also supports transformer-based pipelines if your project needs them later.

Installing spaCy

Getting set up takes a few steps: create a virtual environment, install the library, then download a language model. The venv step is easy to skip, but worth the extra couple of lines - it keeps spaCy and its dependencies isolated from whatever else is already installed on your system, so a different project's requirements don't fight with this one later. spaCy provides the processing framework and tokenizer; the separately installed en_core_web_sm pipeline adds trained components for tasks such as part-of-speech tagging, dependency parsing, and named entity recognition.

The commands below are for macOS and Linux - the activation step in particular (source ./venv/bin/activate) is platform-specific, and on Windows you'd activate the environment differently.

Shell (macOS/Linux)
$ python3 -m venv venv
$ source ./venv/bin/activate
(venv) $ python -m pip install spacy
(venv) $ python -m spacy download en_core_web_sm

en_core_web_sm is a small English pipeline. It downloads quickly and is enough for the examples in this article. Small pipelines do not include static word vectors, so if you later explore semantic similarity, you can install en_core_web_md or en_core_web_lg and update the name passed to spacy.load(). Larger pipelines require more memory, and whether they improve the results depends on the task. We'll come back to this in a future article.

Your First Look at NLP with spaCy

Let's actually run something. Once spaCy and the model are installed, this is all it takes to start processing text:

Python
import spacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("Desk2Mob is a blog about building things with AI and cloud tools.")

for token in doc:
    print(token.text, token.pos_, token.lemma_)

Running that gives you something like this:

Output
Desk2Mob PROPN Desk2Mob
is AUX be
a DET a
blog NOUN blog
about ADP about
building VERB build
things NOUN thing
with ADP with
AI PROPN AI
and CCONJ and
cloud NOUN cloud
tools NOUN tool
. PUNCT .

A few lines of code and spaCy has already done a surprising amount of work. Each row contains the original token, its part-of-speech label, and its lemma, or base form. For example, PROPN means proper noun, AUX means auxiliary verb, and DET means determiner. Notice that "is" has the lemma "be", while "building" has the lemma "build". Reducing a word to its base form like that is called lemmatization, and we'll get into it properly in a later article.

One thing worth keeping in mind: spaCy produces these annotations using a combination of trained components and language-specific rules. The results can occasionally be wrong, especially with unusual names, specialist terminology, or informal text.

The nlp(...) call is where the real work happens. Calling nlp(...) runs the configured pipeline and returns a Doc object. The Doc keeps the original text along with annotations produced by the pipeline, including tokens, part-of-speech tags, lemmas, sentence boundaries, dependency labels, and named entities. It's all sitting there, ready for you to use. We'll spend the next article picking that Doc object apart properly, along with sentence detection and tokenization in more depth.

For now, the takeaway is this: NLP is about giving computers some grip on human language, and spaCy makes getting started with it in Python remarkably straightforward.

Before moving on, try replacing the example sentence with one of your own. Compare the labels spaCy assigns and see whether any of its predictions surprise you.

Posted on September 04, 2026 by Desk2Mob in spaCy, NLP, AI, python


All Posts