我正在读这本书(NLTK),它令人困惑。熵的定义为:
熵是每个标签的概率之和 乘以相同标签的log概率
我如何在文本挖掘方面应用熵和最大熵?有人能给我举个简单的例子吗?
我正在读这本书(NLTK),它令人困惑。熵的定义为:
熵是每个标签的概率之和 乘以相同标签的log概率
我如何在文本挖掘方面应用熵和最大熵?有人能给我举个简单的例子吗?
当前回答
我真的建议你读一下信息理论,贝叶斯方法和MaxEnt。我们可以从大卫·麦凯(David Mackay)的这本书(网上免费下载)开始:
http://www.inference.phy.cam.ac.uk/mackay/itila/
这些推理方法真的比文本挖掘更通用,如果不学习这本书或其他关于机器学习和MaxEnt贝叶斯方法的介绍性书籍中的一些基本知识,我真的无法设计如何将其应用到NLP中。
The connection between entropy and probability theory to information processing and storing is really, really deep. To give a taste of it, there's a theorem due to Shannon that states that the maximum amount of information you can pass without error through a noisy communication channel is equal to the entropy of the noise process. There's also a theorem that connects how much you can compress a piece of data to occupy the minimum possible memory in your computer to the entropy of the process that generated the data.
我不认为你真的有必要去学习所有这些关于通信理论的定理,但如果不学习什么是熵,它是如何计算的,它与信息和推理的关系等基本知识,就不可能学习这些……
其他回答
首先,最好了解信息的度量方法。
我们如何衡量这些信息?
当一件不太可能发生的事情发生时,我们说这是一个大新闻。此外,当我们说一些可预测的事情时,它真的不有趣。为了量化这个有趣的东西,函数应该满足
如果事件的概率为1(可预测),则函数给出0 如果事件的概率接近于0,则函数应给出较高的数值 如果概率为0.5的事件发生,则给出1比特的信息。
满足约束条件的一个自然度量是
I(X) = -log_2(p)
其中p是事件x的概率,单位是位,与计算机使用的位相同。0或者1。
示例1
公平抛硬币:
从一次抛硬币中我们能得到多少信息?
答案:-log(p) = -log(1/2) = 1(位)
示例2
如果明天有一颗流星撞击地球,p=2^{-22},那么我们可以得到22位的信息。
如果太阳明天升起,p ~ 1,那么它是0位信息。
熵
所以如果我们对事件Y的有趣性取期望,那么它就是熵。 也就是说,熵是一个事件有趣度的期望值。
H(Y) = E[ I(Y)]
更正式地说,熵是一个事件的预期比特数。
例子
Y = 1:事件X发生的概率为p
Y = 0:事件X发生的概率为1-p
H(Y) = E[I(Y)] = p I(Y==1) + (1-p) I(Y==0)
= - p log p - (1-p) log (1-p)
以2为底的对数。
我真的建议你读一下信息理论,贝叶斯方法和MaxEnt。我们可以从大卫·麦凯(David Mackay)的这本书(网上免费下载)开始:
http://www.inference.phy.cam.ac.uk/mackay/itila/
这些推理方法真的比文本挖掘更通用,如果不学习这本书或其他关于机器学习和MaxEnt贝叶斯方法的介绍性书籍中的一些基本知识,我真的无法设计如何将其应用到NLP中。
The connection between entropy and probability theory to information processing and storing is really, really deep. To give a taste of it, there's a theorem due to Shannon that states that the maximum amount of information you can pass without error through a noisy communication channel is equal to the entropy of the noise process. There's also a theorem that connects how much you can compress a piece of data to occupy the minimum possible memory in your computer to the entropy of the process that generated the data.
我不认为你真的有必要去学习所有这些关于通信理论的定理,但如果不学习什么是熵,它是如何计算的,它与信息和推理的关系等基本知识,就不可能学习这些……
当我在实现一个算法来计算图像的熵时,我发现了这些链接,看这里和这里。
这是我使用的伪代码,你需要调整它来处理文本而不是图像,但原则应该是相同的。
//Loop over image array elements and count occurrences of each possible
//pixel to pixel difference value. Store these values in prob_array
for j = 0, ysize-1 do $
for i = 0, xsize-2 do begin
diff = array(i+1,j) - array(i,j)
if diff lt (array_size+1)/2 and diff gt -(array_size+1)/2 then begin
prob_array(diff+(array_size-1)/2) = prob_array(diff+(array_size-1)/2) + 1
endif
endfor
//Convert values in prob_array to probabilities and compute entropy
n = total(prob_array)
entrop = 0
for i = 0, array_size-1 do begin
prob_array(i) = prob_array(i)/n
//Base 2 log of x is Ln(x)/Ln(2). Take Ln of array element
//here and divide final sum by Ln(2)
if prob_array(i) ne 0 then begin
entrop = entrop - prob_array(i)*alog(prob_array(i))
endif
endfor
entrop = entrop/alog(2)
我从某处得到了这个代码,但我找不到链接。
非正式的
熵是信息或知识的可用性,信息的缺乏会导致预测未来的困难,这是高熵(文本挖掘中的下一个词预测),信息/知识的可用性将帮助我们更现实地预测未来(低熵)。
任何类型的相关信息都会减少熵,帮助我们预测更现实的未来,这些信息可以是句子中有“肉”这个词,也可以是句子中没有“肉”这个词。这就是所谓的信息获取
正式
熵是缺乏可预测性的顺序
当你在读一本关于NLTK的书时,你会很有趣地读到MaxEnt分类器模块http://www.nltk.org/api/nltk.classify.html#module-nltk.classify.maxent
对于文本挖掘分类,步骤可以是:预处理(标记化,蒸,信息增益的特征选择……),转换为数字(频率或TF-IDF)(我认为这是理解使用文本作为只接受数字的算法的输入时的关键步骤),然后使用MaxEnt进行分类,当然这只是一个例子。