# 复习论文

复现者：[千寻](https://github.com/425776024/AP-MPCNN)

Attention-based Pairwise Multi-Perspective Convolutional Neural Network for Answer Selection in Question Answering

![](/files/-Lr7RuI9Ox3eysEfmoTb)

## 句子模型

### 句子输入

1.解析xml数据，变成成对的合法数据

2.下载解析golve向量

3.**Sentence Modeling** ：模型输入question/pa/na的处理

> 把句子编码矩阵：300x句子长。问题、答案都这样编码得到数字矩阵。
>
> 如果单词拿不到对应的词向量，unk词向量表示
>
> 词向量这里用的是golve300
>
> **Attention**：每个输出单词，聚焦于输入和输出单词更相关的部分

![](/files/-Lr7RuIHQkxVSVi-zbdu)

4.实现D矩阵计算，输入两个S句子，得到D：

$$
D\[i]\[j]=cos(s\_1\[:]\[i],s\_2\[:]\[j])
$$

5.实现E矩阵计算

$$
E\_1\[i]=\sum\_jD\[i]\[j],E\_2\[j]=\sum\_jD\[i]\[j]
$$

6.实现A矩阵计算

$$
\begin{aligned}
softmax(z)\[i]&=\frac{e^{z\[i]}}{\sum\_je^{z\[j]}};for \space i=1,2,...,|z|\\
\&A\_1=softmax(E\_1)\\
\&A\_2=softmax(E\_2)
\end{aligned}
$$

7.实现newEmb计算

$$
\begin{aligned}
newEmb\_1\[:]\[i]=A\_1\[i] \times S\_1\[:]\[i]\\
newEmb\_2\[:]\[i]=A\_2\[i] \times S\_2\[:]\[i]\\
\end{aligned}
$$

8.实现attenEmb

$$
\begin{aligned}
attenEmb\_1=concat(S\_1,newEmb\_1)\\
attenEmb\_2=concat(S\_2,newEmb\_2)
\end{aligned}
$$

Produced attention embedded will be sent as input to the convolutional neural network.

### 卷积层

The AP-MPCNN model uses holistic convolution (He, et al., 2015).

卷积核用的是全卷积，如下图上下是全跨度的，也就是上面输入的attenEmb矩阵的H

> 这种类型的卷积之所以被称为整体卷积，而每个过滤器被称为整体过滤器，是因为每个过滤器都覆盖词向量的所有维度

文章提到更好的捕捉两边的信息，要如下样子填充0，从最左边开始滑动

![](/files/-Lr7RuIKK_euWB7QeuSd)

计算

> 每个F代表一个元组$$\<w\_s,W\_f,b\_F,h\_F>$$，$$w\_s$$是滑动窗口长度
>
> $$W\_f \in R^{d\times ws}$$是卷积核参数
>
> $$b\_F$$是偏置
>
> $$h\_F$$是激活函数
>
> 输出还是｜S｜个长度，$$out\_F(\_s,S)\[i]=h\_f(W\_F.S\[:]\[i:i+w\_s-1]+b\_F),out\_F \in R^{|S|}$$

### Pooling池化

AP-MPCNN uses Max pooling to extract the most important features from convolutional feature maps

Tu (Tu, 2018) defines some objects composed of groups and blocks used to classify convolutions. A group is a tuple consisting of a convolutional layer with window size, a pooling function, and an embedded sentence.

$$
\begin{aligned}
\&group(w\_s,pooling,sent)=pooling(out\_F(ws,sent))\\
\&block={group(w\_s,max,sent):w\_s \in {1...M}}
\end{aligned}
$$

也就是多个不同大小的$$w\_s$$窗口滑动，得到不同的group，然后组成一组block

> (3.1.4)AP-MPCNN uses different sliding window sizes to test different grams

**Figure 5 shows a subnet from the input to the final pooling stage:**

![](/files/-Lr7RuIROUHG9tgYOim5)

## 相似测量层


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/lun-wen-yue-du/1-attention-based-pairwise-multi-perspective-convolutional-neural-network-for-answer-selection-in-qu/code-attention-based-pairwise-multi-perspective-convolutional-neural-network-for-answer-selection-in.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
