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

argument 'tensors' (position 1) must be tuple of Tensors, not str #23

Open
Crista23 opened this issue Jan 3, 2022 · 2 comments
Open

Comments

@Crista23
Copy link

Crista23 commented Jan 3, 2022

How to fix the error below? Thank you!

$ python3 example.py
Traceback (most recent call last):
File "example.py", line 79, in
test_sentence_score()
File "example.py", line 72, in test_sentence_score
mover = sentence_score(sys, refs)
File "example.py", line 23, in sentence_score
scores = word_mover_score(references, hypothesis, idf_dict_ref, idf_dict_hyp, stop_words=[], n_gram=1, remove_subwords=False)
File "/usr/lib/python3.7/site-packages/moverscore_v2.py", line 128, in word_mover_score
device=device)
File "/usr/lib/python3.7/site-packages/moverscore_v2.py", line 100, in get_bert_embedding
batch_embedding = torch.stack(batch_embedding)
TypeError: stack(): argument 'tensors' (position 1) must be tuple of Tensors, not str

@vejvarm
Copy link

vejvarm commented Jan 18, 2023

Had the same problem due to PyPI version of moverscore being outdated,

Please try installing moverscore from the git repo as refered in this solution.

@jsl5710
Copy link

jsl5710 commented Jun 28, 2024

I am having the same error and installing moverscore from the git repo as referred in this #22 (comment) did not work. Can someone please help?

from moverscore_v2 import get_idf_dict, word_mover_score
from collections import defaultdict

Define your texts here

references = ["The quick brown fox jumps over the lazy dog.", "A stitch in time saves nine."]
translations = ["The speedy brown fox leaps over the lazy dog.", "A stitch at the right time saves nine."]

Get IDF dictionaries

idf_dict_hyp = get_idf_dict(translations) # Using default if not specified
idf_dict_ref = get_idf_dict(references) # Using default if not specified

Calculate MoverScore

try:
scores = word_mover_score(references, translations, idf_dict_ref, idf_dict_hyp,
stop_words=[], n_gram=1, remove_subwords=True)
print("Scores:", scores)
except Exception as e:
print("Error during scoring:", str(e))

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

3 participants