# RankNet

RankNet是通过一个神经网络模型来计算样本的**得分**，输入层和样本特征维数有关，输出层是一个节点，就是分值。以三层的神经网络模型举例，则计算分值函数定义为：

$$
s\_n = f(x\_n) = g^3(\Sigma\_j W\_{ij}^{32}g^2(\Sigma\_k W\_{jk}^{21}x\_{nk} + b^2) + b^3)
$$

其中权值参数w和偏置参数b的上标表示节点所在的层，下标表示同一层中节点的编号；$$x\_{nk}$$表示特征向量$$x\_n$$的第k个分量，这是是输入到输入层的。\
RankNet是从概率角度解决排序的问题,证明了如果知道一个待排序文档的排列中相邻两个文档之间的排序概率，则通过推导可以算出每两个文档之间的排序概率。因此对于一个待排序文档序列，**只需计算相邻文档之间的排序概率**，不需要计算所有pair，减少计算量。

## 损失函数

训练时以预测概率与真实概率的交叉熵作为损失函数

* 预测概率：

$$
P\_{ij} \equiv P(D\_i \triangleright D\_j) \equiv \frac {1}{1+e^{-\sigma(s\_i-s\_j)}}
$$

$$s\_i$$ ：文档$$D\_i$$模型计算出来的得分

* 真实概率：

$$
\overline P\_{ij} = \frac {1}{2}(1+S\_{ij})
$$

$$S\_{ij}$$ 文档$$D\_i$$与$$D\_j$$真实排序。取值{-1,0,1}。1表示$$D\_i$$应该在$$D\_j$$前面，-1表示$$D\_i$$应该在$$D\_j$$后面，0表示谁前谁后无所谓

* 交叉熵：

$$
C = - \overline P\_{ij} \log P\_{ij} - (1 - \overline P\_{ij}) \log (1-\log P\_{ij}) \\
\= \frac {1}{2} (1-S\_{ij}) \sigma(s\_i-s\_j) + \log (1+e^{-\sigma(s\_i-s\_j)}) \\
\text{log以e为底数}
$$

**预测概率函数**就是逻辑回归的sigmoid函数，由于$$\sigma$$ 影响的是sigmoid函数的形状，对最终结果影响不大，因此默认使用 $$\sigma=1$$进行简化。

**损失函数**有以下几个特点：

* 当两个相关性不同的文档算出来的模型分数相同时，损失函数的值大于0，仍会对这对pair做惩罚，使他们的排序位置区分开
* 损失函数是一个类线性函数，可以有效减少异常样本数据对模型的影响，因此具有鲁棒性

## 反向梯度下降

$$
W\_k \to W\_k - \eta \frac {\partial C}{\partial W\_k} =
W\_k - \eta (\frac {\partial C}{\partial s\_i} \frac {\partial s\_i}{\partial W\_k} + \frac {\partial C}{\partial s\_j} \frac {\partial s\_j}{\partial W\_k})
$$

### 参考佳文：

[再理解RankNet算法](http://blog.csdn.net/puqutogether/article/details/43667375)\
[Learning To Rank之LambdaMART的前世今生](http://blog.csdn.net/huagong_adu/article/details/40710305)


---

# 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://json007.gitbook.io/svm/rank/ranknet.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.
