**我正在尝试保存模型以便在 Web 应用程序中使用它,但出现此错误 **
X = []
sentences = list(review_df['text'])
for sen in sentences:
X.append(clean_text(sen))
y = review_df['Label']
y = np.array(list(map(lambda x: 1 if x=="fake" else 0, y)))
#使用递归神经网络 (LSTM) 进行文本分类
from keras.layers.recurrent import LSTM
model = Sequential()
embedding_layer = Embedding(vocab_size, 100, weights=[embedding_matrix], input_length=maxlen ,
trainable=False)
model.add(embedding_layer)
model.add(LSTM(128))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['acc'])
print(model.summary())
#训练模型
history = model.fit(X_train, y_train, batch_size=128, epochs=6, verbose=1, validation_split=0.2)
score = model.evaluate(X_test, y_test, verbose=1)
#打印模型结果
print("Test Score:", score[0])
print("Test Accuracy:", score[1])
#对单个实例进行预测
instance = X[57]
print(instance)
instance = tokenizer.texts_to_sequences(instance)
flat_list = []
for sublist in instance:
for item in sublist:
flat_list.append(item)
flat_list = [flat_list]
instance = pad_sequences(flat_list, padding='post', maxlen=maxlen)
model.predict(instance)
#保存模型
import pickle
with open('model.pkl', 'wb') as f:
pickle.dump(model, f)
当我尝试保存模型时出现此错误: TypeError: can't pickle _thread.RLock objects 有没有解决此错误的想法
噜噜哒
吃鸡游戏
相关分类