Your question is Python Function for a Basic Gen Model. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
JPMorganChase is evaluating lightweight text-generation components for internal AI assistants. Implement a token-level generative model without external machine learning libraries.
Given a training corpus, build an interpolated n-gram model that predicts the next token from the longest available context. Apply additive smoothing so every vocabulary token remains possible, back off to shorter contexts when a context was not observed, and generate a reproducible continuation using a seeded random number generator.
Implement generate_text(corpus, prompt, order, max_tokens, temperature, seed).
corpus and prompt are non-empty whitespace-separated strings.order is the maximum context length.max_tokens is the number of tokens to generate, excluding the prompt.temperature controls randomness. A value of 0 selects the highest-probability token; positive values sample from temperature-adjusted probabilities.seed initializes Python's pseudorandom generator.max_tokens is zero.Use additive smoothing with a fixed alpha of 0.1. If several tokens have the same highest probability at temperature 0, choose the lexicographically smallest token.
def generate_text(corpus, prompt, order, max_tokens, temperature, seed):