blu*_*sky 6 nlp markov trigram
鉴于:
以下内容:
用于:
q(runs | the, dog) = 0.5
Run Code Online (Sandbox Code Playgroud)
这不应该1是
q(runs | the, dog):xi = run,xi-2 = the,xi-1 = dog
概率是(wi已被替换为xi):
因此:
count(the dog runs) / count(the dog) = 1 / 1 = 1
Run Code Online (Sandbox Code Playgroud)
但在上面的例子中,该值为0.5.0.5如何到达?
基于http://files.asimihsan.com/courses/nlp-coursera-2013/notes/nlp.html#markov-processes-part-1
0.5这个数字根本就没有“到达”;作者只是为了说明的目的而随意取了一个数字。
任何 n-gram 语言模型都包含两部分:词汇和转换概率。并且模型“不关心”这些概率是如何得出的。唯一的要求是概率是自洽的(即对于任何前缀,所有可能的连续的概率之和为 1)。对于上面的模型,这是正确的:例如p(runs|the, dog) + p(STOP|the,dog)=1。
当然,在实际应用中,我们确实感兴趣如何从一些文本语料库中“学习”模型参数。您可以计算出您的特定语言模型可以生成以下文本:
the # with 0.5 probability
the dog # with 0.25 probability
the dog runs # with 0.25 probability
Run Code Online (Sandbox Code Playgroud)
根据这一观察,我们可以对训练语料库进行“逆向工程”:它可能由 4 个句子组成:
the
the
the dog
the dog runs
Run Code Online (Sandbox Code Playgroud)
如果您计算该语料库中的所有三元组并对计数进行标准化,您会发现生成的相对频率等于屏幕截图中的概率。特别是,有1个句子以“thedog”结尾,1个句子中“thedog”后面跟着“runs”。这就是概率 0.5 ( =1/(1+1)) 的产生方式。