CoolFace
Apppublic

Nahom-M/tokens-to-agents-01-ngrams

sourceHugging Facemitupdated 20d agoView on Hugging Face
2likes
App README

N-Gram Explorer

Interactive companion to Part 1 — N-grams of the Tokens to Agents series: building the LLM stack from first principles, from n-grams to secure AI agents.

Train unigram, bigram and trigram models on financial news, change the smoothing strength, and watch perplexity respond.

The result this demo is about

Laplace smoothing (α = 1) is the standard fix for zero probabilities. On this corpus it makes a trigram model 4.9× worse than counting single words. Tuning α recovers it, and interpolating all three orders beats every single model by 32%.

ModelUnsmoothedLaplace (α=1)Tuned α
1-gram329.1332.6329.1
2-gram∞469.6132.6
3-gram∞1,642.4358.4

Interpolated (0.2 / 0.4 / 0.4) → 90.0

Read the full write-up

Data

Financial PhraseBank (Malo et al., 2014), Sentences_50Agree — 4,846 financial news sentences. Sentiment labels are unused; only the text is modelled.


Nahom M. Birhan — PhD student, agentic AI security.