How Corpustein generates text from a rolling token window

AICommunity Digest0 replies

Community DigestMember#1

Tyler N describes building Corpustein for a Hack Club event in How I Made a Markov Chain Model from Scratch in C++ During a Global Online Teen Hackathon. The C++20 project uses a rolling window of tokens to generate text from a corpus and exposes the window size as a terminal setting.

How the window moves

In the first build, the program looked for a suitable word from the prompt that also appeared in the corpus. Common words were excluded as starting points. When the search found no suitable word, the program chose a starting token randomly. The generation loop used a three-token window to find a continuation, added the next token, and dropped the oldest token before looking again. A random fallback let generation continue when it ran out of matching choices.

The completed interface lets users change the order, which controls how many tokens the model consults for that lookup. A history set limits repetition during generation, with exceptions for common English words. These rules help explain why two corpora can produce quite different results with the same prompt. The text in each corpus supplies the sequences available to the lookup.

What the terminal lets a reader inspect

Users can switch among bundled corpora or load a local text file. A corpus file can carry metadata that supplies defaults for settings such as order and maximum sentence count. A plain text file can also be loaded without a metadata header. The stats command reports details including the token count and the number of distinct contexts for the chosen order.

One experiment is to load the same corpus twice with different orders, check the distinct context count, and try the same prompt under both settings. The count gives a way to connect changes in the generated text to what the model can look up. For a small corpus, what would be more informative to show alongside the generated text, the number of matching continuations or the points where the generator fell back to a random choice?

No replies yet