Skip to content

Instantly share code, notes, and snippets.

@gkarthik
Created November 7, 2020 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkarthik/144c7ea44372172d8e6b9b0fe2b214c5 to your computer and use it in GitHub Desktop.
Save gkarthik/144c7ea44372172d8e6b9b0fe2b214c5 to your computer and use it in GitHub Desktop.
import numpy as np
nentity = 100
nhidden = 20
nrelations = 10
entity_embedding = np.random.uniform(-10, 10, (nentity, nhidden))
relation_embedding = np.random.uniform(-1, 1, (nrelations, nhidden))
# For every iteration
head = entity_embedding[0] # Pick any entity based negative or positive samples per batch
tail = entity_embedding[10] # Pick any entity based negative or positive samples per batch
relation = relation_embedding[0] # Pick a relation that connects head and tail entities based on positive or negative samples
# Compute score using transE embedding
score = (head+relation) - tail
# Minimize loss etc....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment