Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: mat1 and mat2 shapes cannot be multiplied #21

Open
rootofmylife opened this issue Jun 8, 2021 · 1 comment
Open

RuntimeError: mat1 and mat2 shapes cannot be multiplied #21

rootofmylife opened this issue Jun 8, 2021 · 1 comment

Comments

@rootofmylife
Copy link

Hi, thank you for your work.

I tried to your code with train data and it worked fine. But when I changed to other kind of data, or even if I used dev data instead of train data. It got RuntimeError: mat1 and mat2 shapes cannot be multiplied

I also refactor some parts of code, but it still only works on your train data, not with others as I mentioned above.

Hope you could give me some glues to overcome this problem.

Full log here

File "/Users/Desktop/cldp/HPSG-Tutorial/HPSG/model/chart_parser.py", line 346, in label_scores_from_annotations
    label_scores_chart = self.f_label(span_features)
  File "/Users/Desktop/cldp/HPSG-Tutorial/venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/Users/Desktop/cldp/HPSG-Tutorial/venv/lib/python3.8/site-packages/torch/nn/modules/container.py", line 119, in forward
    input = module(input)
  File "/Users/Desktop/cldp/HPSG-Tutorial/venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/Users/Desktop/cldp/HPSG-Tutorial/venv/lib/python3.8/site-packages/torch/nn/modules/linear.py", line 94, in forward
    return F.linear(input, self.weight, self.bias)
  File "/Users/Desktop/cldp/HPSG-Tutorial/venv/lib/python3.8/site-packages/torch/nn/functional.py", line 1753, in linear
    return torch._C._nn.linear(input, weight, bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (9x6144 and 6016x250)

Thank you.

@rootofmylife
Copy link
Author

Recently, I have found a way to work around above problem. The solution is to change lal_combine_as_self param to True (I made this change in main.py file at line 81).

Why I know this? When I debugged code at the line number 1379 in KM_parser.py file, I tried to use hparams.d_model and the error did not occur.

annotation_dim = ((label_vocab.size - 2) * self.lal_d_proj) if (self.use_lal and not self.lal_combine_as_self) else hparams.d_model

But for me, I do not like this solution because it decreases accuracy so much, at least in my task. So use it carefully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant