psunlpgroup / CONTaiNER

Code for ACL 2022 paper "CONTaiNER: Few-Shot Named Entity Recognition via Contrastive Learning"
MIT License
112 stars 18 forks source link

AssertionError: dimension is not of square shape. #7

Open Pranjal-Gupta2 opened 2 years ago

Pranjal-Gupta2 commented 2 years ago

Hi, I am trying to run your code but it is giving me this error:

Iteration:   0%|                                                                                                                       | 0/3110 [00:00<?, ?it/s]
Epoch:   0%|                                                                                                                              | 0/1 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "src/container.py", line 732, in <module>
    main()
  File "src/container.py", line 649, in main
    global_step, tr_loss = train(args, train_dataset, model)
  File "src/container.py", line 140, in train
    outputs = model(**inputs)
  File "/u/pranjalgupta/.local/share/virtualenvs/CONTaiNER-y1BOzUqP/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/dccstor/pranjalgupta2/CONTaiNER/src/utils.py", line 191, in forward
    loss = calculate_KL_or_euclidean(self, attention_mask, original_embedding_mu,
  File "/dccstor/pranjalgupta2/CONTaiNER/src/utils.py", line 115, in calculate_KL_or_euclidean
    assert len(repeated_labels) == (filtered_instances_nos * filtered_instances_nos), "dimension is not of square shape."
AssertionError: dimension is not of square shape.

Steps to reproduce:

  1. Download the dataset using dataset.sh
  2. Run process_fewnerd.sh script
  3. Uncomment ## training with toy evaluation for sanity check section in exec_container.sh script
  4. Run exec_container.sh script with the intra 0 5 5 as command line arguments

Can you please help me in resolving this error? Thanks!

Heihaierr commented 2 years ago

I am facing the same error. It seems "len(repeated_labels) ==(filtered_instances_nos filtered_instances_nos)" is not reasonable, can you explain why "#ensure that the vector sizes are of filtered_instances_nos filtered_instances_nos"?

mayubo2333 commented 2 years ago

Hi, I am facing the same error too. Have you solved this problem?

mayubo2333 commented 2 years ago

Hi, I am facing the same error too. Have you solved this problem?

I find a solution to run this code. 1) delete the assertion command in line 115. 2) change x.view(filtered_instances_nos, filtered_instances_nos) to x.view(filtered_instances_nos, len(output_embedding_mu)) in line 129 - line 131.

ywm-up commented 1 year ago

Hi, I am facing the same error too. Have you solved this problem?

I find a solution to run this code.

  1. delete the assertion command in line 115.
  2. change x.view(filtered_instances_nos, filtered_instances_nos) to x.view(filtered_instances_nos, len(output_embedding_mu)) in line 129 - line 131.

It works for me, thank you for your solution.

gangtie95 commented 1 year ago

Hi, I am facing the same error too. Have you solved this problem?

I find a solution to run this code.

  1. delete the assertion command in line 115.
  2. change x.view(filtered_instances_nos, filtered_instances_nos) to x.view(filtered_instances_nos, len(output_embedding_mu)) in line 129 - line 131.

Thank you for your solution. It is works.