python - 属性错误: module 'keras.preprocessing' has no attribute 'text'

标签 python keras

当我尝试在 Keras 中导入 Tokenizer() 函数时,出现以下错误。

我正在关注 Keras 官方文档 https://keras.io/preprocessing/text/#tokenizer

import keras
tokenizer = keras.preprocessing.text.Tokenizer()

出现这样的错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'keras.preprocessing' has no attribute 'text'

使用 Keras 版本“2.1.3”

我哪里做错了?

最佳答案

你想要

from keras.preprocessing import text
tokenizer = text.Tokenizer(...) 

原因是 keras/preprocessing/__init__.py 没有导入或公开 text 子模块

关于python - 属性错误: module 'keras.preprocessing' has no attribute 'text' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48561909/

相关文章:

python - 全局名称 'RequestContext' 未定义

python - 如何将具有自定义 keras 层(.h5)的 keras 模型卡住为 tensorflow 图(.pb)?

python - 如何在keras中为给定数据点指定多个标签?

neural-network - Keras - 层的线性堆栈?

python - 通过循环 train_test_split 和不循环训练来训练模型

python - 正则表达式:如何使用正则表达式在可选捕获组之后捕获组?

python - 为什么 functools.partial 不返回一个真正的函数(以及如何创建一个真正的函数)?

python - numpy 数组与 nan 与标量的不等式比较

python - 用python计算纬度和经度之间的距离?

python - tensorflow Triplet_semihard_loss 在多个纪元后不会改变