【问题标题】:Trouble in Keras LabelingKeras标签的问题
【发布时间】:2020-12-29 21:53:46
【问题描述】:

我正在使用预处理来标记数据并使用 em 拟合模型

我的资源:@​​987654321@

这是我的代码(我想从否定词中检测肯定词):

from keras.preprocessing.text import one_hot
from keras.preprocessing.text import text_to_word_sequence
import pandas as pd
import numpy as np
from keras.layers import Dense
from keras.models import Sequential
from keras.preprocessing.text import Tokenizer
from tensorflow.keras.layers.experimental import preprocessing
data = ["Good", "Great", 'Bad', 'Awefull']
t = Tokenizer()
# fit the tokenizer on the documents
t.fit_on_texts(data)
# integer encode documents
x = t.texts_to_matrix(data, mode='count')
print(x)
y = np.array([[1],[1],[0],[0]])
print(y)
model = Sequential()
model.add(Dense(16, input_dim=2, activation='relu'))
model.add(Dense(16, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='mean_squared_error',
    optimizer='adam',
    metrics=['binary_accuracy'])
model.fit(x, y, verbose=2, epochs=500)
model.save("good_or_bad.h5")

我有这个错误:

raise ValueError(

    ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 2 but received input with shape [None, 5]

我该如何解决这个错误?

【问题讨论】:

    标签: python tensorflow machine-learning keras artificial-intelligence


    【解决方案1】:

    改变这一行:

    model.add(Dense(16, input_dim=5, activation='relu'))
    

    【讨论】:

      猜你喜欢
      • 2019-05-29
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-04
      • 2011-06-10
      • 2011-09-27
      • 2014-09-19
      相关资源
      最近更新 更多