gpt-2-simple icon indicating copy to clipboard operation
gpt-2-simple copied to clipboard

gpt

Open ghost opened this issue 2 years ago • 1 comments

Thank you

ghost avatar Aug 15 '22 17:08 ghost

Heres a start

!pip install transformers
import transformers
config = transformers.GPT2Config.from_pretrained('/content/checkpoint/run3/hparams.json')
tokenizer = transformers.GPT2Tokenizer("checkpoint/run3/encoder.json", "checkpoint/run3/vocab.bpe")
model = transformers.GPT2Model.from_pretrained('/content/checkpoint/run3/model-1500.index',from_tf=True,config=config)

model.save_pretrained('gpt2_')
tokenizer.save_pretrained('gpt2_')

from transformers import pipeline
fill_masker = pipeline(task ='text-generation', model="/content/gpt2_")

Heres how you implement greedy

fill_masker("hello my name is inigo montoya you",max_length=20)

maybe you can ask the huggingface community for alternative searching methods


Also here how you do beam search with huggingface

fill_masker("hello my name is inigo montoya you",num_return_sequences=20, num_beams=60,batch_size=20)

refer to this link to explore different searches https://huggingface.co/docs/transformers/main_classes/text_generation

enochlev avatar Dec 30 '22 20:12 enochlev