title: invalid data type 'numpy.str_' when training bert model with pytorch
body: <p>my data are divided to 2 parts training and validation one . I Used load_dataset and dataloader functions . I convert data in dataset to torch format using traindataset.set_format
  when starting training I got error</p>
  <blockquote>
  <p>new(): invalid data type 'numpy.str_'
  in this line</p>
  </blockquote>
  <pre><code>for step,batch in enumerate(train_dataloader):
  </code></pre>
  <p>so how can i fix this error?</p>
  <pre><code>model= MixModel()
  #model.load_state_dict(torch.load(r&quot;/media/sh/saved_weightscnnbert.pt&quot;))
  tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased')
  traindataset = load_dataset('csv', data_files='/content/drive//My Drive/Colab Notebooks/newdataset/newdata_train2',split='train')
  testdataset = load_dataset('csv', data_files='/content/drive//My Drive/Colab Notebooks/newdataset/newdata_valid2',split='train')
  traindataset =traindataset.map(encode)
  testdataset1 = testdataset.map(encode)
  
  traindataset =traindataset.map(lambda examples: {'labels': examples['symptoms']}, batched=True)
  testdataset =testdataset1.map(lambda examples: {'labels': examples['symptoms']}, batched=True)
  traindataset.set_format(type='torch', columns=['input_ids', 'attention_mask', 'labels'])
  testdataset.set_format(type='torch', columns=['input_ids',  'attention_mask', 'labels'])
  train_dataloader = torch.utils.data.DataLoader(traindataset, batch_size= 64)
  test_dataloader = torch.utils.data.DataLoader(testdataset, batch_size= 64)
  
  
  </code></pre>
  <pre><code># function to train the model
  def train():  
    model.train()
    total_loss, total_accuracy = 0, 0  
    # empty list to save model predictions
    total_preds=[]
    Labels=[]  
    # iterate over batches
    for step,batch in enumerate(train_dataloader):    
      # progress update after every 50 batches.
      if step % 100 == 0 and not step == 0:
        print('  Batch {:&gt;5,}  of  {:&gt;5,}.'.format(step, len(train_dataloader)))
  
      sent_id, mask, labels = batch['input_ids'],batch['attention_mask'],batch['labels']   
      # clear previously calculated gradients 
      model.zero_grad() 
      # get model predictions for the current batch
      preds = model(sent_id, mask, labels)    
      # compute the loss between actual and predicted values
      alpha=0.25
      gamma=2
      ce_loss = loss_fn(preds, labels)
      #pt = torch.exp(-ce_loss)
      #focal_loss = (alpha * (1-pt)**gamma * ce_loss).mean() # mean over the batch   
  
      # add on to the total loss
      total_loss = total_loss + ce_loss.item()   
  
      # backward pass to calculate the gradients
      ce_loss.backward()
  
      torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)
  
      # update parameters
      optimizer.step()
      preds =torch.argmax(preds, dim=1)
      total_preds.append(preds)
      total_accuracy += (preds == labels).float().sum()
      
     
  
      
    # compute the training loss of the epoch
    avg_loss = total_loss / len(train_dataloader)
    avg_accuracy = total_accuracy / len(traindataset)
    
    # predictions are in the form of (no. of batches, size of batch, no. of classes).
    # reshape the predictions in form of (number of samples, no. of classes)
    total_preds  = np.concatenate(total_preds, axis=0)
    
    #returns the loss and predictions
    return avg_loss, total_preds, avg_accuracy
  
  
  </code></pre>