WRITE · TRACE · UNDERSTAND
Multinomial Naive Bayes
Count tokens per class with Laplace smoothing.
Your experiment
log_scores(documents, labels, query, vocabulary) returns log posterior scores (without normalization) for classes 0 and 1. Both classes have documents; vocabulary is nonempty and unique. Ignore query tokens outside vocabulary, use alpha=1 and empirical class priors.
Python runs in your browser. Your draft stays on this device.
What to look for
Count tokens per class with Laplace smoothing. Work in log space to avoid multiplying tiny probabilities; repeated tokens contribute repeatedly.
Watch your code work
Ready to experimentWrite a solution or load the worked answer, then choose Trace & check.
Step through arrays, variables and training curves produced by your own Python.