如何计算文本分类中的困惑度?

How to compute the perplexity in text classification?

我正在使用 scikit learn、朴素贝叶斯和 countvectorizer 进行方言文本分类。到目前为止,我只对 3 种方言进行文本分类。我将添加一种新的方言(或者实际上,这些方言的正式语言)。问题是,我要添加的新文本与其他 3 种方言共享很多词。所以我在研究文档中阅读了以下内容:

We train an n-gram model for each dialect from the collected data. To train the MSA model, we select sentences from Arabic UN corpus and news collections. All the dialect and MSA models share the same vocabulary, thus perplexity can be compared properly. At classification time, given an input sentence, the classifier computes the perplexity for each dialect type and choose the one with minimum perplexity as the label.

他们的意思是 MSA(现代标准阿拉伯语),它是这些方言的正式语言。他们如何计算困惑度?他们只是在使用朴素贝叶斯还是还有更多?

据我所见,引用的作品根本没有使用朴素贝叶斯分类器;该方法与您的建议不同。

提议的方法是为 每个 方言训练基于个体 n-gram 的语言模型进行分类。为了对给定输入属于哪种方言进行分类,使用每种语言模型对输入文本进行评分。根据 LM,困惑度越低,概率越高。因此,如果在方言 A 上训练的 LM 比方言 B 为输入分配更低的困惑度(即更高的概率),则输入文本更有可能是方言 A.

Perplexity is the inverse probability of some text normalized by the number of words (source).

对于一句话W,
Perplexity(W) = P(W)^(-1/N),其中 N 是句子中的单词数,P(W) 是根据 LM 得到 W 的概率。

因此,根据每个语言模型计算输入的概率和困惑度,并将这些进行比较以选择最可能的方言。