MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / hop

Function hop

nlp_class3/memory_network.py:350–364  ·  view source on GitHub ↗
(query, story)

Source from the content-addressed store, hash-verified

348# define one hop
349# the "query" can be the question, or the answer from the previous hop
350def hop(query, story):
351 # query.shape = (embedding_dim,)
352 # story.shape = (num sentences, embedding_dim)
353 x = Reshape((1, embedding_dim))(query) # make it (1, embedding_dim)
354 x = dot([story, x], 2)
355 x = Reshape((story_maxsents,))(x) # flatten it for softmax
356 x = Activation('softmax')(x)
357 story_weights = Reshape((story_maxsents, 1))(x) # unflatten for dotting
358
359 # makes a new embedding
360 story_embedding2 = embed_and_sum(input_story_)
361 x = dot([story_weights, story_embedding2], 1)
362 x = Reshape((embedding_dim,))(x)
363 x = dense_layer(x)
364 return x, story_embedding2, story_weights
365
366
367# do the hops

Callers 1

memory_network.pyFile · 0.85

Calls 2

dotFunction · 0.85
embed_and_sumFunction · 0.85

Tested by

no test coverage detected