Perplexity定义

article/2025/9/24 13:19:57

Refer from http://blog.csdn.net/pipisorry/article/details/42460023

http://blog.csdn.net/pipisorry/article/details/42460023

熵/信息熵



Perplexity定义

perplexity是一种信息理论的测量方法,b的perplexity值定义为基于b的熵的能量(b可以是一个概率分布,或者概率模型),通常用于概率模型的比较

wiki上列举了三种perplexity的计算:

1 概率分布的perplexity

公式:  20130718161536515

其中H(p)就是该概率分布的熵。当概率P的K平均分布的时候,带入上式可以得到P的perplexity值=K。

2 概率模型的perplexity

公式: 20130718161551531

公式中的Xi为测试局,可以是句子或者文本,N是测试集的大小(用来归一化),对于未知分布q,perplexity的值越小,说明模型越好。

A model of an unknown probability distribution p, may be proposed based on a training sample that was drawn fromp. Given a proposed probability modelq, one may evaluateq by asking how well it predicts a separate test samplex1,x2, ...,xN also drawn fromp. The perplexity of the modelq is defined as

b^{- \frac{1}{N} \sum_{i=1}^N \log_b q(x_i)}

where b is customarily 2. Better modelsq of the unknown distributionp will tend to assign higher probabilitiesq(xi) to the test events. Thus, they have lower perplexity: they are less surprised by the test sample.

The exponent above may be regarded as the average number of bits needed to represent a test eventxi if one uses an optimal code based onq. Low-perplexity models do a better job of compressing the test sample, requiring few bits per test element on average becauseq(xi) tends to be high.

指数部分 也可以用交叉熵来计算。
H(\tilde{p},q) = -\sum_x \tilde{p}(x) \log_2 q(x)
where  \tilde{p}  denotes the empirical distribution of the test sample (i.e., \tilde{p}(x) = n/N  if x  appeared  n  times in the test sample of size  N )

3单词的perplexity

perplexity经常用于语言模型的评估,物理意义是单词的编码大小。例如,如果在某个测试语句上,语言模型的perplexity值为2^190,说明该句子的编码需要190bits

[http://en.wikipedia.org/wiki/Perplexity]

皮皮blog



评估LDA主题模型-perflexity

LDA主题模型好坏的评估,判断改进的参数或者算法的建模能力。

perplexity is only a crude measure, it's helpful (when using LDA) to get 'close' to the appropriate number of topics in a corpus. 

Blei先生在论文《Latent Dirichlet Allocation》实验中用的是Perplexity值作为评判标准,并在论文里只列出了perplexity的计算公式。


Note:M代表测试语料集的文本数量,Nd代表第d篇文本的大小(即单词的个数),P(Wd)代表文本的概率

文本的概率的计算:


p(z)表示的是文本d在该主题z上的分布,应该是p(z|d)

Note

1. Blei是从每篇文本的角度来计算perplexity的,而上面是从单词的角度计算perplexity。

2. 测试文本集中有M篇文本,对词袋模型里的任意一个单词w,P(w)=∑z p(z|d)*p(w|z),即该词在所有主题分布值和该词所在文本的主题分布乘积。

3. 模型的perplexity就是exp^{ - (∑log(p(w))) / (N) },∑log(p(w))是对所有单词取log(直接相乘一般都转化成指数和对数的计算形式),N的测试集的单词数量(不排重)

4. P(w)=∑z p(z|d)*p(w|z)这个w是测试集上的词汇

[http://blog.csdn.net/pipisorry/article/details/42460023]

[http://faculty.cs.byu.edu/~ringger/CS601R/papers/Heinrich-GibbsLDA.pdf - 29页]


Estimate the perplexity within gensim

The `LdaModel.bound()` method computes a lower bound on perplexity, based on a supplied corpus (~of held-out documents).
This is the method used in Hoffman&Blei&Bach in their "Online Learning for LDA" NIPS article.

[https://groups.google.com/forum/#!topic/gensim/LM619SB57zM]

you can also use model.log_perplexity(heldout), which is a convenience wrapper.

皮皮blog


评价一个语言模型Evaluating Language

假设我们有一些测试数据,test data.测试数据中有m个句子;s1,s2,s3…,sm

我们可以查看在某个模型下面的概率:image

我们也知道,如果计算相乘是非常麻烦的,可以在此基础上,以另一种形式来计算模型的好坏程度。

在相乘的基础上,运用Log,来把乘法转换成加法来计算。

image

 

补充一下,在这里的p(Si)其实就等于我们前面所介绍的q(the|*,*)*q(dog|*,the)*q(…)…

有了上面的式子,评价一个模型是否好坏的原理在于:

a good model should assign as high probability as possible to these test data sentences.

image,this value as being a measure of how well the alleviate to make sth less painful or difficult to deal with language model predict these test data sentences.

The higher the better.

上面的意思也就是说,如果image的值越大,那么这个模型就越好。

  • 实际上,普遍的评价的指标是perplexity

image

其中,M的值是测试数据test data中的所有的数量。

那么从公式当中查看,可以知道。perplexity的值越小越好。

为了更好的理解perplexity,看下面这个例子:

  • 我们现在有一个单词集V,N=|V|+1

image

有了上面的条件,可以很容易的计算出:

image

Perplexity是测试branching factor的数值。

branching factor又是什么呢?有的翻译为分叉率。如果branching factor高,计算起来代价会越大。也可以理解成,分叉率越高,可能性就越多,需要计算的量就越大。

上面的例子q=1/N只是一个举例,再看看下面这些真实的数据:

  • Goodman的结果,其中|V|=50000,在trigram model的image中,Perplexity=74
  • 在bigram model中,image,Perplexity=137
  • 在unigram model中,image,perplexity=955

在这里也看到了,几个模型的perplexity的值是不同的,这也就表明了三元模型一般是性能良好的。

[评价一个语言模型Evaluating Language Models:Perplexity]

皮皮blog



Questions find in :

the mailing list of gensim


from:http://blog.csdn.net/pipisorry/article/details/42460023

ref:Topic models evaluation in Gensim

http://stackoverflow.com/questions/19615951/topic-models-evaluation-in-gensim

http://www.52ml.net/14623.html

Ngram model and perplexity in NLTK

http://www.researchgate.net/publication/221484800_Improving_language_model_perplexity_and_recognition_accuracy_for_medical_dictations_via_within-domain_interpolation_with_literal_and_semi-literal_corpora

Investigating the relationship between language model perplexity and IR precision-recall measures.

LDA/NMF/LSA多模型/多主题一致性评价方法《Exploring topic coherence over many models and many topics》K Stevens, P Kegelmeyer, D Andrzejewski... [University of California Los Angeles] (2012)  GITHUB

论文:(概率)生成模型评价方法研究《A note on the evaluation of generative models》Lucas Theis, Aäron van den Oord, Matthias Bethge (2015) 

Notes on A note on the evaluation of generative models by Hugo Larochelle 



http://chatgpt.dhexx.cn/article/Ig9ix8ry.shtml

相关文章

gensim---LDA---perplexity

以下内容来源于https://blog.csdn.net/qq_25073545/article/details/79773807 使用gensim实现lda,并计算perplexity( gensim Perplexity Estimates in LDA Model) Neither. The values coming out of bound() depend on the number of topi…

世界上第一个会话搜索引擎——Perplexity AI使用测评

引言 比起传统的列表式搜索,Perplexity AI把艳惊四座的ChatGPT和必应搜索结合起来,既有ChatGPT式的问答,又像普通搜索引擎那样列出链接,就连马斯克也亲自称赞:它不仅总结出了推文的由来,还将推文的内容解释…

主题模型TopicModel:LDA主题模型的评估

http://blog.csdn.net/pipisorry/article/details/42460023 基础知识:熵 [熵与互信息] 皮皮blog Perplexity定义 perplexity是一种信息理论的测量方法,b的perplexity值定义为基于b的熵的能量(b可以是一个概率分布,或者概率模型…

语言模型常用评价方法:perplexity、bleu

目录 1. perplexity(困惑度、复杂度) 2. BLEU 代码实现 1. perplexity(困惑度、复杂度) 更多详细,参考:详解语言模型NGram及困惑度Perplexity 语言模型:语言模型可以表示为一个计算 的模型&a…

LDA主题模型绘制困惑度(perplexity)-主题数曲线——python

主题建模作为一种基于机器学习的文本内容分析技术,一般用于推断文本文档中隐藏主题的技术。很多研究使用了基于Latent Dirichlet Allocation (LDA)的主题建模算法来处理大规模文档并识别潜在主题。LDA主题模型已经在多个研究领域得到应用,且都有着不俗表…

Android keystore

1.keystore是一个密钥库,密钥库中可以放很多对密钥对(私钥证书(证书中包含公钥,数字签名,证书有效期,组织机构名称,申请时间,算法等。))kestore中有两种密码,一个密码是访问密钥库的…

查看KeyStore的信息,(本地的和线上的)

本地的: 1.找到jdk路径、如图 输入cmd 2.输入:keytool -list -v -keystore C:\Users\j\Desktop\app-android-v1.6-1caec749d84e708f91fd90ab383e42d7b417a47e\你的名.keystore 注意:C:\Users\j\Desktop\app-android-v1.6-1caec749d84e708f9…

Keystore与Truststore的区别

Keystore vs Truststore 概念 Keystore 用于存储特定程序应提供给双方(服务器或客户端)以进行验证的私钥和身份证书。 Truststore 用于存储来自认证机构 (CA) 的证书,这些证书验证服务器在 SSL 连接中提供的证书。 区别 KeystoreTruststo…

Keystore、Key attestation

最近看见了Keystore这个名词不知道什么意思,百度找到了前辈的优秀文章,这里copy学习一下,原文链接放在文末,感谢前辈。 Keystore的技术演进之路 Android提供的keystore功能发展历程伴随着Android版本不断演进。 从 Android 6.0 …

Android KeyStore流程

文章目录 一、Keystore二、Keystore架构及接口函数1. Keystore组件架构2. IKeymasterDevice.hal中的几个重要接口函数2.1 begin函数2.2 update函数2.3 finish函数2.4 abort函数 3. Keymaster TA4. 对称密码函数API 三、从Keystore到Keymaster的完整分析1. cts问题2. 代码流程分…

AndroidStudio生成keystore

相信大家都慢吞吞的切换将开发工具迁移到了AS,今天,奉上生成keystore的方法。 看图: 点击我选中的Generate Signed APK,翻译过来大致是,生成已签署的APK,我们点击这一项 如果还没有生成keystore&#xff…

keytool生成keystore、truststore、证书

keytool生成keystore、truststore、证书 1. 打开cmd命令行,进入文件夹(如:D:\test_icessl_key)。keytool会把接下来生成的所有文件都保存到此处。 2. 输入:keytool -genkeypair -alias icesslkey -keyalg RSA -validi…

Android Studio 默认keystore 以及自定义keystore

我们使用Android Studio 运行或测试我们的app 它使用一个默认的debug.keystore进行签名。 这个默认签名(keystore)是不需要密码的,它的默认位置在 $HOME/.android/debug.keystore,如果不存在Android studio会自动创建它。 例如我的debug.keystore就在…

SSL证书中的keystore是什么

什么是keystore 是java的密钥库、用来进行通信加密用的、比如数字签名。keystore就是用来保存密钥对的,比如公钥和私钥。 在keystore里,包含两种数据: 密钥实体(Key entity)——密钥(secret key&#xff0…

Keystore密钥库

近来由于项目需要做Single Sign On, 研究了一下CAS(具体配置等下篇再介绍), 而这个CAS的配置最关键的不是CAS本身,而是数字证书,如何配置多台服务器之间的信任链接。因此,有必要把keystore, keytool的东西翻出来晒晒。…

KeyStore秘钥库

keytool 在打包Android APK的时候进行签名需要选择一个keystore,查看秘钥库: C:\Users\47355\.android>keytool -list -v -keystore debug.keystore 输入密钥库口令: 密钥库类型: PKCS12 密钥库提供方: SUN 您的密钥库包含 1 个条目 别名: androidd…

keystore 介绍

随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666) Keytool 是一个有效的安全钥匙和证书的管理工具. Java 中的 keytool.exe (位于 JDK\Bin 目录下)可以用来创建数字证书,所有的…

安卓生成keystore和查看keystore

————————————————重要通知—————————————— Hello,本人的博客文章已更新至个人网站(www.jonexu.cn) 文章中有问题可以到网站联系博主,后续新的文章也将更新在个人网站 —————————————…

Python Tkinter库的简单使用

今天写了两个小小的图像界面小游戏,对Tkinter库进行了简单的熟悉。 1.随机造句小游戏: import Tkinter as tk import random window tk.Tk()def randomNoun():nouns ["cats", "hippos", "cakes"]noun random.choice…

《tkinter实用教程二》tkinter的子模块ttk

更多《Tkinter 实用教程》系列文章 tkinter 的子模块 ttk 本文主要介绍 tkinter 子模块的特性,以及和原生 tkinter 控件之间的区别。 tkinter.ttk 模块提供了对 tk 风格控件集合的访问途径,在 tkinter 8.5 中引入。 引入 tkinter.ttk 的基本思想是尽…