machine-learning - FastAI 关于使用 TextList 加载数据的问题
问题描述
我的最终目标是使用 FastAI 实现 ULMFit 来预测灾难推文(作为Kaggle 竞赛的一部分)。我想做的是从数据框中读取推文。但由于我不知道的原因,我被困在数据加载阶段。我根本无法使用以下方法这样做 -
from fastai.text.all import *
train= pd.read_csv('../input/nlp-getting-started/train.csv')
dls_lm = (TextList.from_df(path,train,cols='text',is_lm=True)
.split_by_rand_pct(0.1)
#.label_for_lm()
.databunch(bs=64))
此行抛出 - NameError: name 'TextList' is not defined。
我可以使用以下代码解决此问题 -
dls_lm = DataBlock(
blocks=TextBlock.from_df('text', is_lm=True),
get_x=ColReader('text'),
splitter=RandomSplitter(0.1)
# using only 10% of entire comments data for validation inorder to learn more
)
dls_lm = dls_lm.dataloaders(train, bs=64, seq_len=72)
为什么这行得通,而不是以前的方法?
笔记本链接供参考。
解决方案
你运行的是哪个版本的 fastai?
import fastai
print(fastai.__version__)
TextList 类来自 FastAI v1,但在我看来,您的导入路径适用于 Fastai v2,而在 v2 中,TextList 使用https://docs.fast.ai/text.data.html#TextBlock更改(这就是它工作的原因使用 Datablock 部分是处理此问题的好方法)
推荐阅读
- datetime - 我的查询适用于时间戳,但日期时间出错
- html - div元素的CSS背景不起作用
- laravel - 如何在 Policy 中允许 nova 资源操作
- python - Python Panda - 将两列值连接成带有标签名称的单列
- java - 事务隔离级别 -1 不支持
- java - 有没有一种特定的方法可以给某个子类一些超类的功能?
- python - pandas groupby 滚动均值/中值删除缺失值
- annotations - 如何为多个场景/功能中的一个场景/功能定义之前的标签
- linux - bash:BASH_XTRACEFD:5:跟踪文件描述符的值无效
- python - 带有星图的多处理池未按预期工作