
วัตถุ Spacy Pipeline สำหรับการคัดค้านแนวคิดในข้อความ ขึ้นอยู่กับอัลกอริทึม NEGEX
NEGEX - อัลกอริทึมที่เรียบง่ายสำหรับการระบุการค้นพบและโรคที่ไม่ถูกต้องในบทสรุปการปลดประจำ
เวอร์ชัน 1.0 เป็นการอัปเดตเวอร์ชันหลักที่ให้การสนับสนุนอินเทอร์เฟซใหม่ของ Spacy 3.0 สำหรับการเพิ่มส่วนประกอบไปป์ไลน์ เป็นผลให้มันไม่สามารถย้อนกลับเข้ากันได้กับ NegSpacy เวอร์ชันก่อนหน้า
หากโครงการของคุณใช้ Spacy 2.3.5 หรือก่อนหน้านี้คุณจะต้องใช้เวอร์ชัน 0.1.9 ดู readme ที่เก็บถาวร
ติดตั้งไลบรารี
pip install negspacyนำเข้าห้องสมุดและ Spacy
import spacy
from negspacy . negation import Negexโหลดโมเดลภาษา Spacy เพิ่มวัตถุไปป์ไลน์ negspacy การกรองประเภทเอนทิตีเป็นทางเลือก
nlp = spacy . load ( "en_core_web_sm" )
nlp . add_pipe ( "negex" , config = { "ent_types" :[ "PERSON" , "ORG" ]})ดูการปฏิเสธ
doc = nlp ( "She does not like Steve Jobs but likes Apple products." )
for e in doc . ents :
print ( e . text , e . _ . negex ) Steve Jobs True
Apple Falseพิจารณาการจับคู่กับ scispacy เพื่อค้นหาแนวคิด UMLS ในการปฏิเสธข้อความและกระบวนการ
กำหนด termset ที่จะใช้ en_clinical ใช้โดยค่าเริ่มต้น
en = วลีสำหรับข้อความภาษาอังกฤษทั่วไปen_clinical default = เพิ่มวลีเฉพาะในโดเมนทางคลินิกเป็นภาษาอังกฤษทั่วไปen_clinical_sensitive = เพิ่มวลีเพิ่มเติมเพื่อช่วยแยกแยะหน่วยงานทางประวัติศาสตร์และอาจไม่เกี่ยวข้องเพื่อตั้งค่า:
from negspacy . negation import Negex
from negspacy . termsets import termset
ts = termset ( "en" )
nlp = spacy . load ( "en_core_web_sm" )
nlp . add_pipe (
"negex" ,
config = {
"neg_termset" : ts . get_patterns ()
}
)แทนที่รูปแบบทั้งหมดด้วยชุดของคุณเอง
nlp = spacy . load ( "en_core_web_sm" )
nlp . add_pipe (
"negex" ,
config = {
"neg_termset" :{
"pseudo_negations" : [ "might not" ],
"preceding_negations" : [ "not" ],
"following_negations" :[ "declined" ],
"termination" : [ "but" , "however" ]
}
}
)เพิ่มและลบแต่ละรูปแบบได้ทันทีจากข้อตกลงในตัว
from negspacy . termsets import termset
ts = termset ( "en" )
ts . add_patterns ({
"pseudo_negations" : [ "my favorite pattern" ],
"termination" : [ "these are" , "great patterns" , "but" ],
"preceding_negations" : [ "wow a negation" ],
"following_negations" : [ "extra negation" ],
})
#OR
ts . remove_patterns (
{
"termination" : [ "these are" , "great patterns" ],
"pseudo_negations" : [ "my favorite pattern" ],
"preceding_negations" : [ "denied" , "wow a negation" ],
"following_negations" : [ "unlikely" , "extra negation" ],
}
)ดูรูปแบบการใช้งาน
from negspacy . termsets import termset
ts = termset ( "en_clinical" )
print ( ts . get_patterns ())ขึ้นอยู่กับรูปแบบการจดจำเอนทิตีที่คุณใช้คุณ อาจ มีคำว่า "รวมกัน" ด้วยคำนาม ตัวอย่างเช่น:
nlp = spacy . load ( "en_core_sci_sm" )
doc = nlp ( "There is no headache." )
for e in doc . ents :
print ( e . text )
# no headache สิ่งนี้จะทำให้อัลกอริทึม NEGEX พลาดการปฏิเสธก่อนหน้านี้ ในการบัญชีสำหรับสิ่งนี้คุณสามารถเพิ่ม chunk_prefix :
nlp = spacy . load ( "en_core_sci_sm" )
ts = termset ( "en_clinical" )
nlp . add_pipe (
"negex" ,
config = {
"chunk_prefix" : [ "no" ],
},
last = True ,
)
doc = nlp ( "There is no headache." )
for e in doc . ents :
print ( e . text , e . _ . negex )
# no headache True การบริจาค
ใบอนุญาต
ห้องสมุดนี้ให้ความสำคัญในจักรวาล Spacy ตรวจสอบสำหรับห้องสมุดและแรงบันดาลใจที่เป็นประโยชน์อื่น ๆ
หากคุณกำลังมองหาวัตถุไปป์ไลน์ Spacy เพื่อแยกค่าที่สอดคล้องกับเอนทิตีที่มีชื่อ (เช่นวันเกิดหมายเลขบัญชีหรือผลลัพธ์ในห้องปฏิบัติการ) ดูที่การสกัด
