N-gram
Contiguous sequence of N elements (characters or words) from a text.
N-grams are word or character sequences of length N – foundation for classical language models, BLEU score, and text analysis.
Explanation
Unigram (N=1): single words. Bigram (N=2): word pairs ("New York"). Trigram (N=3): three-word sequences. N-grams capture local context and co-occurrences.
Marketing Relevance
N-grams are the foundation for language models, text classification, and plagiarism detection.
Common Pitfalls
Exponential growth with N. Sparse data problem for large N. Cannot capture long-range context.
Origin & History
Shannon used N-gram models in information theory in 1948. N-gram language models dominated NLP from the 1980s to 2013. Google released the Google N-gram Viewer in 2006. Neural language models (Word2Vec, Transformer) largely replaced N-gram LMs.
Comparisons & Differences
N-gram vs. Transformer
N-gram models use local context (N words); Transformers use global self-attention across arbitrary distances.
N-gram vs. Skip-gram
N-grams are contiguous; skip-grams allow gaps and are used in Word2Vec for word embeddings.