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...
]
}