How does Naive Bayes handle unseen or out-of-vocabulary tokens at inference time?

Quick Overview

Asks how a Naive Bayes text classifier treats words at prediction time that it never saw in training, and how that differs from words seen in training but never with a given class. Tests understanding of Laplace smoothing, vectorizer behavior and practical fixes for a high out-of-vocabulary rate.

How does Naive Bayes handle unseen or out-of-vocabulary tokens at inference time?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

How does Naive Bayes handle unseen or out-of-vocabulary tokens at inference time? Assume a text classifier such as a spam filter, trained on a bag-of-words representation. ```hint Two kinds of unseen A word can be missing from the training vocabulary entirely, or present in the vocabulary but never seen with one particular class. Ask which of the two smoothing was designed for. ``` ```hint Look at the smoothed estimate Write the smoothed probability of a word with zero count and check what it depends on in each class. ``` ### What a Strong Answer Covers - Separates tokens missing from the vocabulary from in-vocabulary words that have zero count in one class - States what happens to each case at inference, including what a standard vectorizer does with an unknown token - Explains, using the smoothed estimate, why scoring an unseen word would skew the prediction - Names practical fixes for a high out-of-vocabulary rate and their limits ### Follow-up Questions - How does the answer change for Bernoulli Naive Bayes, where the absence of a vocabulary word also counts? - How would you choose the frequency threshold for mapping rare words to an `<UNK>` token? - What does the hashing trick give up in exchange for removing out-of-vocabulary tokens? - The share of dropped tokens in production rises from 2% to 20%. What do you check and what do you change?

Overview: Asks how a Naive Bayes text classifier treats words at prediction time that it never saw in training, and how that differs from words seen in training but never with a given class. Tests understanding of Laplace smoothing, vectorizer behavior and practical fixes for a high out-of-vocabulary rate.

General logo
General
Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

How does Naive Bayes handle unseen or out-of-vocabulary tokens at inference time?

Assume a text classifier such as a spam filter, trained on a bag-of-words representation.

What a Strong Answer Covers Guidance

  • Separates tokens missing from the vocabulary from in-vocabulary words that have zero count in one class
  • States what happens to each case at inference, including what a standard vectorizer does with an unknown token
  • Explains, using the smoothed estimate, why scoring an unseen word would skew the prediction
  • Names practical fixes for a high out-of-vocabulary rate and their limits

Follow-up Questions Guidance

  • How does the answer change for Bernoulli Naive Bayes, where the absence of a vocabulary word also counts?
  • How would you choose the frequency threshold for mapping rare words to an <UNK> token?
  • What does the hashing trick give up in exchange for removing out-of-vocabulary tokens?
  • The share of dropped tokens in production rises from 2% to 20%. What do you check and what do you change?