as-ideas / DeepPhonemizer

Grapheme to phoneme conversion with deep learning.
MIT License
361 stars 41 forks source link

Downloading and caching checkpoints #42

Open sidharthrajaram opened 11 months ago

sidharthrajaram commented 11 months ago

Downloading and caching ability when loading checkpoints (similar to Transformers API).

Why?

Test cases:

Invalid file

>>> phonemizer = Phonemizer.from_checkpoint('test')
ValueError: test is not a valid model file (.pt).

Invalid checkpoint file

>>> phonemizer = Phonemizer.from_checkpoint('test.pt')
...
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://public-asai-dl-models.s3.eu-central-1.amazonaws.com/DeepPhonemizer/test.pt

Checkpoint name provided

>>> phonemizer = Phonemizer.from_checkpoint('en_us_cmudict_forward.pt')
Loading model from /PATH/TO/.cache/cached_path/6c84425c...
>>>

Cached model loaded

>>> phonemizer = Phonemizer.from_checkpoint('en_us_cmudict_forward.pt')
Loading model from /PATH/TO/.cache/cached_path/6c84425c...
>>>

URL to checkpoint provided

>>> phonemizer = Phonemizer.from_checkpoint('https://public-asai-dl-models.s3.eu-central-1.amazonaws.com/DeepPhonemizer/en_us_cmudict_ipa_forward.pt')
Loading model from /PATH/TO/.cache/cached_path/3f662135...
>>>

Cached model loaded (with just checkpoint name)

>>> phonemizer = Phonemizer.from_checkpoint('en_us_cmudict_ipa_forward.pt')
en_us_cmudict_ipa_forward.pt already exists in cache.
Loading model from /PATH/TO/.cache/cached_path/3f662135...
>>>

Cached model loaded (with checkpoint URL)

>>> phonemizer = Phonemizer.from_checkpoint('https://public-asai-dl-models.s3.eu-central-1.amazonaws.com/DeepPhonemizer/en_us_cmudict_ipa_forward.pt')
en_us_cmudict_ipa_forward.pt already exists in cache.
Loading model from /PATH/TO/.cache/cached_path/3f662135...
>>>