neural-network - 如何使用 theano 使用 LSTM 进行多标签学习?

标签 neural-network theano deep-learning lstm

我有一些文本数据,每个文档都有多个标签。我想使用 Theano 为这个数据集训练一个 LSTM 网络。我遇到了http://deeplearning.net/tutorial/lstm.html但它只会促进二元分类任务。如果有人对继续使用哪种方法有任何建议,那就太好了。我只需要一个初步可行的方向,我可以继续工作。

谢谢,
阿米特

最佳答案

1)改变模型的最后一层。 IE。

pred = tensor.nnet.softmax(tensor.dot(proj, tparams['U']) + tparams['b'])

应该由其他一些层替换,例如乙状结肠:
pred = tensor.nnet.sigmoid(tensor.dot(proj, tparams['U']) + tparams['b'])

2)成本也应该改变。

IE。
cost = -tensor.log(pred[tensor.arange(n_samples), y] + off).mean()

应该用其他一些费用代替,例如交叉熵:
one = np.float32(1.0)
pred = T.clip(pred, 0.0001, 0.9999)  # don't piss off the log
cost = -T.sum(y * T.log(pred) + (one - y) * T.log(one - pred), axis=1) # Sum over all labels
cost = T.mean(cost, axis=0) # Compute mean over samples

3) 在函数中 build_model(tparams, options) ,你应该替换:
y = tensor.vector('y', dtype='int64')

经过
y = tensor.matrix('y', dtype='int64') # Each row of y is one sample's label e.g. [1 0 0 1 0]. sklearn.preprocessing.MultiLabelBinarizer() may be handy.

4) 更改 pred_error()以便它支持多标签(例如,使用一些指标,如来自 scikit-learn 的准确性或 F1 分数)。

关于neural-network - 如何使用 theano 使用 LSTM 进行多标签学习?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29102165/

相关文章:

java - 如何在保持其尺寸不变的情况下放大缩放图像?

machine-learning - 开源神经网络库

python - Lasagne/Theano 梯度值

machine-learning - 有没有像「scaler.inverse_transform()」这样的方法来获取部分缩放器参数来对答案进行反规范化?

python - 通过随机初始化权重进行 0 次训练后会发生什么?

neural-network - ANN 多输出与单输出

machine-learning - 深度学习和传统的人工神经网络机器学习有什么区别?

python - 简单千层面网络输出很慢

python - 训练回归网络时的 NaN 损失

annotations - 如何注释图像分割的基本事实?