Yes I turned it on the CPU,and yes the error is about “IndexError: index out of range in self”  at these lines of code :
u = model(inputs_ids_a, attention_mask=attention_a)[0]  
v = model(inputs_ids_b, attention_mask=attention_b)[0] 
.....


I got this error:
IndexError                                Traceback (most recent call last)
 in ()
18         # extract token embeddings from BERT
19         u = model(inputs_ids_a, attention_mask=attention_a)[0]
—> 20         v = model(inputs_ids_b, attention_mask=attention_b)[0]
21         # get the mean pooled vectors
22         u = mean_pool(u, attention_a)
/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py in embedding(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq, sparse)
2042         # remove once script supports set_grad_enabled
2043         no_grad_embedding_renorm(weight, input, max_norm, norm_type)
 → 2044     return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
2045
2046

IndexError: index out of range in self
I tried to break down the code to figure it out:
Here the problem, at the last line of code : I got the same error, above
from tqdm.auto import tqdm

loop = tqdm(loader, leave=True)
for batch in loop:
  inputs_ids_a = batch['code_file1_input_ids'].to(device)
  inputs_ids_b = batch['code_file2_input_ids'].to(device)
  attention_a = batch['code_file1_attention_mask'].to(device)
  attention_b = batch['code_file2_attention_mask'].to(device)
  label = batch['similar_or_different'].to(device)
  u = model(inputs_ids_a, attention_mask=attention_a)[0]

But I don’t get it.Could you please point me in the right direction?What to do and thanks:
Knowing that my dataloder is :
all_cols = ['similar_or_different']
for part in ['code_file1','code_file2']:
    train_code_net = train_code_net.map(lambda x: tokenizer(x[part], max_length=128, padding='max_length',truncation=True),
                                        batched=True)
    for col in ['input_ids', 'attention_mask']:
        train_code_net = train_code_net.rename_column(col, part+'_'+col)
        all_cols.append(part+'_'+col)
print(all_cols)


Here a screenshot with the features:

3932×384 72.2 KB

and the original dataset (that I transformed in a dataloader) is a simple dataset :
train_code_net

Dataset({
    features: ['code_file1', 'code_file2', 'similar_or_different'],
    num_rows: 10000
})