简体   繁体   English

Deeplearning4j:用于评论情绪分析的LSTM示例

[英]Deeplearning4j: LSTM example for review sentiment analysis

I am looking through the example of deeplearning 4j for classifying movie reviews according to their sentiment. 我正在查看deeplearning 4j的例子,根据他们的情绪对电影评论进行分类。 ReviewExample ReviewExample

At line 124-142 the N-dimensional arrays are created and I am kind of unsure what is happening at these lines: 在第124-142行,创建了N维数组,我不确定这些行发生了什么:

Line 132: 第132行:

features.put(new INDArrayIndex[]{NDArrayIndex.point(i),
NDArrayIndex.all(), NDArrayIndex.point(j)}, vector);

I can image that .point(x) and .point(j) address the cell in the array, but what exactly does the NDArrayIndex.all() call do here? .point(x).point(j)对数组中的单元格进行寻址,但是NDArrayIndex.all()调用到底在做什么呢?

While building the feature array is more or less ok what is happening there I get totally confused by the label mask and this lastIdx variable 虽然构建特征数组或多或少可以正常发生,但我完全被标签掩码和lastIdx变量lastIdx糊涂了

Line 138 - 142 第138-142行

            int idx = (positive[i] ? 0 : 1);
            int lastIdx = Math.min(tokens.size(),maxLength);
            labels.putScalar(new int[]{i,idx,lastIdx-1},1.0);   //Set label: [0,1] for negative, [1,0] for positive
            labelsMask.putScalar(new int[]{i,lastIdx-1},1.0);   //Specify that an output exists at the final time step for this example

The label array itself is addressed by i, idx eg column/row that is set to 1.0 - but I don't really get how this time-step information fits in? 标签数组本身由i, idx例如设置为1.0的列/行)寻址 - 但我真的不知道这个时间步信息是如何适应的? Is this conventional that the last parameter has to mark the last entry? 这是常规的最后一个参数必须标记最后一个条目吗?

Then why does the labelsMask use only i and not i, idx ? 那么为什么labelsMask只使用i而不是i, idx

Thanks for explanations or pointer that help to clarify some of my questions 感谢您的解释或指针,以帮助澄清我的一些问题

It's an index per dimension. 这是每个维度的索引。 All() is an indicator (use this whole dimension). All()是一个指标(使用整个维度)。 See the nd4j user guide: http://nd4j.org/userguide 请参阅nd4j用户指南: http ://nd4j.org/userguide

As for the 1. That 1 is meant to be the class for the label there. 至于1.那1是那里的标签类。 It's a text classification problem: Take the window from the text and word vectors and have the class be predicted from that. 这是一个文本分类问题:从文本和单词向量中取出窗口,并从中预测类。

As for the label mask: The prediction of a neural net happens at the end of a sequence. 至于标签掩码:神经网络的预测发生在序列的末尾。 See: http://deeplearning4j.org/usingrnns 请参阅: http//deeplearning4j.org/usingrnns

write a test and you will know it. 写一个测试,你会知道它。

val features = Nd4j.zeros(2, 2, 3) val toPut = Nd4j.ones(2) features.put(Array[INDArrayIndex](NDArrayIndex.point(0), NDArrayIndex.all, NDArrayIndex.point(1)), toPut) val features = Nd4j.zeros(2,2,3)val toPut = Nd4j.ones(2)features.put(Array [INDArrayIndex](NDArrayIndex.point(0),NDArrayIndex.all,NDArrayIndex.point(1)),放在)

the result is [[[0.00, 1.00, 0.00], 结果是[[[0.00,1.00,0.00],
[0.00, 1.00, 0.00]], [0.00,1.00,0.00]],

[[0.00, 0.00, 0.00], [[0.00,0.00,0.00],
[0.00, 0.00, 0.00]]] it will put the 'toPut' vector to the features. [0.00,0.00,0.00]]]它会将'toPut'向量放到要素上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM