question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: could not broadcast input array from shape (4,) into shape (1,)

See original GitHub issue

Thanks for the very interesting paper and code. I’m trying to train adapet on custom data (in Google Colab). I’ve prepared the data in the format as indicated in the documentation. my task is a binary sentiment classification task “positive” vs. “negative”.

!python cli.py --data_dir data/sentiment-news-econ \
               --pattern 'The quote: "[TEXT1]". The quote is overall [LBL]' \
               --dict_verbalizer '{"positive": "verbalizer_1", "negative": "verbalizer_2"}'

I get the following error:

Traceback (most recent call last):
  File "cli.py", line 54, in <module>
    train(config)
  File "/content/drive/MyDrive/Colab Notebooks/Few-shot-experiments/ADAPET/src/train.py", line 93, in train
    loss, dict_val_update = model(sup_batch)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "/content/drive/MyDrive/Colab Notebooks/Few-shot-experiments/ADAPET/src/adapet.py", line 213, in forward
    pet_disc_loss = self.get_decoupled_label_loss(batch)
  File "/content/drive/MyDrive/Colab Notebooks/Few-shot-experiments/ADAPET/src/adapet.py", line 178, in get_decoupled_label_loss
    lbl_logits = self.get_single_logits(pet_mask_ids, mask_idx, list_lbl) # [bs, num_lbl]
  File "/content/drive/MyDrive/Colab Notebooks/Few-shot-experiments/ADAPET/src/adapet.py", line 70, in get_single_logits
    lbl_ids[i, :len(i_lbl_ids)] = i_lbl_ids
ValueError: could not broadcast input array from shape (4,) into shape (1,)

The error seems to come from the following part in the source code. Where the token IDs for the labels are retrieved. https://github.com/rrmenon10/ADAPET/blob/6d2bfef5405ca53112235021d9fb8b36f641be9d/src/adapet.py#L70

I couldn’t figure out what it causing it though 😕

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MoritzLaurercommented, Feb 26, 2022

ah no, my line 72 is return self.config.max_num_lbl (without _tok) I’ll try manually deleting the cloned directory and reinstalling, maybe that fixes it

—update: after manually deleting and reinstalling on my google drive, it seems to be working now, thank you!

1reaction
amith-ananthramcommented, Feb 26, 2022

(and congrats on the very cool work!)

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: could not broadcast input array from shape ...
At least one item in your list is either not three dimensional, or its second or third dimension does not match the other...
Read more >
Valueerror: could not broadcast input array from shape
The error message "Valueerror: could not broadcast input array from shape" basically means that pandas won't be able to remove two data frames...
Read more >
Python Error ""ValueError: could not broadcast input array ...
In your for loop, you are getting a labels_batch from the generator which apparently has a shape of (16, 4) and you are...
Read more >
ValueError could not broadcast input array from shape 360 ...
Hi@akhtar,. In the above error it shows could not broadcast input array from shape (360,270,3) into shape (360,280,3), means you are ...
Read more >
could not broadcast input array from shape (8407,1) into ...
The error you are getting simply implies that pandas can't subtract two dataframes if there are no common indexes or column names between...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found