简体   繁体   English

keras val_loss:0.0000e+00 - val_accuracy:0.0000e+00

[英]keras val_loss: 0.0000e+00 - val_accuracy: 0.0000e+00

In my network the validation metrics if fixed on 0.0000e+00 from the epoch.在我的网络中,如果从 epoch 开始,验证指标固定为 0.0000e+00。

I've looked around that few people had the same problem but I'm not be able to fix it following same advices.我环顾四周,很少有人遇到同样的问题,但我无法按照相同的建议解决它。

Rows are shuffled and label is already transformaned into float32.行被打乱,并且 label 已经转换为 float32。 These are suggestions I've found on similar questions.这些是我在类似问题上找到的建议。 Can you tell me what i'm wrong?你能告诉我我错了吗?

# data here https://www.kaggle.com/crowdflower/twitter-airline-sentiment
dtf_data = pd.read_csv(str_path + "Tweets.csv")

def clean_data(str_text): 
    lst_tokens = str_text.split()
    lst_tokens = [w for w in lst_tokens if not any(True for e in ["@", "#"] if e in w)]
    table = str.maketrans('', '', string.punctuation)
    lst_tokens = [c.translate(table) for c in lst_tokens]
    lst_tokens = [str_word for str_word in lst_tokens if str_word.isalpha()] # solo parole
    lst_stop_words = set(stopwords.words('english'))
    lst_tokens = [str_word for str_word in lst_tokens if not str_word in lst_stop_words and len(str_word) > 1]
    return " ".join(lst_tokens)

dtf_data["text_cleaned"] = dtf_data["text"].apply(lambda x: clean_data(x))
dtf_data["y"] = (dtf_data["airline_sentiment"] == "positive").astype(int)

X_train, X_test, y_train, y_test = train_test_split(dtf_data["text_cleaned"], dtf_data["y"], test_size=.25, random_state=0)

y_train = np.array(y_train, dtype = 'float32')
y_test = np.array(y_test, dtype = 'float32')

def build_corpus(dtf_in, str_col):
    corpus = []
    for sentence in dtf_in[str_col].iteritems():
        word_list = sentence[1].split()
        corpus.append(word_list)

    return corpus

corpus = build_corpus(dtf_data, 'text_cleaned')

model2vec = word2vec.Word2Vec(corpus, size=50)

tokenizer = Tokenizer()
tokenizer.fit_on_texts(corpus)

corpus_train, corpus_test = train_test_split(corpus, test_size=.25, random_state=0)
sequences_train = tokenizer.texts_to_sequences(corpus_train)
sequences_test = tokenizer.texts_to_sequences(corpus_test)

word_index = tokenizer.word_index
print('Found %s unique tokens' % len(word_index))

data_train = pad_sequences(sequences_train, maxlen=20)
data_test = pad_sequences(sequences_test, maxlen=20)
# pred = np.array(data.sentiment.values)
print('Shape of data tensor:', data_train.shape)
print('Shape of label tensor:', data_test.shape)

nb_words = min(200000, len(word_index))+1

embedding_matrix = np.zeros((nb_words, 50))
for word, i in word_index.items():
    if word in model2vec.wv.vocab:
        embedding_matrix[i] = model2vec.wv[word]

data_train, y_train = shuffle(data_train, y_train, random_state=0)
data_test, y_test = shuffle(data_test, y_test, random_state=0)

model_input = Input(shape=(20,))

model = Embedding(nb_words, 50, weights=[embedding_matrix],input_length=20,
        trainable=False)(model_input)
model = Dropout(0.25)(model)

model = LSTM(20, dropout=0.35,recurrent_dropout=0.35)(model)
model = BatchNormalization()(model)

model = Dropout(0.25)(model)
model = Dense(32)(model)
model = Activation('relu')(model)
model = BatchNormalization()(model)

model = Dense(1)(model)
out = Activation('sigmoid')(model)

opt = SGD(lr = 0.1, momentum = 0.9, nesterov=True)

model = Model(inputs=model_input, outputs=out)

model.compile(loss='binary_crossentropy',
              optimizer=opt,
              metrics=['accuracy'])

model.fit(data_train, y_train,
          batch_size=128,
          epochs=5,
          verbose=1,
          validation_data=[data_test, y_test])

Epoch 1/5
68/68 [==============================] - 1s 22ms/step - loss: 0.5084 - accuracy: 0.7975 - val_loss: 0.0000e+00 - val_accuracy: 0.0000e+00
Epoch 2/5
68/68 [==============================] - 1s 19ms/step - loss: 0.5109 - accuracy: 0.7976 - val_loss: 0.0000e+00 - val_accuracy: 0.0000e+00
Epoch 3/5
68/68 [==============================] - 1s 19ms/step - loss: 0.5095 - accuracy: 0.7976 - val_loss: 0.0000e+00 - val_accuracy: 0.0000e+00
Epoch 4/5
68/68 [==============================] - 1s 19ms/step - loss: 0.5084 - accuracy: 0.7975 - val_loss: 0.0000e+00 - val_accuracy: 0.0000e+00
Epoch 5/5
68/68 [==============================] - 1s 20ms/step - loss: 0.5083 - accuracy: 0.7973 - val_loss: 0.0000e+00 - val_accuracy: 0.0000e+00

In addition I found that the metrics in validation is actually different此外我发现验证中的指标实际上是不同的

accuracy_score(y_test, [c[0]>.3 for c in model.predict(data_test)])
0.7661122661122661

I really do not understand why this issue occured.我真的不明白为什么会出现这个问题。 Any idea?任何想法? Thank you谢谢

Fixed.固定的。 I've just downgraded my tensorflow to 2.0.我刚刚将我的 tensorflow 降级到 2.0。 pip install tensorflow==2.0 pip 安装张量流==2.0

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

相关问题 “损失:0.0000e+00 - acc: 1.0000 - val_loss: 0.0000e+00 - val_acc: 1.0000”是什么意思? - what does "loss: 0.0000e+00 - acc: 1.0000 - val_loss: 0.0000e+00 - val_acc: 1.0000" mean? 如何修复分类分类中的“val_accuracy: 0.0000e+00”? - How to fix “val_accuracy: 0.0000e+00” in categorical classification? Keras 损失:0.0000e+00 且精度保持不变 - Keras loss: 0.0000e+00 and accuracy stays constant 为什么我的准确率总是0.0000e+00,而且损失巨大? - Why is my accuracy always 0.0000e+00, and loss and huge? CNN 精度:0.0000e+00 用于图像的多分类 - CNN accuracy: 0.0000e+00 for multi-classification on images 获得精度:0.0000e+00 在我的张量流 model - Getting accuracy: 0.0000e+00 in my Tensor flow model 我使用 fit_generator 的损失是 0.0000e+00(使用 Keras) - My loss with fit_generator is 0.0000e+00 (using Keras) 如何解决 LSTM 问题中的 loss: nan &accuracy: 0.0000e+00? 张量流 2.x - How to solve loss: nan & accuracy: 0.0000e+00 in a LSTM problem? Tensorflow 2.x Conv2d Tensorflow 结果错误 - 准确度 = 0.0000e+00 - Conv2d Tensorflow results wrong - accuracy = 0.0000e+00 Twitter 情绪分析常数零(0.0000e+00)损失值 - Twitter Sentiment Analysis Constant Zero (0.0000e+00) Loss value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM