IBCNServices / pyRDF2Vec

🐍 Python Implementation and Extension of RDF2Vec
https://pyrdf2vec.readthedocs.io/en/latest/
MIT License
242 stars 47 forks source link

Error running the `Getting started` example, `unhashable type: 'SPARQLConnector` #210

Open sky-2002 opened 12 months ago

sky-2002 commented 12 months ago

First of all, thanks a lot for this repo, @bsteenwi @GillesVandewiele @rememberYou .

🐛 Bug

TypeError: unhashable type: 'SPARQLConnector' when running example code given in readme. The error arises out of the following code: responses = [self.connector.fetch(query) for query in queries] present here.

I also tried installing from the develop branch as was mentioned in this issue. But I am still getting the error.

Expected Behavior

No errors.

Current Behavior

The line embeddings, literals = transformer.fit_transform(knowledge_graph, entities) results into the error - TypeError: unhashable type: 'SPARQLConnector'.

Steps to Reproduce

I tried the code given in the readme file on the repo.

# Create our transformer, setting the embedding & walking strategy.
transformer = RDF2VecTransformer(
    Word2Vec(epochs=10),
    walkers=[RandomWalker(4, 10, with_reverse=False, n_jobs=2)],
    # verbose=1
)
# Get our embeddings.
embeddings, literals = transformer.fit_transform(knowledge_graph, entities)
print(embeddings)

Environment

Possible Solution

For me, changing this line in connectors.py:

@cachedmethod(operator.attrgetter("cache"), key=partial(hashkey, "fetch"))
def fetch(self, query: str) -> Response:

to this:

@cachedmethod(operator.attrgetter("cache"))
def fetch(self, query: str) -> Response:

solved the issue. But I think a solution for error free installation is needed, without needing to change this line, happy to contribute if guided.

rememberYou commented 12 months ago

Hi @sky-2002, thank you very much for your feedback! :-)

It's not the first time I've seen some users encounter problems with the cached fetch method. I know that back in the day they didn't specify a hash key for it, but that it was problematic at some point.

Thanks for the suggestion as well.

bsteenwi commented 12 months ago

hmm @rememberYou,

you already solved that issue right?: The commit d039a702c9b072983b5f60ba7892b8d7a2cf1993 on the develop branch has fixed the issue with cachetool.

I can't find any reference to @cachedmethod(operator.attrgetter("cache"), key=partial(hashkey, "fetch"))

rememberYou commented 12 months ago

@bsteenwi Oh yes indeed, I can see that the use of key=partial(hashkey, "fetch")) has already been removed from the develop branch since quite a while.

@sky-2002 In principle, this error should no longer be present. Did you clone the repository?