Unbabel / COMET

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

[QUESTION]__init__.py generates a wrong path for hparams.yaml in Windows #123

Closed YZhou0413 closed 1 year ago

YZhou0413 commented 1 year ago

What is your question?

Hello Ricardo,

i just installed COMET 2.0.0 and ran a basic test with the text examples after the full installation. And i got the Exception:

hparams.yaml file is missing from C:Users\username.cache\huggingface\hub\models--Unbabel--wmt22-comet-da\snapshots\371e9839ca4e213dde891b066cf3080f75ec7e72!

I noticed that the path of the parent folder is incorrect, a "\" is missing in "C:Users". How can I fix it?

Thank you!

What's your environment?

K024 commented 1 year ago

It happens here:

https://github.com/Unbabel/COMET/blob/77eb17921d597ffcea2ab6eea15a9c36ce78bd3e/comet/models/__init__.py#L56-L59

Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] on win32
>>> import os
>>> os.path.join("C:", "Users")
'C:Users'

For temporary usage, try to move the snapshot into the folder where your project locates in and use relative path to load it.


To developers: I'd suggest using pathlib for path manipulating.

from pathlib import Path

# ...
checkpoint_path = Path(checkpoint_path)

if not checkpoint_path.is_file():
  raise Exception(f"Invalid checkpoint path: {checkpoint_path}")

parent_folder = checkpoint_path.parents[1] # .parent.parent
hparams_file = parent_folder / "hparams.yaml"
# ...
YZhou0413 commented 1 year ago

Thank you! @K024

ricardorei commented 1 year ago

Thanks @K024!

ricardorei commented 1 year ago

@YZhou0413 I just pushed the changes suggested above. You can test the current master

YZhou0413 commented 1 year ago

@ricardorei It's working, Thanks!

ricardorei commented 1 year ago

@YZhou0413 I'll release this on the next pypi version!

Since we just released version 2.0 and I expect more people reporting issues, I'll just wait a few weeks.