T5 model checkpoint is loaded, but it is repeatedly output during reasoning?

50 Views Asked by At

Task 1: Let the T5-base model generate questions according to the context, and then use torch.save () to save the trained model and get the following files: enter image description here Task 2: Load the T5-base checkpoint in Task 1 with the following code, and then let it generate problems according to the text in the form of model reasoning:

qg_model_path = args.qg_model_path
    if not qg_model_path.endswith('/'):
        qg_model_path += '/'
    
    qg_config_file = qg_model_path + "config.json"
    qg_model_file = qg_model_path + "pytorch_model.bin"
    qg_tokenizer_file = qg_model_path + "tokenizer.json"
    qg_special_tokens_file = qg_model_path + "special_tokens_map.json"
    qg_spiece_model_file = qg_model_path + "spiece.model"
    qg_optimizer_file = qg_model_path + "optimizer.pt"
    qg_text_generation_file = qg_model_path + "generation.txt"
    
    qg_config = qg_config_name.from_json_file(qg_config_file)
    qg_model = qg_model_class.from_pretrained(qg_model_file, config=qg_config).to(device_qg)
    qg_tokenizer = qg_tokenizer_mame.from_pretrained(qg_model_path)
    
    # load special tokens map
    with open(qg_special_tokens_file, 'r', encoding='utf-8') as f:
        special_tokens_map = json.load(f)
        qg_tokenizer.add_special_tokens(special_tokens_map)
    
    # load sentencepiece model
    qg_tokenizer.sp_model.load(qg_spiece_model_file)

    qg_model.eval()

My question: The checkpoint outputs normal questions during training in Task 1, but after reloading, it outputs a lot of repeated garbled codes. What is the reason?

namnamnamnamnamnamnamnamnamnamnamnamnamnamnamnamnamnamna
namnamnamnamnam léger léger léger léger léger léger léger léger léger léger léger léger léger lége
namnamnamnamnamnam Khan Khan Khan Khan Khan Khan Khan Khan Khan Khan Khan Khan Kha

I tried to adjust beam_search from 4 to 8, but it didn't work. It was just output as other repeated garbled words. I expect to generate some normal questions as I trained in Task 1:

What are the victims of extinction?
Who is the hero in the story?
0

There are 0 best solutions below