Memory Network(1) - 给你的网络加点memor

作者: l1n3x | 来源:发表于2019-03-13 19:36 被阅读84次

    今天分享一下ICLR2015年的一篇论文Memory Networks

    动机

    实际上Memory并不是一个新鲜的东西,LSTM的全称就是Long Short-Term Memory,长短时间记忆网络。这篇文章单独提出一个Memory Network的原因大概是:

    However, their memory (encoded by hidden states and weights) is typically too small, and is not compartmentalized enough to accurately remember facts from the past (knowledge is compressed into dense vectors).
    RNNs are known to have difficulty in performing memorization, for example the simple copying task of outputting the same input sequence they have just read

    论文认为RNN等类似网络记忆力"is too small",至少在拷贝一个向量这样的任务上做的还不是很好。因此作者才提出了更"纯粹的记忆力单元"。

    结构

    文章中提到memory network由memory m,其中包含了多个slot。例如如果m是一个矩阵,则它的行|列就是一个slot。以及其他四个与memory交互的部分I,G,O,R组成:

    • I: (input feature map) – converts the incoming input to the internal feature representation
    • G: (generalization) – updates old memories given the new input. We call this generalization as there is an opportunity for the network to compress and generalize its memories at this stage for some intended future use.
    • O: (output feature map) – produces a new output (in the feature representation space), given the new input and the current memory state.
    • R: (response) – converts the output into the response format desired. For example, a textual response or an action.

    翻译一下:

    • I​ : 将输入转换为特征表示,不同的应用有不同的方法。例如NLP中的词向量化等。
    • G : 负责根据输入更新memory单元
    • O : 负责根据输入获取memory单元的输出
    • R : 将memory的输出转换为目标输出

    其中I,R算是memory的配套设施。主要与memory交互的还是GO这两个部分。一个负责更新memory,一个负责从memory中读取数据。
    文章对G的描述如下:
    \mathbf{m}_{H(x)}=I(x)
    H(.)用来选择更新哪一个slot,这个过程类似于计算机中的寻址。论文中还这样描述了G

    G updates the index H(x) of m, but all other parts of the memory remain untouched。

    也就是G只更新H(.)寻址到的slot,其他位置不变。论文中还提出了对H(.)的其他设想,例如H(.)可以在memory becomes full选择一些单元进替换,这一点在memory network的后续论文中都有实现,以后会讲到。
    文章对R的描述非常简洁:

    The O component is typically responsible for reading from memory and
    performing inference, e.g., calculating what are the relevant memories to perform a good response.

    也就是说R就是寻找一个与inputs相关的slot输出。

    一个实际的例子

    论文中也给出了基于这个框架的在问答任务上的一个例子。根据材料以及问题得出答案。数据采用一个toy data set。例如:

    Joe went to the kitchen. Fred went to the kitchen. Joe picked up the milk.
    Joe travelled to the office. Joe left the milk. Joe went to the bathroom.
    Where is the milk now? A: office
    Where is Joe? A: bathroom
    Where was Joe before the office? A: kitchen

    论文中给出的实现是这样的:
    先把一个句子通过embeding嵌入到一个向量。然后每一个 slot 存储一个句子向量。相当于H(x)始终返回一个空闲的slot。简单一点说,就是把材料中的每一个句子转换成一个向量,整个材料转换为一个矩阵。这个矩阵也就是memory m,这里其实一丁点新的东西都没有。然后对于输入的问题,仍然先转换为一个向量。然后使用函数s_O计算问题向量与每个slot的相似度。然后找出k supporting memories,也就是会找到 k 个 slots。具体的计算是这样的:

    1. 首先根据xs_O找出最相关的 slot , m_{o_1},采用o_{1}=O_{1}(x, \mathbf{m})=\underset{i=1, \ldots, N}{\arg \max } s_{O}\left(x, \mathbf{m}_{i}\right)计算m_{o1}
    2. 然后根据m_{o1}x找出m_{o2},方法为:
      o_{2}=O_{2}(x, \mathbf{m})=\underset{i=1, \ldots, N}{\arg \max } s_{O}\left(\left[x, \mathbf{m}_{o_{1}}\right], \mathbf{m}_{i}\right)

    按照上面的方法,通过xm_{o_1}, m_{o_2},...,m_{o_{k-1}}就能得出m_{o_k}。然后会将x,m_{o_1}, m_{o_2},...,m_{o_{k-1}}传递给R使用。然后,R会根据词库中的每一个词与slot的相关性输出最终的答案:
    r=\arg \max _{w \in W} s_{R}\left(\left[x, \mathbf{m}_{o_{1}}, \mathbf{m}_{o_{2}}\right], w\right)
    其中W代表词库中所有的词。论文中还给为什么使用这种方式给出了解释:

    In order to answer the question x = “Where is the milk now?”,
    the O module first scores all memories, i.e., all previously seen sentences, against x to retrieve the most relevant fact, mo1 = “Joe left the milk” in this case. Then, it would search the memory again to find the second relevant fact given [x, mo1], that is mo2 = “Joe travelled to the office” (the last place Joe went before dropping the milk). Finally, the R module using eq. (4) would score words given [x, mo1, mo2] to output r = “office”

    通俗易懂这里也就不再翻译了。最后,匹配输出词语以及寻找slot的相似函数如下:
    s(x, y)=\Phi_{x}(x)^{\top} U^{\top} U \Phi_{y}(y)

    一点分析

    事实上,看完这篇论文也不知道memory到底是什么。文章最终也没提到最终的实现方式相比传统模型为何有优点。实际模型中的的IG简直就是一个摆设,相当于传统模型的输入部分。最终的推理部分R,O也有很大 RNN 的影子,让人有一种强行memory的感觉。实际上,[1]中提出了更完善的memory 模型。这篇论文与其相比就显得简陋了许多。虽然是 ICLR 上的一篇论文,但是不得不让人感到有点水。。。

    参考

    [1] Neural turing machines
    [2] Memory Networks

    相关文章

      网友评论

        本文标题:Memory Network(1) - 给你的网络加点memor

        本文链接:https://www.haomeiwen.com/subject/wultmqtx.html