superlinked / VectorHub

VectorHub is a free, open-source learning website for people (software developers to senior ML architects) interested in adding vector retrieval to their ML stack.
https://superlinked.com/vectorhub/
Other
387 stars 90 forks source link

in the article "Answering Questions with Knowledge Graph Embeddings" #358

Closed younggggger closed 4 weeks ago

younggggger commented 2 months ago

when i run :

Get node and relation IDs

france = nodes["France"] rel = edges["/location/location/contains"] burgundy = nodes["Burgundy"] riodj = nodes["Rio de Janeiro"] bnc = nodes["Bonnie and Clyde"]

Define triplets

head_entities = torch.tensor([france, france, france], dtype=torch.long) relationships = torch.tensor([rel, rel, rel], dtype=torch.long) tail_entities = torch.tensor([burgundy, riodj, bnc], dtype=torch.long)

Score triplets using the model

scores = model(head_entities, relationships, tail_entities) print(scores.tolist())

error:

NameError Traceback (most recent call last) Cell In[9], line 2 1 # Get node and relation IDs ----> 2 france = nodes["France"] 3 rel = edges["/location/location/contains"] 4 burgundy = nodes["Burgundy"]

NameError: name 'nodes' is not defined

svonava commented 2 months ago

Thanks @younggggger - the code is illustratory and doesn't currently seem to include the graph building part. We can ping the author for feedback:

@krichard98 any chance you have the graph building code around as well?

ricsi98 commented 2 months ago

Thanks @younggggger for reaching out. As @svonava pointed out, the code snippet provided in the blog post serves primarily as an illustrative tool for enhancing comprehension. However, the process of resolving entity names for the FB15k_237 dataset can indeed be somewhat convoluted.

I've prepared a gist here that extracts ID-node index mappings. With these mappings, resolving entity names based on the IDs becomes feasible.

To illustrate, here's an example of how you can resolve entity names using the Wikidata Query Service:

SELECT ?item ?itemLabel WHERE {
  ?item wdt:P646 "/m/0mm1q".
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ClaireSuperlinked commented 1 month ago

@AruneshSingh is this updated in the article? If not let's get it changed as needed :)

AruneshSingh commented 4 weeks ago

Added the explanation and related examples in the article.