Created
March 14, 2019 21:37
-
-
Save victorkohler/35b0d5e0d685b7bbb50b8955463c22e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------- | |
# TENSORFLOW GRAPH | |
#------------------------- | |
# Set up our Tensorflow graph | |
graph = tf.Graph() | |
def init_variable(size, dim, name=None): | |
''' | |
Helper function to initialize a new variable with | |
uniform random values. | |
''' | |
std = np.sqrt(2 / dim) | |
return tf.Variable(tf.random_uniform([size, dim], -std, std), name=name) | |
def embed(inputs, size, dim, name=None): | |
''' | |
Helper function to get a Tensorflow variable and create | |
an embedding lookup to map our user and item | |
indices to vectors. | |
''' | |
emb = init_variable(size, dim, name) | |
return tf.nn.embedding_lookup(emb, inputs) | |
def get_variable(graph, session, name): | |
''' | |
Helper function to get the value of a | |
Tensorflow variable by name. | |
''' | |
v = graph.get_operation_by_name(name) | |
v = v.values()[0] | |
v = v.eval(session=session) | |
return v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment