Related error not enough values to unpack (expected 2, got 1)

sripathisony_sony: <p>I am trying to create a classification class for pertained model xlnet.</p>
<p>below my code:<br>
‘’'class check(torch.nn.Module):<br>
def <strong>init</strong>(self,num_labels=2):<br>
super(check, self).<strong>init</strong>()<br>
self.num_labels = num_labels<br>
<span class="hashtag">#self</span>.xlnet = XLNetModel(config)<br>
self.xlnet = XLNetModel.from_pretrained(PRE_TRAINED_MODEL_NAME)<br>
self.drop = nn.Dropout(p=0.3)<br>
self.classifier = torch.nn.Linear(768, num_labels)<br>
torch.nn.init.xavier_normal_(self.classifier.weight)<br>
def forward(self,input_ids=None,token_type_ids=None,attention_mask=None,labels=None):<br>
_, pooled_output = self.xlnet(input_ids=input_ids,attention_mask=attention_mask,token_type_ids=token_type_ids,labels=labels)<br>
print(pooled_output[0])<br>
output = self.drop(pooled_output)<br>
return self.out(output)</p>
<p>class Classification(Dataset):</p>
<pre><code>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',
    )

    

    input_ids = pad_sequences(encoding['input_ids'], maxlen=MAX_LEN, dtype=torch.Tensor ,truncating="post",padding="post")
    input_ids = input_ids.astype(dtype = 'int64')
    input_ids = torch.tensor(input_ids) 

    attention_mask = pad_sequences(encoding['attention_mask'], maxlen=MAX_LEN, dtype=torch.Tensor ,truncating="post",padding="post")
    attention_mask = attention_mask.astype(dtype = 'int64')
    attention_mask = torch.tensor(attention_mask)       

    return {
    'review_text': text,def train_epoch(
</code></pre>
<p>model,<br>
data_loader,<br>
loss_fn,<br>
optimizer,<br>
device,<br>
scheduler,<br>
n_examples<br>
):<br>
model = model.train()<br>
losses = []<br>
correct_predictions = 0<br>
for d in data_loader:<br>
input_ids = d[“input_ids”].reshape(4,512).to(device)<br>
print(type(input_ids))<br>
attention_mask = d[“attention_mask”].to(device)<br>
print(attention_mask.shape)<br>
labels = d[“labels”].to(device)<br>
outputs = check(input_ids=input_ids,token_type_ids=None, attention_mask=attention_mask,labels= labels)<br>
print(d[‘outputs’].shape)</p>
<pre><code>_, 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()
</code></pre>
<p>return correct_predictions.double() / n_examples, np.mean(losses)</p>
<p>train_acc, train_loss = train_epoch(<br>
check,<br>
train_data_loader,<br>
loss_fn,<br>
optimizer,<br>
device,<br>
scheduler,<br>
len(df_train))<br>
print(f’Train loss {train_loss} accuracy {train_acc}’)’’’</p>
<p>error:<br>
forward(self, input_ids, token_type_ids, attention_mask, labels)<br>
9     torch.nn.init.xavier_normal_(self.classifier.weight)<br>
10   def forward(self,input_ids=None,token_type_ids=None,attention_mask=None,labels=None):<br>
—&gt; 11     _, pooled_output = self.xlnet(input_ids=input_ids,attention_mask=attention_mask,token_type_ids=token_type_ids,labels=labels)<br>
12     print(pooled_output[0])<br>
13     output = self.drop(pooled_output)</p>
<p>ValueError: not enough values to unpack (expected 2, got 1)</p>

ronaldgevern: <aside class="quote no-group" data-username="sripathisony_sony" data-post="1" data-topic="111388">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sripathisony_sony/48/33487_2.png" class="avatar"> sripathisony_sony:</div>
<blockquote>
<p>ValueError: not enough values to unpack (expected 2, got 1)</p>
</blockquote>
</aside>
<p>During a multiple value assignment, the ValueError: not enough values to unpack occurs when either you have fewer objects to assign than variables, or you have more variables than objects. This error caused by the mismatch between the number of values returned and the number of variables in the assignment statement. This error happened mostly in the case of using <a href="http://net-informations.com/python/file/split.htm" rel="noopener nofollow ugc">python split</a> function.  Verify the assignment variables. If the number of assignment variables is greater than the total number of variables, delete the excess variable from the assignment operator. The number of objects returned, as well as the number of variables available are the same. This will resolve the value error.</p>