上下文:我有一组文档,每个文档都有两个关联的概率值:属于A类的概率或属于B类的概率。这些类是互斥的,并且这些概率加在一起。因此,例如,文档D具有与基本事实相关的概率(0.6,0.4)。

每个文档都由其包含的术语的tfidf表示,从0标准化为1。我还尝试了doc2vec(从-1标准化为1的形式)和其他几种方法。

我建立了一个非常简单的神经网络来预测这种概率分布。


输入层具有与要素一样多的节点
具有一个节点的单个隐藏层
具有softmax和两个节点的输出层
交叉熵损失函数
我还尝试了不同的更新功能和学习率


这是我使用nolearn编写的代码:

net = nolearn.lasagne.NeuralNet(
    layers=[('input', layers.InputLayer),
        ('hidden1', layers.DenseLayer),
        ('output', layers.DenseLayer)],
    input_shape=(None, X_train.shape[1]),
    hidden1_num_units=1,
    output_num_units=2,
    output_nonlinearity=lasagne.nonlinearities.softmax,
    objective_loss_function=lasagne.objectives.binary_crossentropy,
    max_epochs=50,
    on_epoch_finished=[es.EarlyStopping(patience=5, gamma=0.0001)],
    regression=True,
    update=lasagne.updates.adam,
    update_learning_rate=0.001,
    verbose=2)
net.fit(X_train, y_train)
y_true, y_pred = y_test, net.predict(X_test)


我的问题是:我的预测有一个临界点,没有一个预测低于该临界点(查看图片以了解我的意思)。
This plot shows the difference between the true probability and my predictions。一点与红线越近,预测越好。理想情况下,所有要点都应在线上。我该如何解决?为什么会这样?

编辑:实际上我通过简单地删除隐藏层解决了问题:

net = nolearn.lasagne.NeuralNet(
    layers=[('input', layers.InputLayer),
        ('output', layers.DenseLayer)],
    input_shape=(None, X_train.shape[1]),
    output_num_units=2,
    output_nonlinearity=lasagne.nonlinearities.softmax,
    objective_loss_function=lasagne.objectives.binary_crossentropy,
    max_epochs=50,
    on_epoch_finished=[es.EarlyStopping(patience=5, gamma=0.0001)],
    regression=True,
    update=lasagne.updates.adam,
    update_learning_rate=0.001,
    verbose=2)
net.fit(X_train, y_train)
y_true, y_pred = y_test, net.predict(X_test)


但是我仍然不明白为什么会有这个问题,以及为什么删除隐藏层可以解决它。有任何想法吗?

这里是新情节:

最佳答案

我认为您的训练集输出值应为[0,1]或[1,0],
[0.6,0.4]不适合softmax / Crossentropy。

07-24 09:52