n元語法

文本中连续出现的n个语词

n元语法(英語:n-gram)指文本中连续出现的n个语词。n元语法模型是基于(n-1)阶马尔可夫链的一种概率语言模型,通过n个语词出现的概率来推断语句的结构。[1][2]这一模型被广泛应用于概率论、通信理论、计算语言学(如基于统计的自然语言处理)、计算生物学(如序列分析)、数据压缩等领域。

当n分别为1、2、3时,又分别称为一元语法(unigram)、二元语法bigram)与三元语法(trigram)。[2]

示例编辑

不同领域中的n元语法示例
领域单位示例一元语法二元语法三元语法
马尔可夫链阶数012
蛋白质测序氨基酸… Cys-Gly-Leu-Ser-Trp ……, Cys, Gly, Leu, Ser, Trp, ……, Cys-Gly, Gly-Leu, Leu-Ser, Ser-Trp, ……, Cys-Gly-Leu, Gly-Leu-Ser, Leu-Ser-Trp, …
DNA测序碱基对…AGCTTCGA……, A, G, C, T, T, C, G, A, ……, AG, GC, CT, TT, TC, CG, GA, ……, AGC, GCT, CTT, TTC, TCG, CGA, …
计算语言学字符…to_be_or_not_to_be……, t, o, _, b, e, _, o, r, _, n, o, t, _, t, o, _, b, e, ……, to, o_, _b, be, e_, _o, or, r_, _n, no, ot, t_, _t, to, o_, _b, be, ……, to_, o_b, _be, be_, e_o, _or, or_, r_n, _no, not, ot_, t_t, _to, to_, o_b, _be, …
计算语言学单词… to be or not to be ……, to, be, or, not, to, be, ……, to be, be or, or not, not to, to be, ……, to be or, be or not, or not to, not to be, …

参考文献编辑

  1. ^ 存档副本. [2016-10-16]. (原始内容存档于2016-12-25). 
  2. ^ 2.0 2.1 n元語法(資訊與通信術語辭典). 國家教育研究院. [2016-10-16]. (原始内容存档于2019-02-17).