为什么神经网络的准确性保持不变?

时间:2017-11-21 20:13:07

标签: machine-learning tensorflow neural-network deep-learning

我将时期从10增加到15,但这对准确性没有影响。两次准确度均为49.3%,损失为1.0。

知道为什么它可能会像这样吗?我是TensorFlow和深度学习的新手。

以下是培训方法:

def train_neural_network(x):
    prediction = neural_network_model(x)
    cost = tf.reduce_mean( tf.nn.softmax_cross_entropy_with_logits(logits=prediction,labels=y) )
    optimizer = tf.train.AdamOptimizer(learning_rate=0.001).minimize(cost)
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())

        try:
            epoch = int(open(tf_log,'r').read().split('\n')[-2]) + 1
            print('STARTING:',epoch)
        except:
            epoch = 1
        # this will track epochs using a log file
        while epoch <= n_epochs:
            if epoch != 1:
                saver.restore(sess,"./model.ckpt")
            epoch_loss = 1
            with open('lexicon-2500-2638.pickle','rb') as f:
                lexicon = pickle.load(f)
                print("lexicon length: ", len(lexicon))
            with open('train_set_shuffled.csv', buffering=20000, encoding='latin-1') as f:
                batch_x = []
                batch_y = []
                batches_run = 0
                for line in f:
                    label = line.split(':::')[0]
                    tweet = line.split(':::')[1]
                    current_words = word_tokenize(tweet.lower())
                    current_words = [lemmatizer.lemmatize(i) for i in current_words]

                    features = np.zeros(len(lexicon))

                    for word in current_words:
                        if word.lower() in lexicon:
                            index_value = lexicon.index(word.lower())

                            features[index_value] += 1
                    line_x = list(features)
                    line_y = eval(label)
                    batch_x.append(line_x)
                    batch_y.append(line_y)
                    if len(batch_x) >= batch_size:
                        _, c = sess.run([optimizer, cost], feed_dict={x: np.array(batch_x),
                                                                      y: np.array(batch_y)})
                        epoch_loss += c
                        batch_x = []
                        batch_y = []
                        batches_run += 1
                        print('Batch run:',batches_run,'/',total_batches,'| Epoch:',epoch,'| Batch Loss:',c,)

            saver.save(sess, "./model.ckpt")
            print('Epoch',epoch,'completed out of',n_epochs,'loss:',epoch_loss)
            with open(tf_log,'a') as f:
                f.write(str(epoch) + '\n')
            epoch += 1
     train_neural_network(x)

1 个答案:

答案 0 :(得分:1)

除了#of epochs之外,还有许多参数可以提高神经网络的效率。

作为第一次尝试,您可能想尝试使用:

  • 不同的批量大小
  • 神经网络的不同架构(即增加层数)。
  • 不同的特征转换(即,可能尝试阻止而不是使用lematizing)

您还可以做更多事情,我建议您查看primer

祝你好运! :)