NLP

基于字/词的 NLP 技术

TF-IDF & BM25

TF-IDF

计算公式为:

BM25

具体计算相似度的方法为:

修正项(非必须,且不同 BM25 算法对此项的处理略有不同)

完整公式

评估指标

BLEU

预训练模型

Tokenizer

BPE 算法

动机

对于英文来说,词的数量可能太多。同一个词根,可以通过修改前/后缀的方式来得到动词形式,名词形式,副词形式,例如如下词表:

own、owner、play、player、research、researcher、care、careful、hope、hopeful。

使用词作为 embeding 的最小单位,需要 10 个向量。但如果拆解为:

own、play、research、care、hope、er、ful。

那么仅需要 7 个向量,且这些词根和前/后缀有着某种含义。因此 embeding 的对象为这些 word piece,似乎比较合理。这带来一个问题,上面的拆解过程是人工找的规律(需要语言学的专业知识),因此需要用一个算法来自动发现这些 word piece。BPE 算法就是一种自动发现 word piece 的算法

具体算法流程参考博客:Byte Pair Encoding

NLP 小工具(常用正则、文本预处理工具等)

英文正则化(上撇号缩写等)

import contractions
contractions.fix("I'm")  # "I am"

Draft

Causal Language Modeling (CausalLM, LM)

即普通的语言模型: 根据已经见到的内容预测下一个 token

参考博客: https://www.projectpro.io/recipes/what-is-causal-language-modeling-transformers

The task of predicting the token after a sequence of tokens is known as causal language modeling. In this case, the model is just concerned with the left context (tokens on the left of the mask).

Last updated