Memory networks
Answering questions or resolving problems given a few facts or a story have led to the design of a new type of networks, memory networks. In this case, the facts or the story are embedded into a memory bank, as if they were inputs. To solve tasks that require the facts to be ordered or to create transitions between the facts, memory networks use a recurrent reasoning process in multiple steps or hops on the memory banks.
First, the query or question q is converted into a constant input embedding:
![](https://static.packt-cdn.com/products/9781786465825/graphics/B05525_09_19.jpg)
While, at each step of the reasoning, the facts X to answer the question are embedded into two memory banks, where the embedding coefficients are a function of the timestep:
![](https://static.packt-cdn.com/products/9781786465825/graphics/B05525_09_20.jpg)
To compute attention weights:
![](https://static.packt-cdn.com/products/9781786465825/graphics/B05525_09_21.jpg)
And:
![](https://static.packt-cdn.com/products/9781786465825/graphics/B05525_09_22.jpg)
Selected with the attention:
![](https://static.packt-cdn.com/products/9781786465825/graphics/B05525_09_23.jpg)
The output at each reasoning time step is then combined with the identity connection, as seen previously to improve the efficiency of the recurrency:
![](https://static.packt-cdn.com/products/9781786465825/graphics/B05525_09_24.jpg)
A linear layer and classification softmax layer are added to the last :
![](https://static.packt-cdn.com/products/9781786465825/graphics/B05525_09_25.jpg)