簡體   English   中英

精度很低的cnn

[英]Very low accuracy cnn

我正在嘗試使用 CNN 進行文本分類。 Model 使用 char 級詞嵌入 + 詞嵌入,然后使用 CNN 層提取特征,然后使用 Dense 層和softmax激活進行分類。 我的 model 使用categorical_crossentropy損失 function。

cnns = [
    [64, 3, 2],
    [128, 3, -1],
    [256, 5, 3],
    [256, 5, -1],
    [512, 5, 3],
]

nb_classes = 2

input_word = Input(shape = (default_max_len_words,), name='input_word')
input_chw = Input(shape = (default_max_len_words, default_max_len_subwords), name='input_chw')

embedding_word = Embedding(input_dim=size_of_word_vocab, output_dim=default_emb_dim, input_length=default_max_len_words, name='word_emb') (input_word)

embedding_chw = Embedding(input_dim=size_of_char_vocab, output_dim=default_emb_dim, input_length=default_max_len_subwords, name='chw_emb') (input_chw)
reduced = tf.keras.layers.Lambda(lambda x: tf.reduce_sum(x, axis=2), name='reduction')(embedding_chw)

x = Add(name='adding')([embedding_word, reduced])

for f, ks, ps in cnns: 
    x = Conv1D(filters=f, kernel_size=ks, padding='valid', activation='relu') (x)
    x = BatchNormalization() (x)
    if ps != -1:
        x = MaxPooling1D(pool_size=ps) (x)

x = Flatten() (x)
x = Dense(256, activation='relu') (x)
x = Dense(128, activation='relu') (x)

x = Dense(2, activation='softmax') (x)

model = keras.Model(inputs=[input_word, input_chw], outputs=x, name='temp')
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['Accuracy'])

在 10 個 epoch 之后,准確度和損失不再改變,准確度非常低(大約 16%)

loss: 0.0162 - accuracy: 0.1983 - val_loss: 1.8428 - val_accuracy: 0.0814

我已經檢查了我的數據。 沒有南。 並且數據在訓練之前被洗牌。

我發現了問題,現在已經解決了。 對於任何有同樣問題的人 keras 指標是區分大小寫的。 用“准確度”替換“准確度”使 model 工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM