LLM Engineering · Exercise 6 of 6 Previous
Advanced
Is the test set in the training text?
Write ngrams(text, n) returning the set of n-word runs of a text: lower-case it, turn every character that is not a letter or digit into a space, split into words, and join each run of n consecutive words with a single space. A text with fewer than n words gives an empty set.
Write overlap_percent(test, train, n) returning the whole-number percentage (100 * hits // total) of the test text's n-grams that also appear in the training text's n-grams. If the test text has no n-grams, return 0.
What Check tests
ngramslower-cases and builds word runs- Punctuation does not glue words together
- A text shorter than n has no n-grams
- A fully copied item scores 100
- A broken-up copy scores 0, and a short item scores 0
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.