Natural Language Processing with spaCy
- 28Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Define natural language processing (NLP).
28 questions
- 1
Define natural language processing (NLP).
Model answer
NLP is the process by which computer systems understand, parse, and extract human language from raw text.
Explanation
NLP involves converting unstructured text into structured data that computers can analyze, enabling tasks like information extraction and classification.
- 2
List four major areas within natural language processing.
Model answer
Named entity recognition (NER), part-of-speech tagging, syntactic parsing, and text categorization (or text classification).
Explanation
Other areas include coreference resolution and machine translation. These tasks help computers understand linguistic structure and meaning.
- 3
What is natural language understanding (NLU) and list two tasks associated with it.
Model answer
NLU is a computational linguistics field adjacent to NLP that focuses on understanding meaning. Tasks include relation extraction and question answering.
Explanation
Other NLU tasks include semantic parsing, summarization, sentiment analysis, and paraphrasing. NLU often powers chatbots and advanced comprehension systems.
- 4
Name three industries that use NLP and NLU.
Model answer
Finance, law, and academia (research).
Explanation
These industries use NLP for tasks like information extraction from financial documents, legal document analysis, and scholarly research.
- 5
Describe the process of information extraction in NLP and give an example.
Model answer
Information extraction transforms unstructured text into structured data by identifying relevant entities. For example, extracting company names, stocks, and indexes from financial news articles.
Explanation
It converts raw text into metadata, finding specific items of interest. NLP frameworks like spaCy enable this by leveraging syntactic and semantic features.
- 6
Explain text categorization (classification) and provide a real-world example.
Model answer
Text categorization assigns labels to text based on content. For example, spam detection classifies emails as spam or not spam using machine learning.
Explanation
It is used in legal settings to reduce document sets by classifying documents by relevance. The model learns patterns from labeled data.
- 7
What advantage does an NLP framework like spaCy have over simple gazetteer or list matching for information extraction?
Model answer
An NLP framework can leverage parsed syntactic and semantic information (e.g., part-of-speech tags, dependencies, coreference) to improve accuracy beyond simple string matching.
Explanation
Gazetteers only match exact strings, while NLP models understand context and relationships, enabling more robust extraction of entities and relations.
- 8
In what programming language is spaCy primarily available (as of 2021)?
Model answer
Python.
Explanation
spaCy is a Python library for NLP, though there may be community efforts for other languages like R.
- 9
Name two other NLP frameworks available in Python mentioned in the content.
Model answer
NLTK (Natural Language Toolkit) and Stanza.
Explanation
These are alternative frameworks for NLP, but spaCy is preferred for its performance and scalability.
- 10
List the four reasons given for choosing spaCy over other NLP frameworks.
Model answer
- Off-the-shelf models that benchmark well (fast and accurate). 2) Ability to leverage transformer models (like BERT). 3) Relatively easy custom training. 4) Scales well to large volumes of documents.
Explanation
spaCy was designed by Explosion AI specifically for production use at scale, with good performance and accuracy metrics (precision, recall, F-score).
- 11
How does spaCy leverage modern NLP methods?
Model answer
spaCy supports transformer models (often called BERT models) for state-of-the-art performance.
Explanation
Transformers allow spaCy to capture deep contextual relationships in text, improving accuracy on complex tasks.
- 12
What does it mean that spaCy 'scales well'?
Model answer
spaCy can efficiently process hundreds of thousands of documents in a relatively short time, especially with rules-based components.
Explanation
Built for production, spaCy handles large datasets without sacrificing speed, making it suitable for enterprise and research applications.
- 13
What is covered in Part 1 of the video series?
Model answer
Part 1 covers how to get the most out of spaCy's off-the-shelf features.
Explanation
The off-the-shelf models provide pre-trained capabilities for common NLP tasks without custom training.
- 14
What topics are addressed in Part 2 of the series?
Model answer
Part 2 covers rules-based components like the entity ruler, matcher, regex injection, and custom spaCy components.
Explanation
These tools allow solving domain-specific problems that off-the-shelf models cannot handle.
- 15
Describe the application demonstrated in Part 3.
Model answer
Part 3 applies lessons from Parts 1 and 2 to information extraction from financial documents, finding stocks, markets, indexes, and stock exchanges.
Explanation
This realistic example shows how to combine off-the-shelf and custom components for a common NLP task.
- 16
What is the recommended learning approach for this video series?
Model answer
First, watch the entire video to get an overview; second, replicate the code alongside the video; third, attempt the tasks independently without references.
Explanation
Using the accompanying textbook (at spacy.pythonhumanities.com) in tandem is also recommended for deeper understanding.
- 17
Where should you go to get installation instructions for spaCy?
Model answer
The spaCy website at spaCy.io/usage provides a user interface to select OS, package manager, and settings.
Explanation
The site gives tailored commands based on your environment (Windows/Mac/Linux, pip/conda, CPU/GPU, language).
- 18
What command installs spaCy via pip?
Model answer
pip install spacy
Explanation
Run this in a terminal or (in Jupyter) with an exclamation mark prefix.
- 19
How do you download the small English model for spaCy?
Model answer
Run the command: python -m spacy download en_core_web_sm
Explanation
This downloads the small English pipeline model, suitable for this course and many common tasks.
- 20
What is the recommended hardware setting for beginners using spaCy in this course?
Model answer
CPU, not GPU.
Explanation
GPU requires additional setup (CUDA) and is more advanced. CPU is simpler and sufficient for the course.
- 21
Which spaCy model is recommended for this course?
Model answer
The small English model: en_core_web_sm.
Explanation
This model is lightweight and fast, ideal for learning and many practical applications.
- 22
Write the Python code to import spaCy and create an nlp object for the small English model.
Model answer
import spacy nlp = spacy.load("en_core_web_sm")
Explanation
After installation, import the library and load the model to start processing text.
- 23
List the three main container types in spaCy that are most frequently used.
Model answer
Doc, Token, and Span.
Explanation
Other containers include Lexeme, Language, DocBin, and SpanGroup, but Doc, Token, and Span are central.
- 24
What is the Doc object in spaCy?
Model answer
The Doc object is the central container that holds all metadata about a text processed by the pipeline.
Explanation
It contains attributes like sentences (doc.sents) and tokens, and is the foundation for all spaCy operations.
- 25
Define a Token in spaCy.
Model answer
A Token is a word or punctuation mark in text that has independent syntactic or semantic value.
Explanation
Tokens are obtained by iterating over a Doc object and are more sophisticated than simple string splitting.
- 26
Define a Span in spaCy and give an example of a multi-token span.
Model answer
A Span is a slice of a Doc that can consist of one or more consecutive tokens. For example, "Martin Luther King" is a span of three tokens.
Explanation
Spans are useful for representing named entities or phrases that span multiple tokens.
- 27
How do you create a Doc object from a text string in spaCy?
Model answer
Pass the text string to the nlp object: doc = nlp("Your text here")
Explanation
The nlp object processes the text and returns a Doc containing all linguistic annotations.
- 28
What is the first step when working with a text file in spaCy, as shown in the example?
Model answer
Open the file using Python's open() function and read its contents into a string variable.
Explanation
The example uses 'with open("data/wiki_us.txt") as f: text = f.read()' to load the text.

Ask anything
We've read this whole study set, so questions about it get the best answers.