forked from msoutopico/python-comet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
60 lines (45 loc) · 2.05 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import comet_ml
from comet import download_model, load_from_checkpoint
from dotenv import load_dotenv
from rich import print
load_dotenv(override=True)
api_key = os.getenv("API_KEY")
experiment = comet_ml.Experiment(api_key=api_key, project_name="test")
print(f"{api_key=}")
# experiment = comet_ml.Experiment(api_key=api_key)
model_path = download_model("Unbabel/wmt22-cometkiwi-da")
# Load the model checkpoint:
model = load_from_checkpoint(model_path)
# Data must be in the following format:
data = [
{
"src": "The output signal provides constant sync so the display never glitches.",
"mt": "Das Ausgangssignal bietet eine konstante Synchronisation, so dass die Anzeige nie stört.",
},
{
"src": "Kroužek ilustrace je určen všem milovníkům umění ve věku od 10 do 15 let.",
"mt": "Кільце ілюстрації призначене для всіх любителів мистецтва у віці від 10 до 15 років.",
},
{
"src": "Mandela then became South Africa's first black president after his African National Congress party won the 1994 election.",
"mt": "その後、1994年の選挙でアフリカ国民会議派が勝利し、南アフリカ初の黒人大統領となった。",
},
]
# Call predict method:
model_output = model.predict(data, batch_size=8, gpus=1)
print(model_output)
print(f"{model_output.scores=}") # sentence-level scores
print(f"{model_output.system_score=}") # system-level score
# Not all COMET models return metadata with detected errors.
if "metadata" in list(model_output.__dict__.keys()):
print(f"{model_output.metadata.error_spans=}") # detected error spans
# problems:
# 1. slow, model is updated every time
# 2. XCOMET-XL model does not load
# 4. questions:
# - what is the system score?
# comet score specific to quality estimation that does not require reference trasnlations
# https://huggingface.co/Unbabel/wmt22-cometkiwi-da
# https://github.com/Unbabel/COMET/blob/v2.0.1/MODELS.md
# https://aclanthology.org/2022.wmt-1.60/