generated from mwc/lab_tinylm
Applying patch
This commit is contained in:
12
tlm/cli.py
12
tlm/cli.py
@@ -54,13 +54,13 @@ def generate(length, context_window_words, filepath, gutenberg, list_gutenberg,
|
||||
raise click.UsageError("No training data provided. Must specify at least one of --filepath, --gutenberg, or --mbox.")
|
||||
|
||||
# Train and generate
|
||||
model = TinyLanguageModel(n=context_window_words)
|
||||
model.train(corpus)
|
||||
tlm = TinyLanguageModel(n=context_window_words)
|
||||
tlm.train(corpus)
|
||||
if prompt:
|
||||
prompt_tokens = tokenize_text(prompt, tokenize_opts)
|
||||
else:
|
||||
prompt_tokens = None
|
||||
join_fn = ''.join if 'char' in tokenize_opts else None
|
||||
join_fn = ''.join if 'char' in tokenize_opts else join
|
||||
display_join = join_fn or join
|
||||
|
||||
if verbose:
|
||||
@@ -70,18 +70,18 @@ def generate(length, context_window_words, filepath, gutenberg, list_gutenberg,
|
||||
def step_callback(pattern, options, chosen):
|
||||
opts = textwrap.fill(', '.join(sorted(set(options))), width=60)
|
||||
rows.append([display_join(list(pattern)), opts, chosen])
|
||||
output = model.generate(length, prompt=prompt_tokens, join_fn=join_fn, step_callback=step_callback)
|
||||
output = tlm.generate(length, prompt=prompt_tokens, join_fn=join_fn, step_callback=step_callback)
|
||||
click.echo(tabulate(rows, headers=["Context", "Options", "Selected"], tablefmt="simple"))
|
||||
click.echo()
|
||||
|
||||
else:
|
||||
output = model.generate(length, prompt=prompt_tokens, join_fn=join_fn)
|
||||
output = tlm.generate(length, prompt=prompt_tokens, join_fn=join_fn)
|
||||
|
||||
click.echo(output)
|
||||
|
||||
if interact:
|
||||
import code
|
||||
code.interact(local=locals(), banner="Entering interactive shell. 'model' and 'output' are available.")
|
||||
code.interact(local=locals(), banner="Entering interactive shell. 'tlm' and 'output' are available.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user