03. Machine Learning

Sentiment Classifier

Paste a restaurant or movie review and a feedforward neural network predicts its star rating on a 1 to 5 scale. All inference runs in your browser.

FFNN with one hidden layer (64 units, ReLU). Bag-of-words input. Trained on 8,000 Yelp reviews. Vocabulary: 8,000 most frequent tokens. Val accuracy: 61%.

Loading model...

Ctrl+Enter to classify

Predicted sentiment
Very Negative
0.0%
Negative
0.0%
Neutral
0.0%
Positive
0.0%
Very Positive
0.0%

How it works

The classifier was trained on 8,000 Yelp reviews with 1 to 5 star ratings. Each review is represented as a bag-of-words vector over the 8,000 most common tokens. The model is a two-layer feedforward neural network with 64 hidden units and a ReLU activation, trained using stochastic gradient descent with minibatches of 32.

Model weights are exported as JSON (4 MB) and loaded at startup. Inference is a sparse matrix-vector product done entirely in TypeScript, no WebAssembly or GPU required.

Accuracy note: 5-class star prediction is genuinely hard. The model reaches about 61% exact-match accuracy on held-out data (compared to 20% random chance). Adjacent-class errors (e.g., predicting 4 stars instead of 5) are common.