<jupyter_start><jupyter_text>Example: GeneratedLM>  Used on Hunggingface's Model<jupyter_code># load pretrained model and vocab
lm = AutoModelWithLMHead.from_pretrained('distilgpt2')
lm.eval()
tokenizer = AutoTokenizer.from_pretrained('distilgpt2')
num_returns = 3
sentence = 'The dog'
tgt = torch.tensor([tokenizer.encode(sentence)] * num_returns)

generate_args = GenerateArgs(   
    max_length=20,
    do_sample=True,
    num_beams=5,
    temperature=1.5,
    top_k=50,
    top_p=1.0,
    repetition_penalty=1,
    length_penalty=1.0,
)
generated_lm = GeneratedLM(lm, tokenizer.vocab_size, lm.config.pad_token_id, [lm.config.eos_token_ids], True)
numeric_result = generated_lm.generate(tgt, generate_args)

for i in range(num_returns):
    result = tokenizer.decode(list(numeric_result[i]), skip_special_tokens=True)
    print(result)<jupyter_output>Using pad_token, but it is not set yet.
Disabled padding because no padding token set (pad_token: None, pad_token_id: None).
To remove this error, you can add a new pad token and then resize model embedding:
	tokenizer.pad_token = '<PAD>'
	model.resize_token_embeddings(len(tokenizer))<jupyter_text>Used on Fastai2 AWD_LSTM<jupyter_code># load pretrained model and vocab
path = untar_data(URLs.WT103_FWD)
vocab = list(path.glob('*.pkl'))[0].load()
model_weights = torch.load(list(path.glob('*.pth'))[0], map_location = lambda storage,loc: storage)
model = get_language_model(AWD_LSTM, len(vocab))
load_ignore_keys(model, model_weights)
# Tokenize and Numericalize
tokenizer = Tokenizer(SpacyTokenizer())
numericalizer = Numericalize(vocab=vocab)
pipe = Pipeline([tokenizer, numericalizer], True)

num_returns = 2
sentence = 'The dog'
tgt = torch.stack([pipe(sentence)] * num_returns, dim=0)
tgt
# Generate and Decode
generate_args = GenerateArgs(   
    max_length=20,
    do_sample=True,
    num_beams=5,
    temperature=1.5,
    top_k=50,
    top_p=1,
    repetition_penalty=1,
    length_penalty=1.0,
)
generated_lm = GeneratedLM(model, len(vocab), awd_lstm_lm_config['pad_token'], [3], False)
numeric_result = generated_lm.generate(tgt, generate_args)

for i in range(num_returns):
    result = pipe.decode(list(numeric_result[i]))
    print(result)<jupyter_output>xxbos xxmaj the dog - like actors of the 1960s films ; he said there were films in the xxeos
xxbos xxmaj the dog show is performed during the day . xxunk is considered as one and they should xxeos
{'fraction_non_alphanumeric': 0.10830921868540719, 'fraction_numerical': 0.016122364613476645, 'mean_word_length': 5.778711484593837, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '279483', 'license': 'Apache-2.0', 'n_tokens_mistral': 894, 'n_tokens_neox': 859, 'n_words': 197, 'path': 'nbs/99c_example_GeneratedLM.ipynb', 'repo_name': 'cwza/fastai_transformers_utils', 'size': '2419'}