SceneGraphParser ( sng_parser )는 종속성 구문 분석을 기반으로 한 장면 그래프 (상징적 표현)로 문장을 구문 분석하기위한 파이썬 툴킷입니다. 이 프로젝트는 스탠포드 장면 그래프 파서에서 영감을 얻었습니다.
스탠포드 버전과는 달리이 파서는 순전히 Python에 의해 작성됩니다. 사용하기 쉬운 사용자 인터페이스와 구성이 쉬운 디자인이 있습니다. 문장을 노드가 명사 인 그래프로 구문 분석하고 (결정 요인 또는 형용사와 같은 수정 자 포함) 가장자리는 명사 사이의 관계입니다. 자세한 내용은 예제 섹션을 참조하십시오.
하이라이트 :이 프로젝트는 여전히 개발 중입니다. 모든 API는 모든 변경의 대상이됩니다.
참고 : 알 수 있듯이, 구문 분석은 구문 분석 트리에 대한 일련의 인간이 작성한 규칙에 의해 수행됩니다. 따라서 현재 프로그램의 실패/코너 사례 수집에 대한 모든 사람의 도움이 필요합니다. 모든 종류의 보고서 나 도움은 환영받는 것 이상이어야합니다.
이 repo는 다음을 위해 개발되었습니다.
통일 시각적 인 미용 임베드 : 구조적 의미 표현을 가진 비전과 언어 브리징
Hao Wu, Jiyuan Mao, Yufeng Zhang, Yuning Jiang, Lei Li, Weiwei Sun 및 Wei-ying MA
컴퓨터 비전 및 패턴 인식에 관한 컨퍼런스 (CVPR) 2019 (Oral Presentation)
당신이 편안하다고 느끼면 우리 논문을 인용하는 것을 고려하십시오 :). 이 저장소와 오리지널 스탠포드 장면 그래프 파서의 차이점은 #7에서 찾을 수 있습니다.
패키지는 PIP를 사용하여 설치할 수 있습니다. 현재 백엔드로만 Spacy를 지원하므로 설치 후 영어 패키지를 다운로드해야합니다.
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.' ) 우리는 Pure 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...
]
}