Unbabel / COMET

A Neural Framework for MT Evaluation
https://unbabel.github.io/COMET/html/index.html
Apache License 2.0
441 stars 72 forks source link

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

Closed ymoslem closed 6 months ago

ymoslem commented 7 months ago

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?

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.

Evstrife commented 7 months ago

I have a same issue with you since yesterday

ymoslem commented 7 months ago

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()