A test set only works if the model has never seen it. When test examples sneak into the training data, your results look better than they really are. This is called data leakage.
Let's check our own data. The key function normalises a message. Lower case, no exclamation marks or full stops, and single spaces. We count unique training messages. Then we look for test messages, whose key also appears in training. Run it. Eight training messages were near duplicates. And four test messages also appear in the training data. Our test set leaks a little. We should remove those four, before trusting our score.
app.pypython
from datasets import load_datasetdata = load_dataset("json", data_files={"train": "tickets_train.jsonl", "test": "tickets_test.jsonl"})def key(text): return " ".join(text.lower().replace("!", "").replace(".", "").split())train_keys = [key(m) for m in data["train"]["message"]]print("Train messages: ", len(train_keys))print("Unique after cleaning: ", len(set(train_keys)))leaks = [m for m in data["test"]["message"] if key(m) in set(train_keys)]print("Test messages also in train:", len(leaks))for m in leaks[:3]: print(" ", m)
Output
Train messages: 527
Unique after cleaning: 519
Test messages also in train: 4
please refund dune, i changed my mind. cheers
Hi, Is Beloved on sale at the moment?
Is Beloved available in the Bath shop?
How do you avoid leakage? Remove duplicates before you split. Split by something bigger than one example, when it makes sense. For example, by customer, or by date. Then no customer appears in both sets. And keep a final test set, that you never look at until the very end.
Let's recap. Leakage means test examples sneak into training. It makes scores look too good. Normalise and compare messages to find it. And dedup before splitting. Next, how much data you actually need.