S

04 / 04 LSTM reviews · Feb 2026

Generating reviews, then catching them.

A language model that writes Amazon-style product reviews, and a discriminator that tells them from real ones. Every part is built from scratch: the tokeniser, the n-gram baseline, the 3.47M-parameter LSTM, and the 1D-CNN detector at 91% accuracy.

Role
Sole author · coursework, Imperial
When
Feb 2026
Stack
Python, PyTorch
Result
perplexity 677 → 106 · detector F1 0.91

01 — Problem

How good does a fake have to be, and can it still be caught?

Two questions in one project. First, how far a small recurrent model gets at writing convincing reviews from 393K real ones. Second, whether a discriminator trained on the output can still tell them apart, which is the question that matters for review platforms.

02 — Method

Tokenise, baseline, model, detect.

Tokeniser. Byte-pair encoding implemented from scratch to an 8K subword vocabulary. Encoding is cached per word, which made tokenising the corpus about 30× faster than the naive loop.

Baseline. A Laplace-smoothed trigram model over 36.2M trigram events, so the LSTM's perplexity has something honest to be compared with.

Language model. A 3.47M-parameter LSTM trained on the tokenised reviews. Held-out perplexity fell from 677 (the baseline) to 106, an 84% reduction.

Detector. A 1D convolutional network over token sequences, trained on real reviews against generated ones. It detects generated reviews at 91% accuracy with an F1 of 0.91.

Fig. III dByte-pair encoding on a review corpus. The most frequent pair merges each step; a sentence retokenises.

03 — Results

The numbers, and what they mean.

106held-out perplexity, LSTM
677held-out perplexity, trigram
−84%perplexity reduction
91%detector accuracy
0.91detector F1

A perplexity of 106 on an 8K vocabulary means the model is choosing among roughly a hundred plausible next tokens where the trigram baseline was choosing among nearly seven hundred. The detector's 91% says the output is still recognisably synthetic to a small convolutional network, which is the more useful result for anyone running a review platform.

[Add: training set size and split, sequence length, epochs, and one example generated review.]

04 — Stack

What it is made of.

01 Output 02 Models 03 Tokens 04 Data 05 Training TEXT MERGES TOKENS TOKENS BASELINE SAMPLE FAKE REAL GENERATED REVIEW VERDICT LSTM · 3.47M TRIGRAM BASELINE 1D-CNN BPE 8K VOCABULARY ENCODING CACHE 393K REVIEWS PYTORCH GPU 01 Output 02 Models 03 Tokens 04 Data 05 Training GENERATED REVIEW VERDICT LSTM · 3.47M TRIGRAM BASELINE 1D-CNN BPE 8K VOCABULARY ENCODING CACHE 393K REVIEWS PYTORCH GPU

System design5 layers, 10 flows. Arrows are the data path; dashed ones are side channels. Hover a layer.