SceneGraphParser
1.0.0
castegraphparser( sng_parser )是基于依赖性解析的python工具包(以自然语言为符号表示)(作为符号表示)。该项目的灵感来自斯坦福大学的图形解析器。
与斯坦福版本不同,该解析器纯粹由Python撰写。它具有易于使用的用户界面和易于配置的设计。它将节点是名词(带有确定性或形容词等修饰符)的句子解析为图表,边缘是名词之间的关系。请参阅示例部分以获取详细信息。
亮点:该项目仍在开发中。所有API都需要任何更改。
注意:您可能会注意到,解析是通过解析树上的一组人写的规则来完成的。因此,我们需要所有人的帮助,以收集当前程序的失败/角案例。任何类型的报告或帮助都应受到欢迎。
此存储库是为:
统一的视觉语义嵌入:带有结构性含义表示的桥接视觉和语言
Hao Wu,Jiayuan Mao,Yufeng Zhang,Yuning Jiang,Lei Li,Weiwei Sun和Wei-Ying MA
在2019年计算机视觉和模式识别会议(CVPR) (口头表现)中
如果您觉得很舒服,请考虑引用我们的论文:)。该仓库和原始的斯坦福大学场景图形解析器之间的区别可以在#7中找到。
可以使用PIP安装软件包。由于目前仅支持后端,因此需要在安装后下载英文包。
pip install SceneGraphParser
python -m spacy download en # to use the parser for English 使用此工具的最简单方法是调用parse功能。在设计中, sng_parser支持不同的后端。目前,我们仅支持Spacy后端。
pip install spacy
> >> import sng_parser
> >> graph = sng_parser . parse ( 'A woman is playing the piano in the room.' ) > >> from pprint import pprint
> >> pprint ( graph ) {'entities': [{'head': 'woman',
'lemma_head': 'woman',
'lemma_span': 'a woman',
'modifiers': [{'dep': 'det', 'lemma_span': 'a', 'span': 'A'}],
'span': 'A woman'},
{'head': 'piano',
'lemma_head': 'piano',
'lemma_span': 'the piano',
'modifiers': [{'dep': 'det',
'lemma_span': 'the',
'span': 'the'}],
'span': 'the piano'},
{'head': 'room',
'lemma_head': 'room',
'lemma_span': 'the room',
'modifiers': [{'dep': 'det',
'lemma_span': 'the',
'span': 'the'}],
'span': 'the room'}],
'relations': [{'object': 1, 'relation': 'playing', 'subject': 0},
{'object': 2, 'relation': 'in', 'subject': 0}]}
> >> sng_parser . tprint ( graph ) # we provide a tabular visualization of the graph. Entities:
+--------+-----------+-------------+
| Head | Span | Modifiers |
|--------+-----------+-------------|
| woman | a woman | a |
| piano | the piano | the |
| room | the room | the |
+--------+-----------+-------------+
Relations:
+-----------+------------+----------+
| Subject | Relation | Object |
|-----------+------------+----------|
| woman | playing | piano |
| woman | in | room |
+-----------+------------+----------+
另外,您可以配置自己的解析器:
> >> import sng_parser
> >> parser = sng_parser . Parser ( 'spacy' , model = 'en' ) # the positional argument specifies the backend, and the keyward arguments are for the backend initialization.
> >> graph = parser . parse ( 'A woman is playing the piano in the room.' )我们使用纯的Pythonic dict和list代表图形。尽管这种灵活性可能带来一些不必要的问题,但我们更喜欢这种表示,因为:
生成的场景图匹配以下规格:
{
'entities' : [ # a list of entities
{
'span' : "the full span of a noun phrase" ,
'lemma_span' : "the lemmatized version of the span" ,
'head' : "the head noun" ,
'lemma_head' : "the lemmatized version of the head noun" ,
'modifiers' : [
{
'dep' : "the dependency type" ,
'span' : "the span of the modifier" ,
'lemma_span' : "the lemmatized version of the span"
},
# other modifiers...
]
},
# other entities...
],
'relations' : [ # a list of relations
# the subject and object fields are sometimes called "head" and "tail" in relation extraction papers.
{
'subject' : "the entity id of the subject" ,
'object' : "the entity id of the object" ,
'relation' : "the relation"
}
# other relations...
]
}