Using "load_metric" offline in datasets

My office PC doesn’t have access to internet, and the load_metric function downloads the metric from internet. I tried pickling using the following code:

PC 1 (connected to internet)

import pickle
from datasets import load_metric
metric = load_metric("glue", "mrpc")
with open('metric.pickle', 'wb') as handle:
    pickle.dump(metric, handle, protocol=pickle.HIGHEST_PROTOCOL)

Now i copied the metric pickle file to the offline PC, and tried opening using the followng code:

import pickle
with open('metric.pickle', 'rb') as handle:
    metric = pickle.load(handle)

but it gived the following error:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ModuleNotFoundError: No module named 'datasets_modules'

Is there way to use datasets load_metric in offline mode?
Thank you in advance.

Hi ! Yes you just need to have the metric python file from datasets/metrics at master · huggingface/datasets · GitHub and load it with

load_metric("path/to/metric.py")
1 Like

Thank you so much, it worked.