@IdoAmit198 , In reply to this question:
with self-trained GPT-2, when I am generating the text, ti gives the following error, while it works with pre-trained gpt-2
from transformers import pipeline, set_seed
my_generator_2 = pipeline(task=‘text-generation’, model=‘checkpoint-24000’,tokenizer=gpt_tokenizer,framework=‘pt’)
set_seed(42)
text = ‘research paper’
my_generator_2(text.lower(),max_length=250,num_return_sequences=2)
“num_return_sequences has to be 1, but is 2 when doing greedy search.”
Transformers inbuilt pipeline for text generation is giving this error. But following method is working well and giving more than one sequences in return:
model = AutoModelForCausalLM.from_pretrained(“checkpoint-80000”)
def text_generator(prompt):
prompt = prompt.lower()
input_ids = gpt_tokenizer(prompt, return_tensors=“pt”).input_ids
outputs = model.generate(input_ids, do_sample=True, max_length=150,min_length=100, temperature=1.5, num_return_sequences=10, top_k=50, top_p=25)
output_text = gpt_tokenizer.batch_decode(outputs, skip_special_tokens=True)
return output_text