[英]Can Anyone please help me in finding the solution to the error "AttributeError: 'Example' object has no attribute 'src_len'"?
I am working on a project which aims to make transformer neural network for machine translation using pytorch.我正在做一个项目,该项目旨在使用 pytorch 制作用于机器翻译的变压器神经网络。 I am facing the error which says "AttributeError: 'Example' object has no attribute 'src_len'".. Any help would be appreciated.
我面临的错误是“AttributeError:'Example' object 没有属性'src_len'”。任何帮助将不胜感激。 Thank you
谢谢
fields = {"English": ("eng", english), "Urdu": ("ur", urdu)}
train_data, test_data,valid_data= TabularDataset.splits(
path="", train="train.json", test="test.json",validation="val.json", format="json", fields=fields
)
english.build_vocab(train_data, max_size=10000, min_freq=2)
urdu.build_vocab(train_data, max_size=10000, min_freq=2)
train_iterator, valid_iterator, test_iterator = BucketIterator.splits(
(train_data, valid_data, test_data),
batch_size=32,
sort_within_batch=True,
sort_key=lambda x: (x.src_len),
device='cuda',
)
for batch in train_iterator:
print(batch)
Error Message:错误信息:
AttributeError
Traceback (most recent call last)
<ipython-input-27-9fe6d4873776> in <module>()
----> 1 for batch in train_iterator:
2 print(batch)
2 frames
<ipython-input-26-1c01ecf39930> in <lambda>(x)
4 batch_size=32,
5 sort_within_batch=True,
----> 6 sort_key=lambda x: (x.src_len),
7 device='cuda',
8 )
AttributeError: 'Example' object has no attribute 'src_len'`
The object x
does not have any attribute called src_len
. object
x
没有任何名为src_len
的属性。 Please check if len(x)
works.请检查
len(x)
是否有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.