Skip to content

'Tensor' and 'list' error when I run the code #3

Description

@WangSheng21s

TypeError Traceback (most recent call last)
Cell In[3], line 48
45 batch_dict = tokenizer(input_texts, max_length=max_length-1, padding=True, truncation=True, return_tensors='pt')
47 # Important! Adding EOS token at the end
---> 48 batch_dict['input_ids'] = [input_ids + [tokenizer.eos_token_id] for input_ids in batch_dict['input_ids']]
49 batch_dict = tokenizer.pad(batch_dict, padding=True, return_attention_mask=True, return_tensors='pt').to("cuda")
51 model.eval()

Cell In[3], line 48
45 batch_dict = tokenizer(input_texts, max_length=max_length-1, padding=True, truncation=True, return_tensors='pt')
47 # Important! Adding EOS token at the end
---> 48 batch_dict['input_ids'] = [input_ids + [tokenizer.eos_token_id] for input_ids in batch_dict['input_ids']]
49 batch_dict = tokenizer.pad(batch_dict, padding=True, return_attention_mask=True, return_tensors='pt').to("cuda")
51 model.eval()

TypeError: unsupported operand type(s) for +: 'Tensor' and 'list'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions