MaartenGr / Concept

Concept Modeling: Topic Modeling on Images and Text
https://maartengr.github.io/Concept/
MIT License
187 stars 16 forks source link

Saving the model #18

Open timverbeij opened 1 year ago

timverbeij commented 1 year ago

Hi Maarten,

Thank you for this awesome package! I have an issue when wanting to save my concept model. I get the following error message:

PicklingError: Can't pickle <function _transform.<locals>.<lambda> at 0x000002837DC60550>: it's not found as sentence_transformers.models.CLIPModel._transform.<locals>.<lambda>

Any idea what might solve this issue?

Thanks for your help!

timverbeij commented 1 year ago

Temporary workaround for others with a similar issue, based on: https://stackoverflow.com/questions/46200897/cannot-pickle-lambda-function-in-python-3.

import dill

To save the model:

with open('concept_model', 'wb') as cm:
    dill.dump(concept_model, cm)

To open the model:

with open("concept_model", "rb") as cm:
    concept_model = dill.load(cm)
bakachan19 commented 1 year ago

Hi @timverbeij. I tried using the solution you suggested for saving and loading the model. However, when I try to load a model I the following error:

[/usr/local/lib/python3.9/dist-packages/dill/_dill.py](https://localhost:8080/#) in _import_module(import_name, safe)
   1003         else:
   1004             return __import__(import_name)
-> 1005         return getattr(__import__(module, None, None, [obj]), obj)
   1006     except (ImportError, AttributeError, KeyError):
   1007         if safe:

AttributeError: module 'umap' has no attribute 'distances'

Any idea on why this is happening? Thank you.

Later edit: the solution proposed by @timverbeij works in my local environment, but on colab I get the error mentioned above.