# Error ValueError: too many values to unpack (expected 2) in model training

**URL:** <https://discuss.huggingface.co/t/error-valueerror-too-many-values-to-unpack-expected-2-in-model-training/116453>\
**Category:** 🤗Transformers\
**Created:** [November 9, 2024, 12:22am UTC](https://discuss.huggingface.co/t/error-valueerror-too-many-values-to-unpack-expected-2-in-model-training/116453 "2024-11-09T00:22:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![felipenandz](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/felipenandz/32/34240_2.png) [@felipenandz](https://discuss.huggingface.co/u/felipenandz)\
**Post date:** [November 9, 2024, 12:22am UTC](https://discuss.huggingface.co/t/error-valueerror-too-many-values-to-unpack-expected-2-in-model-training/116453/1 "2024-11-09T00:22:55Z")

</div>

Hello,

I’m getting a persistente error while trying to train my model LayoutLM3.

Let me describe

I already encoded my dataset with this method here

def process(list):

```
for data in list:
  labels = data["labels"]
  bboxes = data["bboxes"]
  tokens = data["tokens"]
  image = Image.open(datasetRootPath + data["file_name"]).convert("RGB")

  encoding = processor(
      image,
      text=tokens,
      boxes=bboxes,
      word_labels=labels,
      padding="max_length",  
      truncation=True,       
      return_tensors="pt"    
  )
  
  yield encoding

```

train\_dataset = list(process(dataset))

```auto
[{'input_ids': tensor([[ 0, 316, 17442, 2064, 337, 3938, 5553, 6560, 4006, 6623,
          1696, 3842, 6304, 1168, 1322, 11903, 14502, 274, 3721, 3808,
           717, 8748, 8041, 22556, 673, 274, 29092, 5945, 1723, 6,
           654, 501, 910, 321, 2831, 35033, 2663, 5479, 541, 5339,
             2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
             1, 1]]), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0]]), 'bbox': tensor([[[0.0000, 0.0000, 0.0000, 0.0000],
         [110.0006, 1385.4795, 182.0733, 1438.7952],
         [79.8919, 486.5594, 361.0753, 508.1014],
         ...,
         [0.0000, 0.0000, 0.0000, 0.0000],
         [0.0000, 0.0000, 0.0000, 0.0000],
         [0.0000, 0.0000, 0.0000, 0.0000]]]), 'labels': tensor([[-100, 5, 0, 0, -100, -100, 0, 0, -100, 0, -100, 0,
            4, -100, -100, 1, -100, 1, -100, -100, -100, 1, -100, -100,
         -100, 1, -100, -100, -100, -100, 3, 3, 3, 2, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100]]), 'pixel_values': tensor([[[[1.0000, 1.0000, 1.0000, ..., 1.0000, 1.0000, 1.0000],
          [1.0000, 1.0000, 1.0000, ..., 1.0000, 1.0000, 1.0000],
          [1.0000, 1.0000, 1.0000, ..., 1.0000, 1.0000, 1.0000],
          ...,
          [0.9373, 0.9373, 0.9373, ..., 0.9529, 0.9529, 0.9608],
          [0.9137, 0.9137, 0.9137, ..., 0.9373, 0.9373, 0.9451],
          [0.8980, 0.8980, 0.8980, ..., 0.9216, 0.9294, 0.9294]],

         [[1.0000, 1.0000, 1.0000, ..., 1.0000, 1.0000, 1.0000],
          [1.0000, 1.0000, 1.0000, ..., 1.0000, 1.0000, 1.0000],
          [1.0000, 1.0000, 1.0000, ..., 1.0000, 1.0000, 1.0000],
          ...,
          [0.9373, 0.9373, 0.9373, ..., 0.9529, 0.9529, 0.9608],
          [0.9137, 0.9137, 0.9137, ..., 0.9373, 0.9373, 0.9451],
          [0.8980, 0.8980, 0.8980, ..., 0.9216, 0.9294, 0.9294]],

         [[1.0000, 1.0000, 1.0000, ..., 1.0000, 1.0000, 1.0000],
          [1.0000, 1.0000, 1.0000, ..., 1.0000, 1.0000, 1.0000],
          [1.0000, 1.0000, 1.0000, ..., 1.0000, 1.0000, 1.0000],
          ...,
          [0.9373, 0.9373, 0.9373, ..., 0.9529, 0.9529, 0.9608],
          [0.9137, 0.9137, 0.9137, ..., 0.9373, 0.9373, 0.9451],
          [0.8980, 0.8980, 0.8980, ..., 0.9216, 0.9294, 0.9294]]]])}]

```

but when I’m passing the train\_dataset to the trainer I’m facing the following error

```auto
forward(self, input_ids, bbox, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, pixel_values, output_attentions, output_hidden_states, return_dict)
    885 if input_ids is not None:
    886 input_shape = input_ids.size()
--> 887 batch_size, seq_length = input_shape
    888 device = input_ids.device
    889 elif inputs_embeds is not None:

ValueError: too many values to unpack (expected 2)

```

Any clue about it ?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [November 9, 2024, 1:46am UTC](https://discuss.huggingface.co/t/error-valueerror-too-many-values-to-unpack-expected-2-in-model-training/116453/2 "2024-11-09T01:46:45Z")

</div>

Maybe this?

> [@Batch\_size, seq\_length = input\_shape ValueError: too many values to unpack (expected 2) Transformer Sentence Similarity Classification](https://discuss.huggingface.co/t/batch-size-seq-length-input-shape-valueerror-too-many-values-to-unpack-expected-2-transformer-sentence-similarity-classification/76245):
>
> I encountering a problem when doing Sentence Similarity Classification Task Using Transformer. It happens when I was about to train my model, I load and process my dataset in this way, and this is what the training dataset element shape looks like: but when I train the model, it says: ValueError: Caught ValueError in replica 0 on device 0. Original Traceback (most recent call last): File “/home/fanshaoqi/anaconda3/envs/tf2/lib/python3.10/site-packages/torch/nn/parallel/parallel\_ap…
