ValueError: not enough values to unpack (expected 2, got 1)
i am trying to create xlnet classificationdef __init__(self,n_classes):
    super(SentimentClassifier, self).__init__()
    self.xlnet = XLNetModel.from_pretrained(PRE_TRAINED_MODEL_NAME)
    self.drop = nn.Dropout(p=0.3)
    self.out = nn.Linear(self.xlnet.config.hidden_size,  n_classes)
  def forward(self, input_ids, 
              attention_mask):
    _, pooled_output = self.xlnet(
      input_ids=input_ids,
      attention_mask=attention_mask)
    output = self.drop(pooled_output)
    return self.out(output)
class Classification(Dataset):


    def __init__(self, texts, labels, tokenizer, max_len):
        self.texts = texts
        self.labels = labels
        self.tokenizer = tokenizer
        self.max_len = max_len
    
    def __len__(self):
        return len(self.texts)
    
    def __getitem__(self, item):
        text = str(self.texts[item])
        label = self.labels[item]

        encoding = self.tokenizer.encode_plus(
        text,
        add_special_tokens=True,
        max_length=self.max_len,
        return_token_type_ids=False,
        pad_to_max_length=False,
        return_attention_mask=True,
        return_tensors='pt',
        )

        

        return {
        'review_text': text,
        'input_ids': encoding['input_ids'].flatten(),
        'attention_mask': encoding['attention_mask'].flatten(),
         'labelss': torch.tensor(label, dtype=torch.long)
        }
def train_epoch(
  model,
  data_loader,
  loss_fn,
  optimizer,
  device,
  scheduler,
  n_examples
):
  model = xlnet_model.train()
  losses = []
  correct_predictions = 0
  for d in data_loader:
    input_ids = d["input_ids"].reshape(4,512).to(device)
    print(d['input_ids'].shape)
    attention_mask = d["attention_mask"].to(device)
    labels = d["labels"].to(device)
    outputs = xlnet_model(input_ids=input_ids, attention_mask=attention_mask)
    
    _, preds = torch.max(outputs, dim=1)
    loss = loss_fn(outputs, labels)
    correct_predictions += torch.sum(preds == labels)
    losses.append(loss.item())
    loss.backward()
    nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0)
    optimizer.step()
    scheduler.step()
    optimizer.zero_grad()
  return correct_predictions.double() / n_examples, np.mean(loss)```
2021-02-05T18:29:23Z
Hi@sru,Can you please include the stack trace so we can help out more?
2021-02-06T16:03:56Z
thanks@FL33TW00Dstack trace:ValueErrorTraceback (most recent call last)in ()6     device,7     scheduler,----> 8     len(df_train)9   )10 print(f’Train loss {train_loss} accuracy {train_acc}’)2 framesin forward(self, input_ids, attention_mask)9     _, pooled_output = self.xlnet(10       input_ids=input_ids,—> 11       attention_mask=attention_mask)12     output = self.drop(pooled_output)13     return self.out(output)ValueError: not enough values to unpack (expected 2, got 1)
2021-02-08T23:44:39Z
Please someone can suggest me plz
2021-02-09T01:10:27Z
@valhallacould you please help me with issue
2021-02-09T13:00:03Z
Hi@sruBy default, all models now return output as adict, but your code expecting a tuple which is the reason for above error. You could access thehidden_statesin the returned object. See the docs for model output classeshttps://huggingface.co/transformers/main_classes/output.htmlAlso,XLNetModeldoes return pooled output, you would need to do the pooling yourself, or you can just useXLNetForSequenceClassification, which does the pooling and passes that pooled output through a classification head. You could refer to howXLNetForSequenceClassificationis implemented.github.comhuggingface/transformers/blob/c6d5e56595c0c0134c744f9e38ab2dedb6707388/src/transformers/models/xlnet/modeling_xlnet.py#L1482return [layer_past.index_select(1, beam_idx.to(layer_past.device)) for layer_past in mems]@add_start_docstrings("""XLNet Model with a sequence classification/regression head on top (a linear layer on top of the pooled output) e.g.for GLUE tasks.""",XLNET_START_DOCSTRING,)class XLNetForSequenceClassification(XLNetPreTrainedModel):def __init__(self, config):super().__init__(config)self.num_labels = config.num_labelsself.transformer = XLNetModel(config)self.sequence_summary = SequenceSummary(config)self.logits_proj = nn.Linear(config.d_model, config.num_labels)self.init_weights()
2021-02-09T17:54:59Z
@valhallathank you, i will check once.
2021-07-05T20:13:34Z
The error message is fairly self-explanatory. Your program expectspython split()to yield 2 elements, but in your case, it is only yielding 1 element. This could be because the data is not in the format you expect, a rogue malformed line, or maybe an empty line - there’s no way to know.To see what line is causing the issue, you could add some debug statements like this:if len(line.split()) != 2:
    print line