从数据帧创建数据加载器时发生FASTAI错误

2024-05-23 19:37:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图建立一个预测器,告诉我推特是否在谈论自然灾害

使用Kaggle数据集

我得到:

    text               target
15  What's up man?      0
16  I love fruits       0
17  Summer is lovely    0
18  My car is so fast   0

这个名单还有很多

我得到的目标,这个数字的外观

04342

13271

名称:target,数据类型:int64

这是我的数据锁

dls_lm = DataBlock(
blocks=(TextBlock.from_df('text', seq_len=15, is_lm=True), CategoryBlock),
get_x=ColReader('text'), get_y=ColReader('target'), splitter=ColSplitter())

这是我的数据加载器

dls = dls_lm.dataloaders(df2, bs=24)

这就是我犯的错误

KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2897             try:
-> 2898                 return self._engine.get_loc(casted_key)
   2899             except KeyError as err:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'is_valid'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
5 frames
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2898                 return self._engine.get_loc(casted_key)
   2899             except KeyError as err:
-> 2900                 raise KeyError(key) from err
   2901 
   2902         if tolerance is not None:

KeyError: 'is_valid'

如果有人知道我如何修复它,我会帮上大忙的。谢谢


Tags: 数据keytextinselftargetpandasget