简体   繁体   English

任何人都可以帮我找到错误“AttributeError:'Example' object has no attribute 'src_len'”的解决方案吗?

[英]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.

相关问题 'super' object 没有属性 '__getattr__',谁能帮帮我? - 'super' object has no attribute '__getattr__', can anyone help me? 你能帮我解决这个错误吗? AttributeError: 'numpy.ndarray' object 没有属性 'keys' - Can you help me in this error? AttributeError: 'numpy.ndarray' object has no attribute 'keys' 谁能解释这个错误? AttributeError:“列表”对象没有属性“编码” - Can anyone explain this error? AttributeError: 'list' object has no attribute 'encode' Python错误:AttributeError:&#39;NoneType&#39;对象没有属性&#39;len&#39; - Python error : AttributeError: 'NoneType' object has no attribute 'len' 有人可以帮我解决这个问题吗? 第一次尝试这个。 AttributeError:类型 object 'Post' 没有属性 'published' - Can someone help me fix this? first time trying this. AttributeError: type object 'Post' has no attribute 'published' 谁能解释这个错误[AttributeError:“ DataFrame”对象没有属性“ to_numeric”] - Can anyone explain this error [AttributeError: 'DataFrame' object has no attribute 'to_numeric'] 谁能告诉我为什么我收到错误 [AttributeError: 'list' object has no attribute 'encode'] - Can anyone tell my why I'm getting the error [AttributeError: 'list' object has no attribute 'encode'] 我在 /listings/5689-resot-relly-market 收到此错误 AttributeError,'Profile' object 没有属性 'favourite' 请提供任何帮助 - I get this Error AttributeError at /listings/5689-resot-relly-market, 'Profile' object has no attribute 'favourite' please any help would be apprciate 有人可以帮我使用以下示例的正则表达式吗? - Can anyone help me with the regex for the following example? 为什么它运行我这个错误:AttributeError:'str' object 没有属性'write'? - why is it running me this Error: AttributeError: 'str' object has no attribute 'write'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM