FastAI 关于使用 TextList 加载数据的问题
FastAI Question on data loading using TextList
我的最终目标是使用 FastAI 实现 ULMFit 来预测灾难推文(作为 this 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: 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)
为什么这个方法有效而不是以前的方法?
Notebook Link供参考。
你是哪个版本的 fastai 运行?
import fastai
print(fastai.__version__)
TextList class 来自 FastAI v1,但在我看来您的导入路径适用于 Fastai v2,而在 v2 中,TextList 已更改为 https://docs.fast.ai/text.data.html#TextBlock(这就是它与 Datablock 一起工作的原因部分至极是处理这个的好方法)
我的最终目标是使用 FastAI 实现 ULMFit 来预测灾难推文(作为 this 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: 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)
为什么这个方法有效而不是以前的方法?
Notebook Link供参考。
你是哪个版本的 fastai 运行?
import fastai
print(fastai.__version__)
TextList class 来自 FastAI v1,但在我看来您的导入路径适用于 Fastai v2,而在 v2 中,TextList 已更改为 https://docs.fast.ai/text.data.html#TextBlock(这就是它与 Datablock 一起工作的原因部分至极是处理这个的好方法)