【问题标题】:Deeplearning4j LSTM (how to) add feature in original DL4J example (UCISequenceClassification)Deeplearning4j LSTM(如何)在原始 DL4J 示例中添加功能(UCISequenceClassification)
【发布时间】:2021-12-12 05:34:10
【问题描述】:

想适应 UCISequenceClassification 的 deeplearning4j 示例: https://github.com/eclipse/deeplearning4j-examples/blob/master/dl4j-examples/src/main/java/org/deeplearning4j/examples/quickstart/modeling/recurrent/UCISequenceClassification.java。 该示例包含一个带有一个标签的特征。我想以完全相同的方式在另一个项目中使用该示例,但是...具有附加功能。所以我尝试添加一个功能(仅作为示例:我添加到代码中的常量值为 1)。 我尝试了多种方法都没有成功。有谁知道如何添加功能?我假设我必须选择另一个 SequenceRecordReader?这是我的第一次尝试:

操纵输入 - 替换这个:

 for (String line : lines) {
        String transposed = line.replaceAll(" +", "\n"); // HERE WILL BE THE CHANGE(!!!)

        //Labels: first 100 quickstartexamples (lines) are label 0, second 100 quickstartexamples are label 1, and so on
        contentAndLabels.add(new Pair<>(transposed, lineCount++ / 100));
    }

操作输入(添加一项功能) - 通过以下方式:

 for (String line : lines) {
        String transposed = line.replaceAll(" +", "|1\n"); // HERE IS THE CHANGE(!!!). I ADD VALUE 1

        //Labels: first 100 quickstartexamples (lines) are label 0, second 100 quickstartexamples are label 1, and so on
        contentAndLabels.add(new Pair<>(transposed, lineCount++ / 100));
    }

现在我尝试添加该功能: 原文:

SequenceRecordReader trainFeatures = new CSVSequenceRecordReader();       
trainFeatures.initialize(new NumberedFileInputSplit(featuresDirTrain.getAbsolutePath() + "/%d.csv", 0, 449));

我的改变:

SequenceRecordReader trainFeatures2 = new CSVMultiSequenceRecordReader("|",Mode.EQUAL_LENGTH); 
trainFeatures2.initialize(new NumberedFileInputSplit(featuresDirTrain.getAbsolutePath() + "/%d.csv", 0, 449));

不幸的是,这不起作用,因为他没有以正确的形式构建数据集。

所以我需要解决的主要问题是:如何更改 SequenceRecordReader 以包含第二个或多个功能?也许使用另一个 Reader 而不是 CSVMultiSequenceRecordReader?还是错误用法?

感谢任何提示。

(提示:请不要评论静态值 1 :-)。这应该只是代表我的例子。它将被另一个有意义的 int 值替换)

【问题讨论】:

    标签: machine-learning artificial-intelligence lstm deeplearning4j


    【解决方案1】:

    另一个功能取决于您使用的记录阅读器实现。 在您的情况下,您使用的是 csv,这意味着每个功能都表示为 CSV 中的一列。标签相似。

    您可以在此处阅读我们的文档,以更全面地了解该主题:https://deeplearning4j.konduit.ai/deeplearning4j/reference/recurrent-layers

    总之,每个文件代表一个时间序列。该文件中的每一列都代表一个特征。您需要对标签执行相同的操作。

    【讨论】:

      猜你喜欢
      • 2016-09-11
      • 1970-01-01
      • 1970-01-01
      • 2016-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-27
      相关资源
      最近更新 更多