Repetitive words in model output

import torch 
from transformers import GPT2Tokenizer, GPT2LMHeadModel

model_name = "gpt2" #output_dir #
tokenizer = GPT2Tokenizer.from_pretrained(model_name, padding_side='left', add_eos_token=True) #gpt2
llm_model = GPT2LMHeadModel.from_pretrained(model_name) # gpt2
device = torch.device('cuda')
llm_model.to(device)

tokenizer.pad_token = tokenizer.eos_token

# Configure the model
llm_model.config.pad_token_id = tokenizer.eos_token_id
llm_model.config.eos_token_id = tokenizer.eos_token_id
llm_model.config.vocab_size = llm_model.config.vocab_size + len(tokenizer.get_added_vocab())
llm_model.resize_token_embeddings(len(tokenizer))
llm_model.config.pad_token_id = tokenizer.pad_token_id

print(tokenizer.eos_token_id)

result

github issue

1 Like


1 Like