How do n-gram features capture contextual information that unigrams miss?

Quick Overview

How do n-gram features recover word order and local phrases that a bag of unigrams loses? The question tests text feature engineering: negation and multi-word expressions, how far n-gram context reaches, and how to control vocabulary growth and sparsity.

How do n-gram features capture contextual information that unigrams miss?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: easy

Interview Round: Other

Consider a bag-of-words text classifier, such as a sentiment model built on word counts or TF-IDF. How do n-gram features capture contextual information that unigrams miss? ```hint Compare two sentences Pick two short sentences that use almost the same words but mean different things, and list the features each one produces under unigrams and under bigrams. ``` ### What a Strong Answer Covers - Which information a bag of unigrams throws away, with concrete examples. - How n-gram features recover part of it, and how a linear model uses them. - How far the recovered context reaches and what stays out of reach. - The cost in vocabulary size and sparsity, and the usual ways to control it. - Where n-gram features stand relative to embeddings and transformer models. ### Follow-up Questions - Your bigram vocabulary has 5 million entries on 200,000 documents. How do you cut it down, and what does each option cost? - What do you gain and lose with the hashing trick compared with a fitted vocabulary? - When would character n-grams work better than word n-grams? - How would you handle a negation that spans more than two tokens, such as "not very good"?

Overview: How do n-gram features recover word order and local phrases that a bag of unigrams loses? The question tests text feature engineering: negation and multi-word expressions, how far n-gram context reaches, and how to control vocabulary growth and sparsity.

PracHub logo
General
Nov 24, 2026
easyMachine Learning EngineerOtherMachine Learning
0
0

Consider a bag-of-words text classifier, such as a sentiment model built on word counts or TF-IDF. How do n-gram features capture contextual information that unigrams miss?

What a Strong Answer Covers Guidance

  • Which information a bag of unigrams throws away, with concrete examples.
  • How n-gram features recover part of it, and how a linear model uses them.
  • How far the recovered context reaches and what stays out of reach.
  • The cost in vocabulary size and sparsity, and the usual ways to control it.
  • Where n-gram features stand relative to embeddings and transformer models.

Follow-up Questions Guidance

  • Your bigram vocabulary has 5 million entries on 200,000 documents. How do you cut it down, and what does each option cost?
  • What do you gain and lose with the hashing trick compared with a fitted vocabulary?
  • When would character n-grams work better than word n-grams?
  • How would you handle a negation that spans more than two tokens, such as "not very good"?