我有一些文本数据,每个文档都有多个标签。我想使用 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/