
句法分析包含:成分句法分析(constituent syntactic parsing) 依存句法分析(dependency syntacticparsing) 语义依存分析(semantic dependency parsing)
目前的句法分析已经从成分句法分析转向依存句法分析,一是因为通用数据集Treebank(Universal Dependencies treebanks)的发展,虽然该数据集的标注较为复杂,但是其标注结果可以用作多种任务(命名体识别或词性标注)且作为不同任务的评估数据,因而得到越来越多的应用,二是成分句法分析的语法集是由固定的语法集组成,较为固定和呆板;三是依存句法分析树标注简单且parser准确率高。
1 成分句法分析
WSJ语料库的短语结构树,用树状结构图来表示,如下图所示:

如何描述文法,有两种主流观点,其中一种是短语结构文法,英文术语是:Constituency = phrase structure grammar = context-free grammars (CFGs)。
成分句法分析简单的上下文无关文法
grammar1 = nltk.CFG.fromstring(""" S -> NP VP VP -> V NP | V NP PP PP -> P NP V -> "saw" | "ate" | "walked" NP -> "John" | "Mary" | "Bob" | Det N | Det N PP Det -> "a" | "an" | "the" | "my" N -> "man" | "dog" | "cat" | "telescope" | "park" P -> "in" | "on" | "by" | "with" """)>>> sent = "Mary saw Bob".split()>>> rd_parser = nltk.RecursiveDescentParser(grammar1)>>> for tree in rd_parser.parse(sent):... print(tree)(S (NP Mary) (VP (V saw) (NP Bob)))
nltk其它功能,如分词,依存分析等功能 需要下载nltk自带的数据:可以api nltk.download()
也可以到 http://www.nltk.org/nltk_data/ 在配置
句法类型:
Symbol | Meaning | Example |
S | sentence | the man walked |
NP | noun phrase | a dog |
VP | verb phrase | saw a park |
PP | prepositional phrase(介词短语) | with a telescope |
Det | determiner(限定词) | the |
N | noun | dog |
V | verb | walked |
P | preposition | in |
Penn Treebank II Constituent Tags:
http://www.surdeanu.info/mihai/teaching/ista555-fall13/readings/PennTreebankConstituents.html#Word
2 句法依存分析
90年代的文法分析论文99%都是短语结构树,但后来人们发现依存文法树标注简单,parser准确率高,所以后来(特别是最近十年)基本上就是依存文法树的天下了(至少80%)。
如何描述文法,另一种是依存结构,用单词之间的依存关系来表达语法。如果一个单词修饰另一个单词,则称该单词依赖于另一个单词:
依存文法存在一个共同的基本假设:文法结构本质上包含词和词之间的依存(修饰)关系。一个依存关系连接两个词,分别是核心词( head)和依存词( dependent)。依存关系可以细分为不同的类型,表示两个词之间的具体句法关系。
依存关系是一个核心词与它的依赖之间的二元对称关系。一个句子的核心词通常是动词,所有其他词要么依赖于核心词,要么依赖路径与它联通。
依存关系表示是一个加标签的有向图,其中节点是词汇项,加标签的弧表示依赖关系, 从中心词到依赖。

英文的依存关系举例

中文的依存关系举例
Neural Dependency Parsing
Deep Biaffine Attention for Neural Dependency Parsing
A Fast and Accurate Dependency Parser using Neural Networks
Globally Normalized Transition-Based Neural Networks
Universal Dependencies: A cross-linguistic typology
Incrementality in Deterministic Dependency Parsing
NLPCC2019 shared tasks(跨领域依存句法分析)的一个baseline方法:
http://hlt.suda.edu.cn/index.php/Nlpcc-2019-shared-task
Deep Biaffine Attention for Neural Dependency Parsing
https://bamtercelboo.github.io/2019/06/27/Dependency_Parsing/
https://zhuanlan.zhihu.com/p/71553871
斯坦福句法分析器说明:
https://nlp.stanford.edu/software/lex-parser.html
https://nlp.stanford.edu/software/nndep.html
斯坦福句法依存手册:
《Stanford typed dependencies manual》
https://nlp.stanford.edu/software/dependencies_manual.pdf
http://universaldependencies.org/docsv1/#zh
Universal Dependencies:
https://universaldependencies.org/
一个跟踪nlp技术进展的git项目:
http://nlpprogress.com/english/dependency_parsing.html
依存分析评价指标

3 语义依存分析
语义依存分析 (Semantic Dependency Parsing, SDP),分析句子各个语言单位之间的语义关联,并将语义关联以依存结构呈现。使用语义依存刻画句子语义,好处在于不需要去抽象词汇本身,而是通过词汇所承受的语义框架来描述该词汇,而论元的数目相对词汇来说数量总是少了很多的。语义依存分析目标是跨越句子表层句法结构的束缚,直接获取深层的语义信息。例如以下三个句子,用不同的表达方式表达了同一个语义信息,即张三实施了一个吃的动作,吃的动作是对苹果实施的。

语义依存分析不受文法结构的影响,将具有直接语义关联的语言单元直接连接依存弧并标记上相应的语义关系。这也是语义依存分析与文法依存分析的重要区别。