implicit_chain_of_thought icon indicating copy to clipboard operation
implicit_chain_of_thought copied to clipboard

Question about missing predicted value in your code

Open Chris0523-ds opened this issue 6 months ago • 1 comments

Hello! Your paper about ICoT impressed me. However, when I tried to reproduct the code, I faced one challenge: Here is the code in file generate.py, lines 58-71:

        for i, (input_ids_all_i, beam_output_i) in enumerate(zip(input_ids_all, beam_output)):
            #sep_position = input_ids_single.tolist().index(tokenizer.eos_token_id)
            sep_position = sep_positions[i].item()
            tgt = input_ids_all_i[sep_position+1:]
            tgt_text = tokenizer.decode(tgt, skip_special_tokens=True)
            ans = extract_answer(tgt_text)
            pred_text = tokenizer.decode(beam_output_i[0][sep_position+1:], skip_special_tokens=True) 
            pred_ans = extract_answer(pred_text)
            #import pdb; pdb.set_trace()
            total_instances += 1
            if ans == pred_ans:
                total_correct += 1
        end_time = time.time()
        total_time += end_time - start_time

When I tried to run the code (Rather than training from scratch, I download the pre-trained model and running the generated & evaluation code at first) I found the predicted value is missing (in this code, the variable of pred_text). There is no output for this variable.

Based on my check, this problem is originated from modeling_gpt2_implicit.py, code line 284-286:

            hidden_states = outputs[0]
            if use_cache is True:
                presents = presents + (outputs[1],)

there is sometimes no output for output[1]., so the code goes wrong.

I guess this problem is related to the edition of library such a transformer. Thus, if possible, could you provide me with the library edition (transformer) of this code? @da03

Thank you very much for your patience to read this code. I am just a master student, so my knowledge might be limited :) Your patience and help will be appreciated !

Chris0523-ds avatar Aug 02 '25 15:08 Chris0523-ds

This issue is solved when I changed my library transformers==4.30.0. Perhaps the updated transformers==4.54.1 cannot support the original function.

Chris0523-ds avatar Aug 04 '25 10:08 Chris0523-ds