AttributeError: module ‘torchtext.data‘ has no attribute ‘Field‘/AttributeError: module ‘torchtext.d
Data No module has attribute Field AttributeError
2023-09-11 14:14:27 时间
Asked 5 months ago
Active 1 month ago
Viewed 10k times
13
1
I want to run a git project used pytorch and torchtext but when I run it, it raise error:
File "main.py", line 60, in <module>
main()
File "main.py", line 50, in main
train_iters, dev_iters, test_iters, vocab = load_dataset(config)
File "/home/esmailza/style transfer/style-transformer/data.py", line 23, in load_dataset
TEXT = data.Field(batch_first=True, eos_token='<eos>')
AttributeError: module 'torchtext.data' has no attribute 'Field'
torch version = 1.8.0 torchtext version = 0.9
def load_dataset(config, train_pos='train.pos', train_neg='train.neg',
dev_pos='dev.pos', dev_neg='dev.neg',
test_pos='test.pos', test_neg='test.neg'):
root = config.data_path
TEXT = data.Field(batch_first=True, eos_token='<eos>')
dataset_fn = lambda name: data.TabularDataset(
path=root + name,
format='tsv',
fields=[('text', TEXT)]
)
python
pytorch
Share
Improve this question
Follow
edited Mar 7 at 12:27
asked Mar 7 at 12:12
abbas hoseini
30322 silver badges1111 bronze badges
Is this an issue in BucketIterator? – OctopuSS7 Mar 7 at 12:18
@OctopuSS7 yes, actually the error raise when he defines Field, but the field is gonna used in BucketIterator. – abbas hoseini Mar 7 at 12:26
Add a comment
2 Answers
31
From TorchText 0.9.0 Release Notes
torchtext.data.Field -> torchtext.legacy.data.Field
This means, all features are still available, but within torchtext.legacy instead of torchtext.
torchtext.data.Field has been moved to torchtext.legacy.data.Field
And the imports would change this way:
from torchtext.legacy import data
Share
Improve this answer
Follow
answered Mar 7 at 15:08
Rishabh Kumar
2,11633 gold badges99 silver badges2121 bronze badges
1
It works. Thanks ! – user1412066 Mar 27 at 9:05
Add a comment
0
Thanks, @Rishabh Kumar answer as well, this works for me!
From TorchText 0.9.0 Release Notes
Based on v0.9 release https://github.com/pytorch/text/releases/tag/v0.9.0-rc5
The current users of the legacy code will experience BC breakage as we have retired the legacy code (#1172, #1181, #1183). The legacy components are placed in torchtext.legacy.data folder as follows:
torchtext.data.Pipeline -> torchtext.legacy.data.Pipeline
torchtext.data.Batch -> torchtext.legacy.data.Batch
torchtext.data.Example -> torchtext.legacy.data.Example
torchtext.data.Field -> torchtext.legacy.data.Field
torchtext.data.Iterator -> torchtext.legacy.data.Iterator
torchtext.data.Dataset -> torchtext.legacy.data.Dataset
This means, all features are still available, but within torchtext.legacy instead of torchtext.
相关文章
- Link static data in sql source control
- 报错:MySQL initialize specified but the data directory has files in it. Aborting.
- Mining of Massive Datasets – Data Mining
- 报错:此版本的SQL Server Data Tools与此计算机中安装的数据库运行时组件不兼容
- 报错:无法将类型"System.Data.EntityState"隐式转换为"System.Data.Entity.EntityState"
- zipimport.ZipImportError: can‘t decompress data; zlib not available make: *** [install] 错误 1
- XAML数据绑定(Data Binding)
- Maven发布封装到中央仓库时候报错:no default secret key: No secret key
- 《Spring Data实战》——第2章 Repository:便利的数据访问层 2.1快速入门
- This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 错误解决办法
- 《Core Data应用开发实践指南》一2.8 创建NSManagedObject的子类
- 《Core Data应用开发实践指南》一2.13 获取托管对象
- 浅析SpringBoot使用@RequestBody搭配@Data的注意点
- CYQ.Data 数据框架系列索引
- 雅虎用生命诠释了什么叫“NO作No die”
- [Oracle工程师手记] 说说什么是 Active Data Guard
- 前端性能优化:使用Data URI代替图片SRC