CNN

时间:2017-06-26 13:42:58

标签: python machine-learning tensorflow

我已经采用了这个CNN示例(https://github.com/dennybritz/cnn-text-classification-tf),它将电影评论分类为正面或负面,并尝试对数组数组进行分类,而不是整数数组。我已经采用了这个例子并对其进行了调整,以便为每个类分类更多的输入数据。问题是在我的版本中它只分类2个类中的一个,精度为1.0,另一个分类的精度为0.0。任何帮助将不胜感激!

作为输入,该示例最初具有作为X的向量列表和作为Y的对应的分类列表:

原始示例中的input_x(每个分类17个整数):

    [1', 2', 3', 4', 5', 6', 7', 8', 0', 0', 0', 0', 0', 0', 0', 0', 0'],
    [1', 2', 23', 49', 58', 64', 27', 82', 33', 0', 0', 0', 0', 0', 0', 0', 0']
原始示例中的

input_y:

    [1,0], #this was a negative movie review
    [0,1]  #this was a positive movie review

新输入(在我的调整之后)包含一个大约713个数组的数组,其中包含60个浮点数:

我的版本中的input_x(每个分类有7个60个浮点阵列):

    [0.86099077150603431, 0.129, 0.12933333333333333, 0.12966666666666668, 0.13, 0.13033333333333333, 0.13066666666666665, 0.124, 0.083333333333333329, 0.13100000000000001, 0.083333333333333329, 0.13133333333333333, 0.017999999999999999, 0.13166666666666665, 0.13200000000000001, 0.13233333333333333, 0.13266666666666665, 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, 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, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.86099080964707053, 0.5403, 0.54000000000000004]
    [0.8609932408012354, 0.59399999999999997, 0.125, 0.59433333333333338, 0.024666666666666667, 0.53300000000000003, 0.59466666666666668, 0.59499999999999997, 0.59533333333333338, 0.0096666666666666672, 0.29266666666666669, 0.59433333333333338, 0.14733333333333334, 0.0089999999999999993, 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, 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, 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.86099298342284247, 0.54069999999999996, 0.54044999999999999]
    [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, 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, 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, 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.86099227073780937, 0.54059999999999997, 0.54044999999999999]

我的版本中的input_y:

    [1,0] #one classification for an entire batch of 713 arrays of 60 floats

当仅使用12个相应分类(每批1个分类)的12个数据集进行培训时,准确性和损失发展如下:

Accuracy graph to 20 batches

突出的是,一旦训练模型,每批的准确度为0.0或1.0。它将[0,1]的精度分类为1,而精度为0.0的[1,0]分类。这可能是什么问题?我尝试调整所有参数,例如学习率和滤镜/卷积层数。 (学习率似乎最好在0.01左右,而filters_sizes的数量似乎效果最好如下:3,4,5,6)

这里是早期批次和成熟批次。注意准确性的差异。

    ------------------------------------------------------------------
    ------------------------------Batch 5----------------------------
    ------------------------------------------------------------------
    ---- Training averages per batch: loss: 5.57, accuracy:0.79 ---

    2017-06-26T11:17:54.625416: step 49, loss 0.60, acc 0.83 - X: 713/670Y:[0 1]
    2017-06-26T11:18:01.825974: step 50, loss 0.55, acc 0.99 - X: 712/422Y:[0 1]
    2017-06-26T11:18:08.960984: step 51, loss 11.40, acc 0.01 - X: 713/578Y:[1 0]
    2017-06-26T11:18:15.795436: step 52, loss 2.77, acc 0.29 - X: 712/477Y:[0 1]
    2017-06-26T11:18:22.635306: step 53, loss 1.05, acc 0.57 - X: 713/464Y:[1 0]
    2017-06-26T11:18:29.465720: step 54, loss 3.22, acc 0.19 - X: 712/447Y:[0 1]
    2017-06-26T11:18:36.271625: step 55, loss 0.97, acc 0.62 - X: 713/581Y:[0 1]
    2017-06-26T11:18:43.075573: step 56, loss 0.58, acc 0.92 - X: 712/475Y:[0 1]
    2017-06-26T11:18:49.843150: step 57, loss 0.56, acc 0.99 - X: 712/618Y:[0 1]
    2017-06-26T11:18:56.643769: step 58, loss 0.56, acc 1.00 - X: 712/683Y:[0 1]
    2017-06-26T11:19:03.465074: step 59, loss 0.56, acc 1.00 - X: 713/464Y:[0 1]
    2017-06-26T11:19:10.300384: step 60, loss 0.56, acc 1.00 - X: 713/636Y:[0 1]

在培训过程的后期,每批的准确度为0.0或1.0,这导致总的精确度平均为0.83。

    ------------------------------------------------------------------
    ------------------------------Batch 9----------------------------
    ------------------------------------------------------------------
    ---- Training averages per batch: loss: 1.09, accuracy:0.83 ---

    2017-06-26T11:23:30.285332: step 97, loss 0.99, acc 1.00 - X: 713/670Y:[0 1]
    2017-06-26T11:23:37.453523: step 98, loss 1.31, acc 0.00 - X: 713/464Y:[1 0]
    2017-06-26T11:23:44.365591: step 99, loss 1.31, acc 0.00 - X: 713/578Y:[1 0]
    2017-06-26T11:23:51.450830: step 100, loss 0.96, acc 1.00 - X: 712/475Y:[0 1]
    2017-06-26T11:23:58.571929: step 101, loss 0.96, acc 1.00 - X: 713/464Y:[0 1]
    2017-06-26T11:24:05.490809: step 102, loss 0.95, acc 1.00 - X: 712/618Y:[0 1]
    2017-06-26T11:24:12.307687: step 103, loss 0.95, acc 1.00 - X: 712/683Y:[0 1]
    2017-06-26T11:24:19.114356: step 104, loss 0.94, acc 1.00 - X: 713/581Y:[0 1]
    2017-06-26T11:24:26.267000: step 105, loss 0.93, acc 1.00 - X: 712/422Y:[0 1]
    2017-06-26T11:24:33.391093: step 106, loss 0.92, acc 1.00 - X: 712/447Y:[0 1]
    2017-06-26T11:24:40.632168: step 107, loss 0.92, acc 1.00 - X: 713/636Y:[0 1]
    2017-06-26T11:24:47.740179: step 108, loss 0.91, acc 1.00 - X: 712/477Y:[0 1]

如果需要,我可以发布代码。任何帮助将不胜感激!

0 个答案:

没有答案