python - "module 'torchtext.data' has no attribute 'Field'"
问题描述
import torchtext
ENGLISH = torchtext.data.Field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")
Error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-12-2a3d11c77e7d> in <module>
----> 1 ENGLISH = torchtext.data.Field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")
AttributeError: module 'torchtext.data' has no attribute 'Field'
It won't import torchtext.data.Field for some reason even though that's whats in the docs
解决方案
[BC Breaking] Legacy 在 v0.9.0 版本中,我们将以下遗留代码移至 torchtext.legacy。这是改造 torchtext 库工作的一部分,其动机已在问题 #664 中讨论:
torchtext.legacy.data.field
torchtext.legacy.data.batch
torchtext.legacy.data.example
torchtext.legacy.data.iterator
torchtext.legacy.data.pipeline
torchtext.legacy.datasets
我们有一个迁移教程来帮助用户在 v0.9.0 版本中切换到 torchtext 数据集。对于仍然需要旧版组件的用户,他们可以将旧版添加到导入路径中。
试试看ENGLISH = torchtext.legacy.data.field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")
推荐阅读
- javascript - Advanced Angular @HostListener - 记录父组件中所有元素的点击(来自子组件)
- r - 将正确的 id 映射到 shp 文件坐标中的唯一标识符
- sql - 关于聚合函数的问题
- regex - 如何在 NiFi 中为内容处理器上的路由指定正则表达式?
- python - Sys.executable 错误 - ModuleNotFound 错误
- linux - 尝试在一行中将 cron 作业添加为 sudo 时出现“意外标记 `crontab' 附近的语法错误”
- database - 如何在 Express 中创建多对多关系?
- javascript - 分配默认道具时,状态不会通过 redux 更改
- arrays - 多选下拉列表和表单字段显示为数组?
- html - 在图像尺寸上使用 rem、em 和 px