PCFG中inside和outside算法详解

简介: inside-outside算法是用来预测一棵句法分析树的概率的算法,算法建立在文法是乔姆斯基范式(CFG)的基础之上,CFG的定义见维基百科。一棵句法分析树的potential定义为它包含的产生式的potential乘积,在PCFG中表示概率,在CRF-CFG中表示特征集合的分数。

inside-outside算法需要定义两个变量:

  • image.png 定义为内部的potential之和,即以 A 为根结点,短语为 image.png 的所有可能的子树的potential之和。
  • image.png 定义为外部的potential之和,即以 A 为根结点,短语为 image.png 的所有可能的子结构的potential之和。

给定文法CFG,输入字符串image.png,计算inside和outside值。

inside


初始化:

如果  image.png,那么 image.png 。否则就等于0。

其中 image.png 为potential值。

类似于CKY算法,自底向上计算inside值:


outside


初始化:image.png

image.png ,其余都等于0。

outside值要分为两部分计算:

c628d96e1b1967a8342b2cd6c86687ff.jpg

第一部分是 image.png ,如上图所示。

e964e990f6c4b0947c5cfb9cff9b382c.jpg

第二部分是 image.png ,如上图所示。

和inside相反,通过自顶向下计算outside值:

image.png

应用


所有可能的句法树potential之和为:

image.png

包含产生式 image.png 的所有可能句法树potential之和是:

image.png

存在非终结符  ,且短语是 image.png 的所有可能句法树potential之和是:

image.png

PCFG参数估计


参数估计的目的就是为了估计出PCFG的概率 P ,使得所有句子的概率之和最大,采用的是EM迭代法。

首先定义:

image.png

这里 image.png 是随机初始化的,满足归一化条件就行。

对于语料库的每一条句子,可以计算出:

image.png

然后算出期望,更新概率,迭代就行了。

CRF-CFG参数估计


首先定义:

image.png

其中 image.png 为特征函数。

那么我们的目的就是训练特征参数 image.png

然后定义似然函数为

image.png

求偏导为

image.png

这里可能有人看不懂,似然函数和偏导是怎么来的呢?下面我详细写一下过程。

似然函数:

image.png

所以偏导为:

image.png


image.png

所以偏导就是这么来的。


相关文章
|
6月前
|
算法 数据挖掘
文献解读-Consistency and reproducibility of large panel next-generation sequencing: Multi-laboratory assessment of somatic mutation detection on reference materials with mismatch repair and proofreading deficiency
Consistency and reproducibility of large panel next-generation sequencing: Multi-laboratory assessment of somatic mutation detection on reference materials with mismatch repair and proofreading deficiency,大panel二代测序的一致性和重复性:对具有错配修复和校对缺陷的参考物质进行体细胞突变检测的多实验室评估
53 6
文献解读-Consistency and reproducibility of large panel next-generation sequencing: Multi-laboratory assessment of somatic mutation detection on reference materials with mismatch repair and proofreading deficiency
|
PyTorch 算法框架/工具
Pytorch中Trying to backward through the graph和one of the variables needed for gradient错误解决方案
Pytorch中Trying to backward through the graph和one of the variables needed for gradient错误解决方案
2343 0
Pytorch中Trying to backward through the graph和one of the variables needed for gradient错误解决方案
|
10月前
|
算法 光互联 计算机视觉
Locally Adaptive Color Correction for Underwater Image Dehazing and Matching
该文提出了一种新颖的水下图像处理方法,结合颜色转移和局部调整来校正颜色,以应对水下光照和散射造成的图像退化。传统颜色转移方法基于全局参数,不适应水下场景中颜色变化的局部性质。文章中,作者通过融合策略,利用光衰减水平估计来实现局部颜色校正。首先,通过暗通道先验恢复彩色补偿图像,然后估计光衰减图。接着,创建一个合成图像,该图像的统计特性代表高衰减区域,用于颜色转移。最后,通过加权融合初始图像和颜色转移图像,生成最终的颜色校正图像。这种方法旨在提高水下图像的对比度和颜色准确性,特别关注高衰减区域。
114 1
|
算法 Java
回溯算法详解(Back Tracking)
回溯算法详解(Back Tracking)
235 0
|
存储 算法
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分)
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分)
103 0
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分)
|
SQL 关系型数据库 MySQL
LeetCode 613. Shortest Distance in a Line
LeetCode 613. Shortest Distance in a Line
110 0
Circles Inside a Square(几何题)
题目描述 You have 8 circles of equal size and you want to pack them inside a square. You want to minimize the size of the square. The following figure illustrates the minimum way of packing 8 circles inside a square:
143 0
Circles Inside a Square(几何题)
PAT (Advanced Level) Practice - 1138 Postorder Traversal(25 分)
PAT (Advanced Level) Practice - 1138 Postorder Traversal(25 分)
112 0
|
Java 编译器 Unix