**我正在尝试保存模型以便在 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 LSTMmodel = 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 picklewith open('model.pkl', 'wb') as f:pickle.dump(model, f)当我尝试保存模型时出现此错误: TypeError: can't pickle _thread.RLock objects 有没有解决此错误的想法
添加回答
举报
0/150
提交
取消