1

我正在尝试使用此示例来训练文本数据,将其标记为正面或负面。但我不明白什么输入应该是训练功能的输入。在 test_sda 函数中,它有一些矩阵,如:train_X、train_Y、test_X、test_Y 和一些变量:train_N、test_N。我不知道这些是什么意思。

就我而言,我使用 SDA 来构建越南情绪分类,请指导我应该为 SDA 输入哪些数据。

private static void test_sda() {
    Random rng = new Random(123);

    double pretrain_lr = 0.1;
    double corruption_level = 0.3;
    int pretraining_epochs = 1000;
    double finetune_lr = 0.1;
    int finetune_epochs = 500;

    int train_N = 10;
    int test_N = 4;
    int n_ins = 28;
    int n_outs = 2;
    int[] hidden_layer_sizes = {15, 15};
    int n_layers = hidden_layer_sizes.length;

    // training data
    int[][] train_X = {
            {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            {0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            {1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1},
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1},
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1},
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1}
    };

    int[][] train_Y = {
            {1, 0},
            {1, 0},
            {1, 0},
            {1, 0},
            {1, 0},
            {0, 1},
            {0, 1},
            {0, 1},
            {0, 1},
            {0, 1}
    };

    // construct SdA
    SdA sda = new SdA(train_N, n_ins, hidden_layer_sizes, n_outs, n_layers, rng);

    // pretrain
    sda.pretrain(train_X, pretrain_lr, corruption_level, pretraining_epochs);

    // finetune
    sda.finetune(train_X, train_Y, finetune_lr, finetune_epochs);


    // test data
    int[][] test_X = {
            {1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            {1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1},
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1}
    };

    double[][] test_Y = new double[test_N][n_outs];

    // test
    for(int i=0; i<test_N; i++) {
        sda.predict(test_X[i], test_Y[i]);
        for(int j=0; j<n_outs; j++) {
            System.out.print(test_Y[i][j] + " ");
        }
        System.out.println();
    }
}

非常感谢。

4

0 回答 0