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

AttributeError: 'dict' object has no attribute 'scores' #183

Closed
ymoslem opened this issue Nov 19, 2023 · 2 comments
Closed

AttributeError: 'dict' object has no attribute 'scores' #183

ymoslem opened this issue Nov 19, 2023 · 2 comments
Labels
question Further information is requested

Comments

@ymoslem
Copy link
Contributor

ymoslem commented Nov 19, 2023

What is your question?

Hello! I have an issue running COMET on Google Colab. I received the following error:

Predicting DataLoader 0: 100%|██████████| 79/79 [03:37<00:00,  2.75s/it]
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-6-82b44970d657>](https://localhost:8080/#) in <cell line: 14>()
     12 model = load_from_checkpoint(model_path)
     13 
---> 14 seg_scores, sys_score = model.predict(data, batch_size=128, gpus=1).values()
     15 comet = round(sys_score*100, 2)
     16 print("COMET:", comet)

1 frames
[/usr/local/lib/python3.10/dist-packages/comet/models/base.py](https://localhost:8080/#) in <listcomp>(.0)
    650             exit()
    651 
--> 652         scores = torch.cat([pred.scores for pred in predictions], dim=0).tolist()
    653         if "metadata" in predictions[0]:
    654             metadata = flatten_metadata([pred.metadata for pred in predictions])

AttributeError: 'dict' object has no attribute 'scores' 

Code example

from comet import download_model, load_from_checkpoint

model = load_from_checkpoint(download_model("Unbabel/wmt22-comet-da"))
data = [
    {
        "src": "Ich esse gerne Pizza.",
        "mt": "I like to eat happy pizza.",
        "ref": "I like to eat pizza."
    },
]
model.predict(data, batch_size=1, gpus=0)[0]

What's your environment?

  • OS: Linux (Google Colab)
  • Python: 3.10.12
  • Packaging: pip 23.3.1
  • Version:
    • unbabel-comet 2.2.0
    • torch 2.1.1
    • torchmetrics 0.10.3
    • pytorch-lightning 2.1.2
    • transformers 4.35.2

What have you tried?

I have also tried it locally on macOS using a virtual environment on Python 3.9.0. I have got the same error message.

@ymoslem ymoslem added the question Further information is requested label Nov 19, 2023
@Evstrife
Copy link

I have a same issue with you since yesterday

@ymoslem
Copy link
Contributor Author

ymoslem commented Nov 20, 2023

This can be fixed through this edit #185

Changed:

scores = torch.cat([pred.scores for pred in predictions], dim=0).tolist()

to:

scores = torch.cat([pred["scores"] for pred in predictions], dim=0).tolist()

@ymoslem ymoslem closed this as completed Nov 21, 2023
@ymoslem ymoslem reopened this Jan 5, 2024
ricardorei pushed a commit that referenced this issue Jan 8, 2024
@ymoslem ymoslem closed this as completed Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants