cltl / aproof-icf-classifier

Classifier that can read medical reports and assign a functional level classification following the WHO ICF classification scheme.
MIT License
4 stars 2 forks source link

Running with local models from the hugging face .cache #2

Open piekvossen opened 3 years ago

piekvossen commented 3 years ago

Running with local models does not work even though the models are in the hugging face .cache:

/Users/piek/.cache/huggingface/transformers

E.g. there is. json file with the following info:

{"url": "https://huggingface.co/CLTL/icf-domains/resolve/main/special_tokens_map.json", "etag": "\"e97d1993365bb21c88f390e8703e4c1af564821f\"”}%

docker run -v /Users/piek/Desktop/r-COVID-19-TM/CovidHerstelZorg-ZonMW/data -e TRANSFORMERS_OFFLINE=1 piekvossen/a-proof-icf-classifier --in_csv example/input.csv --text_col text

Error message is below:

Loading input csv file: example/input.csv Input csv file (example/input.csv) is successfuly loaded! Anonymizing the text in "text" column. This might take a while. Splitting the text in "text" column to sentences. This might take a while. Generating domains predictions. This might take a while. CUDA device not available; running on a CPU! Cannot find the requested files in the cached path and outgoing traffic has been disabled. To enable model look-ups and downloads online, set 'local_files_only' to False. Downloading the model from https://huggingface.co/CLTL/icf-domains Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/transformers/configuration_utils.py", line 546, in get_config_dict resolved_config_file = cached_path( File "/usr/local/lib/python3.8/site-packages/transformers/file_utils.py", line 1402, in cached_path output_path = get_from_cache( File "/usr/local/lib/python3.8/site-packages/transformers/file_utils.py", line 1620, in get_from_cache raise FileNotFoundError( FileNotFoundError: Cannot find the requested files in the cached path and outgoing traffic has been disabled. To enable model look-ups and downloads online, set 'local_files_only' to False.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "./main.py", line 154, in main( File "./main.py", line 121, in main sents['predictions'] = predict_domains( File "/icfc/src/icf_classifiers.py", line 49, in predict_domains model = MultiLabelClassificationModel( File "/usr/local/lib/python3.8/site-packages/simpletransformers/classification/multi_label_classification_model.py", line 194, in init self.config = config_class.from_pretrained(model_name, self.args.config) File "/usr/local/lib/python3.8/site-packages/transformers/configuration_utils.py", line 489, in from_pretrained config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, kwargs) File "/usr/local/lib/python3.8/site-packages/transformers/configuration_utils.py", line 570, in get_config_dict raise EnvironmentError(msg) OSError: Can't load config for 'CLTL/icf-domains'. Make sure that:

sandertan commented 3 years ago

Hi @piekvossen , if the above command is the one you executed, I think it's missing the -v parameter to mount your local cache directory to the container's cache dir. Could you try:

docker run \
  -v /Users/piek/.cache/huggingface/transformers:/root/.cache/huggingface/transformers/ \
  -e TRANSFORMERS_OFFLINE=1 \
  piekvossen/a-proof-icf-classifier --in_csv example/input.csv --text_col text

It's possible to mount multiple directories, so you can add a -v to also mount a custom data folder.

piekvossen commented 3 years ago

Hi Sander,

Thanks for pointing out.

This seems to solve some of the problems but I still got an error for one of the cached models. That would be weird as I did run it using the online models and also downloaded it in the data folder:

(base) @.*** aproof-icf-classifier % ls ~/Desktop/r-COVID-19-TM/CovidHerstelZorg-ZonMW/data [Spam] COVID data.eml icf-levels-adm icf-levels-ber icf-levels-etn icf-levels-ins icf-levels-stm icf-domains icf-levels-att icf-levels-enr icf-levels-fac icf-levels-mbw

groetjes

Piek

(base) @.*** aproof-icf-classifier % docker run \ -v /Users/piek/Desktop/r-COVID-19-TM/CovidHerstelZorg-ZonMW/data \ -v /Users/piek/.cache/huggingface/transformers:/root/.cache/huggingface/transformers/ \ -e TRANSFORMERS_OFFLINE=1 \ piekvossen/a-proof-icf-classifier --in_csv example/input.csv --text_col text Loading input csv file: example/input.csv Input csv file (example/input.csv) is successfuly loaded! Anonymizing the text in "text" column. This might take a while. Splitting the text in "text" column to sentences. This might take a while. Generating domains predictions. This might take a while. Downloading the model from https://huggingface.co/CLTL/icf-domains CUDA device not available; running on a CPU! 14%|█▍ | 1/7 [00:00<00:00, 13.65it/s] 100%|██████████| 1/1 [00:00<00:00, 2.74it/s]Processing domains predictions. Generating levels predictions for ADM. Downloading the model from https://huggingface.co/CLTL/icf-levels-adm

CUDA device not available; running on a CPU! 50%|█████ | 1/2 [00:00<00:00, 8.68it/s] 100%|██████████| 1/1 [00:00<00:00, 6.92it/s]There are no sentences for which ATT was predicted. There are no sentences for which BER was predicted. Generating levels predictions for ENR. Downloading the model from https://huggingface.co/CLTL/icf-levels-enr

Cannot find the requested files in the cached path and outgoing traffic has been disabled. To enable model look-ups and downloads online, set 'local_files_only' to False. Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/transformers/configuration_utils.py", line 546, in get_config_dict resolved_config_file = cached_path( File "/usr/local/lib/python3.8/site-packages/transformers/file_utils.py", line 1402, in cached_path output_path = get_from_cache( File "/usr/local/lib/python3.8/site-packages/transformers/file_utils.py", line 1620, in get_from_cache raise FileNotFoundError( FileNotFoundError: Cannot find the requested files in the cached path and outgoing traffic has been disabled. To enable model look-ups and downloads online, set 'local_files_only' to False.

On 18 Oct 2021, at 13:29, Sander Tan @.**@.>> wrote:

Hi @piekvossenhttps://github.com/piekvossen , if the above command is the one you executed, I think it's missing the -v parameter to mount your local cache directory to the container's cache dir. Could you try:

docker run \ -v /Users/piek/Desktop/r-COVID-19-TM/CovidHerstelZorg-ZonMW/data \ -v /Users/piek/.cache/huggingface/transformers:/root/.cache/huggingface/transformers/ \ -e TRANSFORMERS_OFFLINE=1 \ piekvossen/a-proof-icf-classifier --in_csv example/input.csv --text_col text

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/cltl/aproof-icf-classifier/issues/2#issuecomment-945672195, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAUDKLAXMZTQEK3PUR27T3DUHQAKHANCNFSM5GF3CXBA.