基于stanford nlp(JAVA)实现关系抽取

关系抽取是自然语言处理和理解的重要任务之一,就是从自由文本中发现实体对(人物、地点、机构、事件)及实体之间的关系。


关系抽取一般采用三元组,(实体,关系,实体)。因此关系抽取是知识图谱构建的重要环节之一。当前关系抽取已经有了各种方法,如有监督,远程监督、神经网络的关系抽取方法。本篇博客则侧重于工程应用中实体关系抽取的实现,主要基于Stanford NLP的库来实现。(见https://nlp.stanford.edu/software/relationExtractor.html),具体的关系抽取的实现方法见课件:https://web.stanford.edu/class/cs224u/materials/cs224u-2016-relation-extraction.pdf。


目前stanford nlp主要支持 Live_InLocated_InOrgBased_InWork_For, and None.这几种关系,它们的准确率介绍如下:

Label                           Correct Predict Actual  Precn   Recall  F       Roth/Yih F1
Live_In                         239.0   302.0   521.0   79.1    45.9    58.1    51.6
Located_In                      179.0   212.0   406.0   84.4    44.1    57.9    56.2
OrgBased_In                     169.0   252.0   452.0   67.1    37.4    48.0    51.7
Work_For                        185.0   247.0   401.0   74.9    46.1    57.1    52.0
_NR                             36176.0 37163.0 36396.0 97.3    99.4    98.4
Total                           772.0   1013.0  1780.0  76.2    43.4    55.3

可见关系抽取这一任务还有待改进之处特别多。


测试如下:

(1) Tim Cook is the CEO of Apple, he replaced Steve Jobs, who died in 2011.

基于stanford nlp(JAVA)实现关系抽取

上述例子,没有发现乔布斯与APPLE之间的关系。

(2)Obama was born in Hawaii. He is our president.

基于stanford nlp(JAVA)实现关系抽取


(3)Xi Jinping delivers a report to the 19th National Congress of the Communist Party of China (CPC) at the Great Hall of the People in Beijing

基于stanford nlp(JAVA)实现关系抽取

这个例子,做十九大报告的例子相对就不是那么准确了。


(4)The aircraft, a Hainan Airlines flight with 22 Chinese passengers onboard, arrived at a Antarctic airport after a more than 20-hour journey starting from Hong Kong.

基于stanford nlp(JAVA)实现关系抽取