【发布时间】:2020-04-18 15:03:21
【问题描述】:
我的代码是:
for ep in range(10):
for x, y in tqdm(train_iterator.gen_batches(batch_size=64,
data_type="train")):
x_embed = embedder(tokenizer(str_lower(x)))
y_onehot = onehotter(classes_vocab(y))
cls.train_on_batch(x_embed, y_onehot)
结果:
<ipython-input-30-3f8c38399ce9> in <module>()
2 for x, y in tqdm(train_iterator.gen_batches(batch_size=64,
3 data_type="train")):
----> 4 x_embed = embedder(tokenizer(str_lower(x)))
5 y_onehot = onehotter(classes_vocab(y))
6 cls.train_on_batch(x_embed, y_onehot)
1 frames
/usr/local/lib/python3.6/dist-packages/deeppavlov/models/preprocessors/str_lower.py in str_lower(batch)
31 return batch.lower()
32 else:
---> 33 return list(map(str_lower, batch))
TypeError: 'float' object is not iterable
我尝试将其更改为 ep = int [float] 但这也不起作用。
【问题讨论】:
-
You
x属于float类型,但它应该是string或 python 中存在的其他可迭代类型,例如 list 或 tuple ,我可以从给定的信息中理解。跨度> -
感谢您对我的帖子进行评论。但是如何通过我的代码将 x 转换为字符串?
-
您期望通过迭代
tqdm(...)产生的x和y是什么?我们对您的数据或数据生成器一无所知。为什么x是一个数字,而其余代码需要一个字符串或字符串列表?不要盲目地在代码中添加补丁 - 专注于理解,而不是补丁。
标签: python for-loop floating-point iterable