`python keras.preprocessing.sequence`没有`pad_sequences`属性。

huangapple go评论96阅读模式
英文:

python keras.preprocessing.sequence has no attribute pad_sequences

问题

from keras.preprocessing import sequence 的翻译是:

from keras.preprocessing import sequence

AttributeError: module 'keras.preprocessing.sequence' has no attribute 'pad_sequences' 的翻译是:

AttributeError: 模块 'keras.preprocessing.sequence' 没有 'pad_sequences' 属性

对于 "Why?" 和 "How can I edit this?" 这两个问题,我不会回答,因为你要求只翻译代码部分。

英文:

import:from keras.preprocessing import sequence

but:
AttributeError: module 'keras.preprocessing.sequence' has no attribute 'pad_sequences'

Why?

How can I edit this?

答案1

得分: 3

似乎您的Keras版本大于2.8,这就是为什么出现错误的原因。

用早期版本的代码:

from keras.preprocessing import sequence

替换为以下提供的代码:

from keras.utils.data_utils import pad_sequences

您还可以使用:

from tensorflow.keras.preprocessing.sequence import pad_sequences

它们都对我起作用。

英文:

Seems like your keras version is greater than 2.8 that's why getting error as

<code>from keras.preprocessing import sequence</code>

works for earlier version. Instead, replace with the below given code:

<code>from keras.utils.data_utils import pad_sequences</code>

You can also use:

<code>from tensorflow.keras.preprocessing.sequence import pad_sequences</code>

They both worked for me.

答案2

得分: 0

Just use keras_preprocessing instead keras.preprocessing:

from keras_preprocessing import sequence
英文:

Just use keras_preprocessing instead keras.preprocessing:

from keras_preprocessing import sequence

答案3

得分: 0

To resolve this issue, you can use the tf.keras version of pad_sequences directly from TensorFlow.

Just use:

import tensorflow as tf
英文:

To resolve this issue, you can use the tf.keras version of pad_sequences directly from TensorFlow.

Just use:

import tensorflow as tf

huangapple
  • 本文由 发表于 2023年3月23日 11:24:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75819004.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定