Nlp 如何定义多类文本数据集(fastai)的日志计数比率?

Nlp 如何定义多类文本数据集(fastai)的日志计数比率?,nlp,text-classification,naivebayes,fast-ai,Nlp,Text Classification,Naivebayes,Fast Ai,我试着用天真的Bayes跟随Rachel Thomas的情感分类路径。在视频中,她使用了一个二进制数据集(pos.和neg.电影评论)。在应用朴素贝叶斯时: 定义:每个单词f的日志计数比率r: r = log (ratio of feature f in positive documents) / (ratio of feature f in negative documents) 其中,正面文档中特征$f$的比率是正面文档具有特征的次数除以正面文档的数量 p1 = np.squeeze(np

我试着用天真的Bayes跟随Rachel Thomas的情感分类路径。在视频中,她使用了一个二进制数据集(pos.和neg.电影评论)。在应用朴素贝叶斯时:

定义:每个单词f的日志计数比率r:

r = log (ratio of feature f in positive documents) / (ratio of feature f in negative documents)
其中,正面文档中特征$f$的比率是正面文档具有特征的次数除以正面文档的数量

p1 = np.squeeze(np.asarray(x[y.items==positive].sum(0)))
p0 = np.squeeze(np.asarray(x[y.items==negative].sum(0)))

pr1 = (p1+1) / ((y.items==positive).sum() + 1)
pr0 = (p0+1) / ((y.items==negative).sum() + 1)

r = np.log(pr1/pr0)
-->将日志计数比率应用于具有2个标签的数据集非常简单

问题: 我的数据集不是二进制的!假设我有5个标签:标签1,…,标签5

如何获取多标签数据集的日志计数比率r

我的方法:

p4 = np.squeeze(np.asarray(x[y.items==label_5].sum(0)))
p3 = np.squeeze(np.asarray(x[y.items==label_4].sum(0)))
p2 = np.squeeze(np.asarray(x[y.items==label_3].sum(0)))
p1 = np.squeeze(np.asarray(x[y.items==label_2].sum(0)))
p0 = np.squeeze(np.asarray(x[y.items==label_1].sum(0)))

log-count-ratio:
pr1 = (p1+1) / ((y.items==label_2).sum() + 1)
pr1_not = (p1+1) / ((y.items!=label_2).sum() + 1)
r_1 = np.log(pr1/pr1_not)

log-count-ratio:
pr2 = (p2+1) / ((y.items==label_3).sum() + 1)
pr2_not = (p2+1) / ((y.items!=label_3).sum() + 1)
r_2 = np.log(pr2/pr2_not)
...

这是正确的吗?这是否意味着我得到了多个比率?

来自 ,对数计数比由后验概率比推导而来,后验概率比有助于比较两个类别,以了解哪个类别最有可能。我猜你们是在尝试用一对一的方法来解决多类问题。这将以5x4/2=10对分类比率结束。如果您只想进行分类,我们通常会计算每个类别的后验概率,并选择最好的。所以在您的例子中,您只需从sum(log(p1))、sum(log(p2))、…、sum(log(p5))中选择最好的