RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
Glossary / Natural language processing / N-gram
Natural language processing

N-gram

An n-gram is a contiguous sequence of n items (usually tokens or characters) from a text. In local AI, n-grams appear in tokenization and language modeling: the tokenizer splits text into tokens, and the model predicts the next token based on the previous n-1 tokens. For operators, n-gram size affects context window usage and generation speed—larger n captures more context but increases memory and compute per token.

Deeper dive

N-grams are foundational to statistical language models and still relevant in neural models via tokenization. A unigram (n=1) treats each token independently; a bigram (n=2) considers the previous token; a trigram (n=3) considers the previous two. Modern LLMs use transformer architectures with attention over the full context, but tokenizers like BPE or SentencePiece still rely on n-gram statistics to build subword vocabularies. For operators, n-gram size in tokenization determines vocabulary size and compression ratio—larger n yields fewer tokens per word but a larger embedding table, impacting VRAM. In practice, most LLMs use subword tokenizers with n-gram-like merges (e.g., GPT-2 tokenizer uses byte-pair encoding with n-gram frequencies).

Practical example

When running Llama 3.1 8B via llama.cpp, the tokenizer uses a BPE model with a vocabulary of 128k tokens built from n-gram statistics. A word like 'unbelievable' might be split into ['un', 'belie', 'vable'] (3 tokens) vs. a character-level tokenizer that would use 12 tokens. Fewer tokens mean faster generation and less VRAM for the same context length.

Workflow example

In LM Studio, when you load a model, the tokenizer's n-gram-based vocabulary is loaded into VRAM. You can inspect tokenization by typing text in the chat box and seeing the token count—e.g., 'Hello world' might be 2 tokens. If you see unexpected splits, it's due to the n-gram merge rules learned during training. In Ollama, you can use ollama run llama3.1:8b and then /show info to see the model's tokenizer details.

Reviewed by Eruo Fredoline. See our editorial policy.

Buyer guides
  • Best GPU for local AI →
  • Best laptop for local AI →
  • Best Mac for local AI →
When it doesn't work
  • CUDA out of memory →
  • Ollama running slowly →
  • ROCm not detected →