from tensorflow.keras.models import Sequential
from tensorflow.keras import layers
# set the embedding dimension
embedding_dim = 100
# create the model
model = Sequential([
layers.Embedding(max_words, embedding_dim, input_length=max_length),
layers.LSTM(64),
layers.Dense(1, activation='sigmoid')
])
# compile the model
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
# print the model summary
print(model.summary())
我尝试使用 Jupyter Notebook (.ipynb) 在 VSCode 中编译上述模型,但遇到以下错误:
AttributeError:模块“keras.src.backend”没有属性“floatx”
最初,我成功地编译了模型,但在拟合模型时导致 VScode 崩溃。重新加载 VSCode 后,我收到此错误。
为了解释上下文,我正在尝试构建一个非常基本的 NLP 模型,以根据情绪对亚马逊评论进行分类。我也在使用 Python 3.11 和 Tensorflow 版本 2.15
首先我尝试了以下方法:
import keras.backend as K
K.set_floatx('float32')
但是我遇到了同样的错误。然后我尝试重置 VSCode 并再次运行笔记本,但仍然遇到相同的错误?
回答我自己的问题。我重新启动桌面并再次运行所有内容,第二次重新启动时,它成功地编译了,没有问题