SceneGraphparser( sng_parser )は、依存関係解析に基づいて、文章(自然言語)をシーングラフ(シンボリック表現として)に解析するためのPythonツールキットです。このプロジェクトは、スタンフォードシーングラフパーサーに触発されています。
スタンフォードバージョンとは異なり、このパーサーは純粋にPythonによって書かれています。使いやすいユーザーインターフェイスと構成しやすいデザインがあります。ノードが名詞(決定要因や形容詞などの修飾子を含む)とエッジが名詞間の関係であるグラフに文を解析します。詳細については、例のセクションをご覧ください。
ハイライト:このプロジェクトはまだ開発中です。すべてのAPIは変更の対象となります。
注:ご存知かもしれませんが、解析は解析ツリーの人間が書いた一連のルールによって行われます。したがって、現在のプログラムの失敗/コーナーケースを収集する際に、すべての人からの助けが必要です。どんな種類のレポートやヘルプは大歓迎であるはずです。
このレポは次のために開発されました:
統一された視覚セマンティックな埋め込み:構造化された意味表現を備えたビジョンと言語の橋渡し
Hao Wu、Jiayuan Mao、Yufeng Zhang、Yuning Jiang、Lei Li、Weiwei Sun、およびWei-ing Ma
コンピュータービジョンとパターン認識に関する会議(CVPR)2019 (口頭発表)
あなたが快適だと感じたら、私たちの論文を引用することを検討してください:)。このレポとオリジナルのスタンフォードシーングラフパーサーの違いは、#7にあります。
パッケージはPIPを使用してインストールできます。現在、バックエンドとしてのスパシーのみをサポートするため、インストール後に英語パッケージをダウンロードする必要があります。
pip install SceneGraphParser
python -m spacy download en # to use the parser for English このツールを使用する最も簡単な方法は、 parse機能を呼び出すことです。設計では、 sng_parserさまざまなバックエンドをサポートしています。現在、スパシーバックエンドのみをサポートしています。
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...
]
}