bhylu.com

Advertisements

AI Generative AI

Understand conditional generation without mistaking fluent output for evidence.

How it works

Generative models produce new sequences or other structured outputs from a learned distribution. Large language models use far richer representations than the tiny transition-count model below. This exercise estimates next-word counts from three original phrases and greedily follows them. It illustrates conditional generation only; it is not an LLM, chatbot or factual answer service.

Run the code

Try in playground loads this complete standard-library Python example without executing it. Choose Run when ready. Local review uses Python 3.12.14; the existing browser editor uses Pyodide 0.27.7. These small fictional examples need no account, external data, model-provider key or database service.

Download the complete generative-ai.py

Example

generative-ai.py

from collections import defaultdict, Counter

phrases = [["wash","trays","now"],["wash","trays","gently"],["pack","crates","now"]]
counts = defaultdict(Counter)
for words in phrases:
    for current, following in zip(words,words[1:]):
        counts[current][following] += 1
output = ["wash"]
for _ in range(2):
    options = counts.get(output[-1])
    if not options:
        break
    output.append(sorted(options,key=lambda word:(-options[word],word))[0])
print(" ".join(output))

Expected result

wash trays gently

The tie between gently and now is resolved alphabetically, making the result inspectable. Real autoregressive models estimate token distributions using many learned parameters. Generated text still needs factual verification, provenance and a policy for unsupported claims; fluency is not a source.

Technical references