SceneGraphParser ( sng_parser ) เป็นชุดเครื่องมือ Python สำหรับการแยกวิเคราะห์ประโยค (ในภาษาธรรมชาติ) ลงในกราฟฉาก (เป็นตัวแทนสัญลักษณ์) ขึ้นอยู่กับการแยกวิเคราะห์การพึ่งพา โครงการนี้ได้รับแรงบันดาลใจจากตัวแยกวิเคราะห์กราฟฉากสแตนฟอร์ด
แตกต่างจากเวอร์ชั่นสแตนฟอร์ดตัวแยกวิเคราะห์นี้เขียนโดย Python อย่างหมดจด มันมีส่วนต่อประสานผู้ใช้ที่ใช้งานง่ายและการออกแบบกำหนดค่าที่ง่าย มันแยกวิเคราะห์ประโยคลงในกราฟที่โหนดเป็นคำนาม (พร้อมตัวดัดแปลงเช่นปัจจัยหรือคำคุณศัพท์) และขอบเป็นความสัมพันธ์ระหว่างคำนาม โปรดดูส่วนตัวอย่างสำหรับรายละเอียด
ไฮไลต์: โครงการนี้ยังคงได้รับการพัฒนา API ทั้งหมดอาจมีการเปลี่ยนแปลงใด ๆ
หมายเหตุ : ดังที่คุณอาจสังเกตเห็นว่าการแยกวิเคราะห์จะทำโดยชุดของกฎที่เขียนโดยมนุษย์บนต้นไม้แยกวิเคราะห์ ดังนั้นเราต้องการความช่วยเหลือจากทุกคนในการรวบรวมกรณีความล้มเหลว/มุมของโปรแกรมปัจจุบัน รายงานหรือความช่วยเหลือใด ๆ ควรได้รับการต้อนรับมากกว่า
repo นี้ได้รับการพัฒนาสำหรับ:
Embeddings ภาพรวมภาพรวม: การมองเห็นและภาษาที่มีการแสดงความหมายที่มีโครงสร้าง
Hao Wu, Jiayuan Mao, Yufeng Zhang, Yuning Jiang, Lei Li, Weiwei Sun และ Weii-inging Ma
ในการประชุมเกี่ยวกับวิสัยทัศน์คอมพิวเตอร์และการจดจำรูปแบบ (CVPR) 2019 (การนำเสนอด้วยวาจา)
โปรดพิจารณาอ้างถึงกระดาษของเราหากคุณรู้สึกว่าสบายใจ :) ความแตกต่างระหว่าง repo นี้และตัวแยกวิเคราะห์กราฟฉากสแตนฟอร์ดดั้งเดิมสามารถพบได้ใน #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.' ) เราใช้ 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...
]
}