VectorHub icon indicating copy to clipboard operation
VectorHub copied to clipboard

in the article "Answering Questions with Knowledge Graph Embeddings"

Open younggggger opened this issue 1 year ago • 2 comments

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

younggggger avatar Apr 22 '24 02:04 younggggger

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?

svonava avatar Apr 24 '24 10:04 svonava

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". }
}

ricsi98 avatar Apr 28 '24 14:04 ricsi98

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

ClaireSuperlinked avatar May 21 '24 10:05 ClaireSuperlinked

Added the explanation and related examples in the article.

AruneshSingh avatar Jun 18 '24 06:06 AruneshSingh