lstm rnn'序列'对象没有属性。

发布于 2025-02-09 16:15:05 字数 921 浏览 1 评论 0原文

我正在对RNN模型进行预测,并且错误地说:

AttributeError                            Traceback (most recent call last)
<ipython-input-18-cd3fe876f68d> in <module>
      1 # Make sentiment predictions
----> 2 predictions = model.predict_classes(X_test)

AttributeError: 'Sequential' object has no attribute 'predict_classes'

我正在做一个复杂的情感分析模型,该模型将编码/代币注释用于使用LSTM层的深度NN工作,目标是可以将所有这些注释和所有评论提供给RNN在此.CSV文件中预测每个评论中每个评论的积极分数。该模型将输出0表示负面评论或1以供积极评论。

所以我处于最后阶段。我对所有数据进行了预处理,编码/令牌化,并构建了NN模型,现在我正在运行训练。我决定训练几个时期,因为它正在吃笔记本电脑的记忆。

# Training the model
batch_size = 1000
epochs = 10

model.fit(
    X_train_rnn,
    y_train_rnn,
    validation_data = (X_val_rnn, y_val_rnn),
    epochs = epochs,
    batch_size = batch_size,
    verbose = 1
)

在我的计算机训练该型号几分钟后,我尝试做出预测,在此遇到错误的地方:

y_rnn_pred = model.predict_classes(X_test_rnn, batch_size=1000)

I'm running predictions on an RNN model and it errors saying:

AttributeError                            Traceback (most recent call last)
<ipython-input-18-cd3fe876f68d> in <module>
      1 # Make sentiment predictions
----> 2 predictions = model.predict_classes(X_test)

AttributeError: 'Sequential' object has no attribute 'predict_classes'

I'm doing a complicated sentiment analysis model that feeds encoded/tokens comments into a Deep NN work using LSTM Layers, the goal is can a RNN be fed all these comments and predict the positivity score of the each comment in this .csv file of 25,000 comments. The model will output either 0 for negative comment or 1 for positive comment.

So I'm at the final stages. I pre-processed and encoded/tokenized all my data, built the NN model, and now I'm running it to train. I decided to train on a few epochs because it's eating the memory of laptop.

# Training the model
batch_size = 1000
epochs = 10

model.fit(
    X_train_rnn,
    y_train_rnn,
    validation_data = (X_val_rnn, y_val_rnn),
    epochs = epochs,
    batch_size = batch_size,
    verbose = 1
)

After my computer trains this model for minutes on end, then I try to make predictions and this where I get the error:

y_rnn_pred = model.predict_classes(X_test_rnn, batch_size=1000)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

呆° 2025-02-16 16:15:05

如果您使用的是TF.KERAS版本2.5+
替换

y_rnn_pred = model.predict_classes(X_test_rnn, batch_size=1000)

y_rnn_pred = (model.predict(X_test_rnn, batch_size=1000) > 0.5).astype("int32")

If you are using tf.keras version 2.5+
replace

y_rnn_pred = model.predict_classes(X_test_rnn, batch_size=1000)

with

y_rnn_pred = (model.predict(X_test_rnn, batch_size=1000) > 0.5).astype("int32")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文