Tokenization and text representations
Compare sparse counts and learned semantic representations.
Choose lexical or semantic features based on the task and evaluate on held-out text.
Interview questions
Choose a question to reveal its answer.
01EasyCoreVisualWhat is tokenization in NLP?
Answer
What is tokenization in NLP?
Segments text into units such as words, characters or subwords.
Split a sentence before passing token IDs to a model.
02EasyCoreHow does stemming work?
Answer
How does stemming work?
Heuristically strips affixes and may produce nonwords.
Map related word variants to a crude root.
03EasyCoreHow does lemmatization differ from stemming?
Answer
How does lemmatization differ from stemming?
Maps inflected words to dictionary forms using linguistic information.
Convert was to be when appropriate.
04MediumHigh priorityWhat information does bag-of-words lose?
Answer
What information does bag-of-words lose?
Represents a document by token counts without sequence order.
Create sparse features for a simple spam classifier.
05MediumHigh priorityHow can n-grams capture local word order?
Answer
How can n-grams capture local word order?
Contiguous sequence of n tokens.
Use two-word phrases to retain limited local order.
06MediumHow does TF-IDF weight words?
Answer
How does TF-IDF weight words?
Weights term frequency by inverse document frequency to emphasize discriminative terms.
Downweight words appearing in almost every document.
from sklearn.feature_extraction.text import TfidfVectorizer
v = TfidfVectorizer()
X = v.fit_transform(['ai helps', 'ai learns'])
print(v.get_feature_names_out())The vectorizer learns vocabulary and IDF weights from its fit corpus.
07MediumWhy use dense embeddings instead of sparse word counts?
Answer
Why use dense embeddings instead of sparse word counts?
Learned dense numeric representation of an item.
Represent words as vectors for similarity comparisons.
08MediumWhat is an out-of-vocabulary token?
Answer
What is an out-of-vocabulary token?
Input unit missing from a fixed vocabulary.
Handle a rare name absent from a word-level dictionary.
09HardHow does subword tokenization handle unfamiliar words?
Answer
How does subword tokenization handle unfamiliar words?
Represents words with reusable pieces, helping handle unfamiliar words.
Split a novel technical word into known segments.
10HardWhy do transformers need padding masks?
Answer
Why do transformers need padding masks?
Indicates positions that should not contribute as real tokens.
Prevent a transformer from attending to padding.
Priority and difficulty are editorial study recommendations.
Technical reference: Documentation / paper ↗
Try a few practice questions
Explore the questions before creating a free account.
1. Which representation preserves no word order by itself?
2. Which technique tends to downweight words appearing in nearly every document?
3. Why are subword tokenizers useful for rare words?
NLP tasks and evaluation
Continue to the next set of interview questions.