NLP Interview Questions and Answers
Last updated 2026-11-19
Natural language processing interviews have moved from counting words to transformers, but the older ideas still appear because they are easy to test: TF-IDF, cosine similarity, n-gram models, tokenisation and evaluation metrics. A strong candidate can do the small calculations and also explain why modern models replaced them.
The questions below mix classical and modern topics with worked numbers. For the large-model side, including retrieval and prompting, continue with generative AI and LLM interview questions; for the neural building blocks see deep learning interview questions.
| Typical rounds | NLP theory, Python coding, case on a text problem |
|---|---|
| Core skills | Text processing, embeddings, transformers, evaluation |
| Questions here | 14 worked questions |
The shape of an NLP interview
- Text preprocessing choices and their effect on a classifier.
- Representations: bag of words, TF-IDF, static embeddings and contextual embeddings.
- Task framing: classification, sequence labelling, generation and retrieval.
- Evaluation: F1 at entity level, BLEU, ROUGE, perplexity.
- Practical issues: imbalance, domain shift, multilingual text and latency.
How to choose a representation
For a small labelled dataset and a fast baseline, TF-IDF with logistic regression is hard to beat on effort. When meaning matters beyond keywords, use pretrained sentence embeddings or fine-tune a transformer encoder. Start simple, measure, and move up only if the metric justifies the cost in latency and serving complexity.
NLP Interview Questions and Answers: questions with worked answers
1 Compare stemming and lemmatization.
easyStemming chops suffixes with rules, so "studies" becomes "studi" and "better" stays "better"; it is fast but can produce non-words. Lemmatization uses a dictionary and part of speech to return the real base form, so "studies" becomes "study" and "better" (adjective) becomes "good". Use stemming for quick search indexing and lemmatization when the word form matters. Modern transformer pipelines usually skip both and use subword tokens.
2 Compute a TF-IDF value. A term occurs 2 times in a 10-word document and in 1 of 3 documents.
easyTerm frequency = 2 / 10 = 0.2. Inverse document frequency = ln(3 / 1) = 1.0986. TF-IDF = 0.2 x 1.0986 = 0.2197. A term in every document gets idf = ln(3/3) = 0, so common words are down-weighted. Libraries use variations: scikit-learn uses ln((1 + n) / (1 + df)) + 1 and L2-normalises each row, so its numbers will differ from the textbook formula.
pythonfrom sklearn.feature_extraction.text import TfidfVectorizer docs = ['the cat sat', 'the dog sat', 'the cat ran away'] vec = TfidfVectorizer() X = vec.fit_transform(docs) print(vec.get_feature_names_out(), X.toarray().round(2))3 Compute cosine similarity of (1, 0) and (1, 1), and say why it is used for text.
easyCosine = dot product divided by the product of norms = (1 x 1 + 0 x 1) / (1 x sqrt 2) = 0.707, an angle of 45 degrees. It measures direction, not length, so a long and a short document on the same topic score high. Vectors (1, 2, 3) and (2, 4, 6) have cosine 1. For unit-length vectors cosine equals the dot product, which is why embedding indexes often normalise first.
4 Explain how Byte Pair Encoding builds a vocabulary. Use words hug (10), pug (5), pun (12), bun (4), hugs (5).
mediumStart from characters. Count adjacent pairs weighted by word frequency: ug appears 10 + 5 + 5 = 20 times, pu 5 + 12 = 17, un 12 + 4 = 16, hu 10 + 5 = 15. The most frequent pair, ug, becomes a new token, and counting repeats on the updated corpus. After the chosen number of merges you get a vocabulary of frequent subwords, so rare or unseen words split into pieces instead of becoming unknown. WordPiece and unigram models do the same job with different selection rules.
5 Word2Vec versus BERT embeddings: what is the difference?
mediumWord2Vec gives one fixed vector per word, learned by predicting context words (skip-gram) or the word from context (CBOW), so "bank" has a single vector for river and money senses. BERT produces a contextual vector for each token that depends on the whole sentence, so the two senses get different vectors. Word2Vec is tiny and fast. BERT-style models are far more accurate on most tasks but need much more compute.
6 BERT versus GPT: architecture and uses.
mediumBERT is an encoder trained with masked language modelling and sees context on both sides, making it suited to classification, tagging and embeddings. GPT is a decoder trained to predict the next token with a causal mask, so each token attends only to earlier ones, which suits text generation. Encoder-decoder models such as T5 map an input sequence to an output sequence and suit translation and summarisation. In practice large decoders now handle many tasks through prompting.
7 Build a quick text classifier and evaluate it.
easyUse a pipeline so vectorisation is fitted only on training data. TF-IDF with word and bigram features plus logistic regression is a strong baseline. Report precision, recall and F1 per class, not only accuracy, and look at the most influential words for sanity checking.
pythonfrom sklearn.pipeline import Pipeline from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.linear_model import LogisticRegression from sklearn.metrics import classification_report clf = Pipeline([('tfidf', TfidfVectorizer(ngram_range=(1, 2), min_df=2, sublinear_tf=True)), ('lr', LogisticRegression(max_iter=1000, class_weight='balanced'))]) clf.fit(X_train, y_train) print(classification_report(y_test, clf.predict(X_test)))8 How is named entity recognition framed, and how is it evaluated?
mediumIt is sequence labelling: each token gets a BIO tag, where B starts an entity, I continues it and O is outside. "Asha joined Infosys in Pune" is tagged B-PER O B-ORG O B-LOC. Evaluation is at the entity level: a prediction counts as correct only if both the span and the type match exactly. If the gold has 4 entities, the model predicts 5 and 3 match, precision is 3/5 = 0.6, recall 3/4 = 0.75 and F1 = 0.667. Token-level accuracy would be misleadingly high because most tokens are O.
9 What is perplexity? A model assigns probability 0.25 to each of four consecutive tokens.
mediumPerplexity is the exponential of the average negative log-likelihood per token, or equivalently the inverse geometric mean of token probabilities. Here the average NLL is -ln 0.25 = 1.386 and exp(1.386) = 4. It can be read as the effective number of equally likely choices the model is torn between at each step; lower is better. Perplexities are comparable only when the tokenisation and the test data are the same.
10 Explain BLEU's clipped precision with the candidate "the the the the the the the" and reference "the cat is on the mat".
mediumRaw unigram precision would be 7/7 = 1, which is absurd. BLEU clips each word's count at its maximum in any reference: "the" appears twice in the reference, so only 2 of 7 candidate words count, giving 2/7 = 0.286. BLEU combines clipped precisions for 1 to 4-grams by geometric mean and multiplies by a brevity penalty for short outputs. ROUGE is recall oriented and used for summarisation. Both reward surface overlap, so for modern generation, complement them with human or model-based judgement.
11 Greedy decoding versus beam search: show why they can differ.
mediumGreedy picks the highest-probability token at each step. Suppose the first token A has probability 0.5 and B has 0.4, and the best continuation after A has probability 0.4 while after B it is 0.9. Greedy takes A, ending at 0.5 x 0.4 = 0.20. Beam search with width 2 keeps both and finds B then its continuation with 0.4 x 0.9 = 0.36. Beam search favours short sequences unless length-normalised, and tends to give repetitive text, so open-ended generation uses sampling with temperature or top-p.
12 How do you handle class imbalance and noisy text in a classification task?
mediumFor imbalance use class weights, threshold tuning, and per-class metrics; resample inside training folds only. For noisy text such as social media, normalise case and repeated characters carefully, handle emojis and transliterated or code-mixed language (for example Hinglish) with subword or character n-gram features, and avoid aggressive stop-word removal for tasks like sentiment where "not" matters. Evaluate on text that looks like production traffic, not only a clean benchmark.
13 Why do transformers use positional encodings?
mediumSelf-attention is permutation invariant: without extra information, shuffling the tokens gives the same outputs up to the same shuffle. Positional information is added to embeddings, either as fixed sinusoids, learned vectors, or relative schemes such as rotary embeddings applied to queries and keys. Without it, "dog bites man" and "man bites dog" would look identical to the model.
Frequently asked questions
Is classical NLP still asked in interviews?
Yes. TF-IDF, n-grams, tokenisation and F1 for NER are easy to test and still used as baselines, so expect them alongside transformers.
Which libraries should I know?
scikit-learn, spaCy or NLTK for preprocessing, and Hugging Face Transformers for pretrained models. Know how to fine-tune a classifier and run inference.
How are NLP and LLM interviews different?
NLP interviews cover tasks, representations and metrics broadly. LLM interviews focus on prompting, retrieval, fine-tuning and serving. The LLM page covers those.
Do I need to know multilingual NLP?
For roles in India it helps: code-mixed text, transliteration and tokenisation across scripts are real problems, and multilingual models are the usual answer.
Related guides
More in Role-wise Interview Questions by Job and Tech Stack
- Node.js Interview Questions and Answers (Node 22)
- NumPy Interview Questions and Answers
- Pandas Interview Questions and Answers
- Performance Testing and JMeter Interview Questions
- Power BI Interview Questions and Answers
- Probability for Data Science Interview Questions and Answers
- Product Analyst Interview Questions and Answers
- PySpark Interview Questions and Answers
- React Hooks Interview Questions and Answers
- React Interview Questions and Answers (React 19)
- React Native Interview Questions and Answers
- Redux Interview Questions and Answers (Redux Toolkit)