我的最终目标是使用FastAI实现ULMFit来预测灾难性推文(作为这个 Kaggle竞赛的一部分)。我试图从DataFrame中读取推文。但由于我不知道的原因,我卡在了数据加载阶段。我无法使用下面的方法做到这一点 –
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: 名称’TextList’未定义。
我能够通过下面的代码绕过这个问题 –
dls_lm = DataBlock( blocks=TextBlock.from_df('text', is_lm=True), get_x=ColReader('text'), splitter=RandomSplitter(0.1) # 使用整个评论数据的10%进行验证,以便学习更多)dls_lm = dls_lm.dataloaders(train, bs=64, seq_len=72)
为什么这种方法有效而前一种方法无效?
Notebook链接供参考。
回答:
您正在运行的FastAI版本是哪个?
import fastaiprint(fastai.__version__)
TextList类来自FastAI v1,但你的导入路径似乎是针对FastAI v2的,而在v2中,TextList已被https://docs.fast.ai/text.data.html#TextBlock替代(这就是为什么使用DataBlock部分有效,这是处理这种情况的正确方法)