FastAI NLP 迁移学习,迁移学习模型是否有预训练模型的词汇表?

时间:2021-07-01 23:15:27

标签: python nlp transfer-learning fast-ai

Lesson 8 video tutorial中,Jeremy 说我们可以使用预训练的 Wiki 模型来训练我们自己的模型。 我记得他说过迁移学习后你自己的语言模型不仅会有来自预先训练好的 Wiki 模型的语料库,还有来自你语言模型的词汇。

但是当我自己尝试时,我发现在我训练我的语言模型后,它不认识 likedmovie 单词,词汇表中只有 4400 个单词。

这是代码,

def get_questions(path):
    return words_df['text'].tolist()

word_path = 'words_oversampled.csv'
words_df = pd.read_csv(word_path)

dls_lm = DataBlock(
    blocks = TextBlock.from_df(words_df, is_lm=True),
    get_items=get_questions,
    splitter=RandomSplitter(0.2)
).dataloaders(word_path, bs=80)

# We get 4400 vocabulary
lm_vocab = dls_lm.vocab
len(lm_vocab), lm_vocab[-20:]

len(lm_vocab) 的输出是 4400。

在训练我的语言模型后,我尝试了下一个单词预测:

TEXT = "I liked this movie because"
N_WORDS = 40
N_SENTENCES = 2
preds = [lm_learner.predict(TEXT, N_WORDS, temperature=0.75) 
         for _ in range(N_SENTENCES)]
print("\n".join(preds))

输出如下:

i xxunk this xxunk because of covid wil covid man made how should medical centers respond to a covid patient what is the realistim wellness impact fi covid what happens when works Do get pay ca nt pay the covid
i xxunk this xxunk because of covid what is the best way to deal with stress during lockdown can antibiotics kill covid é covid a bio weapon why covid is worse than flu want are the descriptive statitics for the

从输出中可以看出,我的语言模式不知道单词:likedmovie。 我很确定在 Wiki 上训练的语言模型肯定会比 4400 个词多,并且 likedmovie 应该包含在训练模型的词汇表中。

那么,我错过了什么?

你可以用几乎任何数据集替换我的 csv 文件来试一试。

0 个答案:

没有答案