【问题标题】:How to perform multi-label learning with LSTM using theano?如何使用 theano 使用 LSTM 执行多标签学习?
【发布时间】:2015-05-20 01:30:49
【问题描述】:

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

谢谢, 阿米特

【问题讨论】:

    标签: neural-network theano deep-learning lstm


    【解决方案1】:

    您可以更改模型的最后一层。它将有一个目标向量,其中每个元素为 0 或 1,具体取决于您是否有目标。

    【讨论】:

      【解决方案2】:

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

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

      应该被其他层替换,例如乙状结肠:

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

      2) 成本也应该改变。

      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 分数等一些指标)。

      【讨论】:

        猜你喜欢
        • 2018-04-05
        • 2019-11-28
        • 2015-08-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-22
        • 2022-12-14
        • 1970-01-01
        相关资源
        最近更新 更多