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

ValueError: Wrong shape for input_ids (shape torch.Size([6])) or attention_mask (shape torch.Size([6])) #20

Closed
liuweijian94 opened this issue Sep 3, 2020 · 2 comments
Assignees
Milestone

Comments

@liuweijian94
Copy link

This is the original code from Introudcing txtai.py

`import numpy as np

sections = ["US tops 5 million confirmed virus cases",
"Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg",
"Beijing mobilises invasion craft along coast as Taiwan tensions escalate",
"The National Park Service warns against sacrificing slower friends in a bear attack",
"Maine man wins $1M from $25 lottery ticket",
"Make huge profits without work, earn up to $100,000 a day"]

print("%-20s %s" % ("Query", "Best Match"))
print("-" * 50)

for query in ("feel good story", "climate change", "health", "war", "wildlife", "asia", "north america", "dishonest junk"):
# Get index of best section that best matches query
uid = np.argmax(embeddings.similarity(query, sections))

print("%-20s %s" % (query, sections[uid]))`

A problem occurs from colab when executing the following line of code:
uid = np.argmax(embeddings.similarity(query, sections))

It shows : "ValueError: Wrong shape for input_ids (shape torch.Size([6])) or attention_mask (shape torch.Size([6]))"

The problem doesn't occur a few days ago.

@davidmezzetti
Copy link
Member

The Sentence Transformers library is currently incompatible with Transformers 3.1.0

A temporary workaround is to downgrade Transformers to 3.0.2 like below:

pip install transformers==3.0.2

I'm working on the next release, if this problem persists, I'll hardcode setup.py to 3.0.2 but I hope this issue is resolved upstream soon.

@davidmezzetti
Copy link
Member

setup.py was fixed to transformers==3.0.2 until sentence-transformers is fixed upstream

@davidmezzetti davidmezzetti self-assigned this Sep 10, 2020
@davidmezzetti davidmezzetti added this to the v1.2.0 milestone May 13, 2021
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

2 participants