
พื้นที่เก็บข้อมูลนี้มีท่อและแบบจำลองที่กำหนดเองที่เกี่ยวข้องกับการใช้ spacy สำหรับเอกสารทางวิทยาศาสตร์
โดยเฉพาะอย่างยิ่งมี tokenizer แบบกำหนดเองที่เพิ่มกฎการทำโทเค็นบน Tokenizer ตามกฎของ Spacy, POS tagger และตัวแยกวิเคราะห์วากยสัมพันธ์ที่ได้รับการฝึกฝนเกี่ยวกับข้อมูลชีวการแพทย์และแบบจำลองการตรวจจับขยายเอนทิตี แยกต่างหากก็มีแบบจำลองสำหรับงานที่เฉพาะเจาะจงมากขึ้น
เพียงแค่ต้องการทดสอบโมเดลบนข้อมูลของคุณ? ตรวจสอบการสาธิตของเรา (หมายเหตุ: การสาธิตนี้กำลังเรียกใช้ Scispacy รุ่นเก่าและอาจให้ผลลัพธ์ที่แตกต่างจากเวอร์ชันล่าสุด)
การติดตั้ง scispacy ต้องใช้สองขั้นตอน: การติดตั้งไลบรารีและติดตั้งรุ่น ในการติดตั้งไลบรารี Run:
pip install scispacyหากต้องการติดตั้งรุ่น (ดูการเลือกรุ่นที่มีอยู่ด้านล่างของเรา) ให้เรียกใช้คำสั่งเช่นต่อไปนี้:
pip install https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.5.4/en_core_sci_sm-0.5.4.tar.gzหมายเหตุ: เราขอแนะนำอย่างยิ่งให้คุณใช้สภาพแวดล้อม Python ที่แยกได้ (เช่น Virtualenv หรือ Conda) เพื่อติดตั้ง scispacy ดูด้านล่างในส่วน "การตั้งค่าสภาพแวดล้อมเสมือนจริง" หากคุณต้องการความช่วยเหลือเกี่ยวกับเรื่องนี้ นอกจากนี้ Scispacy ยังใช้คุณสมบัติที่ทันสมัยของ Python และมีให้เฉพาะสำหรับ Python 3.6 หรือมากกว่าเท่านั้น
ในช่วงหลายปีที่ผ่านมาการติดตั้ง NMSLIB นั้นค่อนข้างยาก มีปัญหา GitHub จำนวนหนึ่งเกี่ยวกับ Scispacy และ NMSLIB repo เกี่ยวกับเรื่องนี้ เมทริกซ์นี้เป็นความพยายามที่จะช่วยให้ผู้ใช้ติดตั้ง NMSLIB ในสภาพแวดล้อมที่พวกเขามี ฉันไม่สามารถเข้าถึงสภาพแวดล้อมทุกประเภทได้ดังนั้นหากคุณสามารถทดสอบบางสิ่งได้โปรดเปิดปัญหาหรือดึงคำขอ!
| Windows 11 | ระบบย่อย Windows สำหรับ Linux | Mac M1 | Mac M2 | Mac M3 | Mac M4 | Intel Mac | |
|---|---|---|---|---|---|---|---|
| Python 3.8 | - | ||||||
| Python 3.9 | - | - | - | ||||
| Python 3.10 | - | - | |||||
| Python 3.11 | - | - | - | ||||
| Python 3.12 | - | - | - |
✅ = ทำงานได้ตามปกติด้วยการติดตั้ง pip ของ scispacy
= ไม่ทำงานตามปกติกับการติดตั้ง pip ของ scispacy
- = สามารถติดตั้งด้วย mamba install nmslib
= สามารถติดตั้งด้วย CFLAGS="-mavx -DWARN(a)=(a)" pip install nmslib
- สามารถติดตั้งได้ด้วย pip install nmslib-metabrainz
- = สามารถติดตั้งได้ด้วย conda install -c conda-forge nmslib
❓ = ไม่ได้รับการยืนยัน
วิธีการอื่น ๆ ที่กล่าวถึงในประเด็น GitHub แต่ยังไม่ได้รับการยืนยันว่าเวอร์ชันใดที่พวกเขาทำงานเพื่อ:
CFLAGS="-mavx -DWARN(a)=(a)" pip install nmslibpip install --no-binary :all: nmslibpip install "nmslib @ git+https://github.com/nmslib/nmslib.git/#subdirectory=python_bindings"pip install --upgrade pybind11 + pip install --verbose 'nmslib @ git+https://github.com/nmslib/nmslib.git#egg=nmslib&subdirectory=python_bindings' Mamba สามารถใช้งานการตั้งค่าสภาพแวดล้อมเสมือนจริงด้วยรุ่น Python ที่จำเป็นสำหรับ Scispacy หากคุณมีสภาพแวดล้อม Python ที่คุณต้องการใช้อยู่แล้วคุณสามารถข้ามไปยังส่วน 'การติดตั้งผ่าน PIP'
ทำตามคำแนะนำการติดตั้งสำหรับ Mamba
สร้างสภาพแวดล้อม conda ที่เรียกว่า "scispacy" ด้วย Python 3.9 (เวอร์ชันใด ๆ > = 3.6 ควรใช้งานได้):
mamba create -n scispacy python=3.10เปิดใช้งานสภาพแวดล้อม Mamba คุณจะต้องเปิดใช้งานสภาพแวดล้อม conda ในแต่ละเทอร์มินัลที่คุณต้องการใช้ scispacy
mamba activate scispacy ตอนนี้คุณสามารถติดตั้ง scispacy และหนึ่งในรุ่นที่ใช้ขั้นตอนด้านบน
เมื่อคุณทำตามขั้นตอนข้างต้นเสร็จแล้วและดาวน์โหลดหนึ่งในรุ่นด้านล่างคุณสามารถโหลดโมเดล scispacy ได้เช่นเดียวกับที่คุณต้องการรุ่น Spacy อื่น ๆ ตัวอย่างเช่น:
import spacy
nlp = spacy . load ( "en_core_sci_sm" )
doc = nlp ( "Alterations in the hypocretin receptor 2 and preprohypocretin genes produce narcolepsy in some animals." ) หากคุณกำลังอัพเกรด scispacy คุณจะต้องดาวน์โหลดโมเดลอีกครั้งเพื่อให้รุ่นโมเดลเข้ากันได้กับเวอร์ชันของ scispacy ที่คุณมี ลิงค์ไปยังรุ่นที่คุณดาวน์โหลดควรมีหมายเลขเวอร์ชันของ scispacy ที่คุณมี
หากต้องการติดตั้งรุ่นคลิกที่ลิงค์ด้านล่างเพื่อดาวน์โหลดรุ่นจากนั้นเรียกใช้
pip install < / path / to / download >หรือคุณสามารถติดตั้งโดยตรงจาก URL โดยคลิกขวาที่ลิงค์เลือก "สำเนาลิงค์ที่อยู่" และกำลังทำงานอยู่
pip install CMD - V ( to paste the copied URL )| แบบอย่าง | คำอธิบาย | ติดตั้ง URL |
|---|---|---|
| en_core_sci_sm | ไปป์ไลน์เครื่องรางเต็มรูปแบบสำหรับข้อมูลชีวการแพทย์ที่มีคำศัพท์ ~ 100K | การดาวน์โหลด |
| en_core_sci_md | ไปป์ไลน์เครื่องรางเต็มรูปแบบสำหรับข้อมูลชีวการแพทย์ที่มีคำศัพท์ ~ 360K และเวกเตอร์คำ 50k | การดาวน์โหลด |
| en_core_sci_lg | ไปป์ไลน์เครื่องรางเต็มรูปแบบสำหรับข้อมูลชีวการแพทย์ที่มีคำศัพท์ ~ 785K และเวกเตอร์คำ 600K | การดาวน์โหลด |
| en_core_sci_scibert | ไปป์ไลน์เครื่องรางเต็มรูปแบบสำหรับข้อมูลชีวการแพทย์ที่มีคำศัพท์ ~ 785K และ allenai/scibert-base เป็นรุ่นหม้อแปลง คุณอาจต้องการใช้ GPU กับรุ่นนี้ | การดาวน์โหลด |
| en_ner_craft_md | โมเดลของ Spacy Ner ที่ได้รับการฝึกฝนในคลังข้อมูลงานฝีมือ | การดาวน์โหลด |
| en_ner_jnlpba_md | โมเดลของ Spacy Ner ที่ได้รับการฝึกฝนเกี่ยวกับ JNLPBA Corpus | การดาวน์โหลด |
| en_ner_bc5cdr_md | แบบจำลอง Spacy Ner ที่ได้รับการฝึกฝนในคลังข้อมูล BC5CDR | การดาวน์โหลด |
| en_ner_bionlp13cg_md | แบบจำลอง Spacy Ner ที่ได้รับการฝึกฝนเกี่ยวกับคลังข้อมูล Bionlp13cg | การดาวน์โหลด |
AbbreviationDetector เป็นองค์ประกอบของ Spacy ซึ่งใช้อัลกอริทึมการตรวจจับตัวย่อใน "อัลกอริทึมที่ง่ายสำหรับการระบุคำจำกัดความตัวย่อในข้อความชีวการแพทย์", (Schwartz & Hearst, 2003)
คุณสามารถเข้าถึงรายการของตัวย่อผ่าน doc._.abbreviations และสำหรับตัวย่อที่กำหนดคุณสามารถเข้าถึงมันเป็นรูปแบบยาว (ซึ่งเป็น spacy.tokens.Span ) โดยใช้ span._.long_form ซึ่งจะชี้ไปที่อีกช่วงหนึ่งในเอกสาร
import spacy
from scispacy . abbreviation import AbbreviationDetector
nlp = spacy . load ( "en_core_sci_sm" )
# Add the abbreviation pipe to the spacy pipeline.
nlp . add_pipe ( "abbreviation_detector" )
doc = nlp ( "Spinal and bulbar muscular atrophy (SBMA) is an
inherited motor neuron disease caused by the expansion
of a polyglutamine tract within the androgen receptor (AR).
SBMA can be caused by this easily." )
print ( "Abbreviation" , " t " , "Definition" )
for abrv in doc . _ . abbreviations :
print ( f" { abrv } t ( { abrv . start } , { abrv . end } ) { abrv . _ . long_form } " )
> >> Abbreviation Span Definition
> >> SBMA ( 33 , 34 ) Spinal and bulbar muscular atrophy
> >> SBMA ( 6 , 7 ) Spinal and bulbar muscular atrophy
> >> AR ( 29 , 30 ) androgen receptorหมายเหตุ หากคุณต้องการที่จะทำให้วัตถุ
docของคุณเป็นอนุกรมให้โหลดเครื่องตรวจจับตัวย่อด้วยmake_serializable=Trueเช่นnlp.add_pipe("abbreviation_detector", config={"make_serializable": True})
EntityLinker เป็นองค์ประกอบของ Spacy ที่ทำการเชื่อมโยงไปยังฐานความรู้ Linker ดำเนินการค้นหาสตริงซ้อนทับ - การค้นหาตาม (Char -3Grams) บนเอนทิตีที่มีชื่อเปรียบเทียบกับแนวคิดในฐานความรู้โดยใช้การค้นหาเพื่อนบ้านที่ใกล้ที่สุดโดยประมาณ
ปัจจุบัน (v2.5.0) มี linkers ที่รองรับ 5 ตัว:
umls : ลิงก์ไปยังระบบภาษาการแพทย์แบบครบวงจรระดับ 0,1,2 และ 9 นี่มีแนวคิด ~ 3Mmesh : ลิงก์ไปยังหัวข้อเรื่องการแพทย์ สิ่งนี้มีชุดเอนทิตีที่มีคุณภาพสูงกว่าซึ่งใช้สำหรับการจัดทำดัชนีใน PubMed ตาข่ายมีเอนทิตี ~ 30k หมายเหตุ: ตาข่าย KB นั้นได้มาจากตาข่ายโดยตรงและใช้ตัวระบุที่ไม่ซ้ำกันที่แตกต่างจาก KBS อื่น ๆrxnorm : ลิงก์ไปยัง ontology rxnorm RXNORM มีแนวคิด ~ 100K มุ่งเน้นไปที่ชื่อปกติสำหรับยาทางคลินิก มันประกอบด้วยคำศัพท์ยาอื่น ๆ ที่ใช้กันทั่วไปในการจัดการร้านขายยาและการทำงานร่วมกันของยารวมถึงฐานข้อมูลแรก, Micromedex และฐานข้อมูลยามาตรฐานทองคำgo : ลิงก์ไปยังยีนอภิปรัชญา ยีนอภิปรัชญามีแนวคิด ~ 67K มุ่งเน้นไปที่การทำงานของยีนhpo : เชื่อมโยงไปยังอภิปรัชญาฟีโนไทป์ของมนุษย์ ontology ฟีโนไทป์ของมนุษย์มีแนวคิด 16K ที่มุ่งเน้นไปที่ความผิดปกติของฟีโนไทป์ที่พบในโรคของมนุษย์คุณอาจต้องการเล่นกับพารามิเตอร์บางส่วนด้านล่างเพื่อปรับให้เข้ากับกรณีการใช้งานของคุณ (ความแม่นยำสูงกว่าการเรียกคืนที่สูงขึ้น ฯลฯ )
resolve_abbreviations : bool = True, optional (default = False) ไม่ว่าจะแก้ไขตัวย่อที่ระบุในเอกสารก่อนทำการเชื่อมโยง พารามิเตอร์นี้ไม่มีผลหากไม่มี AbbreviationDetector ในท่อส่งก๊าซk : int, optional, (default = 30) จำนวนเพื่อนบ้านที่ใกล้ที่สุดเพื่อค้นหาจากตัวสร้างผู้สมัครต่อการกล่าวถึงthreshold : float, optional, (default = 0.7) เกณฑ์ที่ผู้สมัครที่กล่าวถึงจะต้องไปถึงเพื่อเพิ่มการกล่าวถึงในเอกสารในฐานะผู้สมัครที่กล่าวถึงno_definition_threshold : float, optional, (default = 0.95) เกณฑ์ที่ผู้สมัครเอนทิตีจะต้องเพิ่มเพื่อเพิ่มลงในการกล่าวถึงในเอกสารในฐานะผู้สมัครที่กล่าวถึงหากผู้สมัครนิติบุคคลไม่มีคำจำกัดความfilter_for_definitions: bool, default = True ไม่ว่าจะกรองเอนทิตีที่สามารถส่งคืนได้เฉพาะผู้ที่มีคำจำกัดความในฐานความรู้max_entities_per_mention : int, optional, default = 5 จำนวนสูงสุดของเอนทิตีซึ่งจะถูกส่งคืนสำหรับการกล่าวถึงที่กำหนดโดยไม่คำนึงถึงจำนวนเพื่อนบ้านที่ใกล้ที่สุด คลาสนี้ตั้งค่าแอตทริบิวต์ ._.kb_ents บน Spacy Span ซึ่งประกอบด้วยรายการ [tuple [str, float]] ที่สอดคล้องกับ KB Concept_id และคะแนนที่เกี่ยวข้องสำหรับรายการของ max_entities_per_mention จำนวนเอนทิตี
คุณสามารถค้นหาข้อมูลเพิ่มเติมสำหรับ ID ที่กำหนดโดยใช้แอตทริบิวต์ KB ของคลาสนี้:
print(linker.kb.cui_to_entity[concept_id])
import spacy
import scispacy
from scispacy . linking import EntityLinker
nlp = spacy . load ( "en_core_sci_sm" )
# This line takes a while, because we have to download ~1GB of data
# and load a large JSON file (the knowledge base). Be patient!
# Thankfully it should be faster after the first time you use it, because
# the downloads are cached.
# NOTE: The resolve_abbreviations parameter is optional, and requires that
# the AbbreviationDetector pipe has already been added to the pipeline. Adding
# the AbbreviationDetector pipe and setting resolve_abbreviations to True means
# that linking will only be performed on the long form of abbreviations.
nlp . add_pipe ( "scispacy_linker" , config = { "resolve_abbreviations" : True , "linker_name" : "umls" })
doc = nlp ( "Spinal and bulbar muscular atrophy (SBMA) is an
inherited motor neuron disease caused by the expansion
of a polyglutamine tract within the androgen receptor (AR).
SBMA can be caused by this easily." )
# Let's look at a random entity!
entity = doc . ents [ 1 ]
print ( "Name: " , entity )
> >> Name : bulbar muscular atrophy
# Each entity is linked to UMLS with a score
# (currently just char-3gram matching).
linker = nlp . get_pipe ( "scispacy_linker" )
for umls_ent in entity . _ . kb_ents :
print ( linker . kb . cui_to_entity [ umls_ent [ 0 ]])
> >> CUI : C1839259 , Name : Bulbo - Spinal Atrophy , X - Linked
> >> Definition : An X - linked recessive form of spinal muscular atrophy . It is due to a mutation of the
gene encoding the ANDROGEN RECEPTOR .
> >> TUI ( s ): T047
> >> Aliases ( abbreviated , total : 50 ):
Bulbo - Spinal Atrophy , X - Linked , Bulbo - Spinal Atrophy , X - Linked , ....
>> > CUI : C0541794 , Name : Skeletal muscle atrophy
> >> Definition : A process , occurring in skeletal muscle , that is characterized by a decrease in protein content ,
fiber diameter , force production and fatigue resistance in response to ...
>> > TUI ( s ): T046
> >> Aliases : ( total : 9 ):
Skeletal muscle atrophy , ATROPHY SKELETAL MUSCLE , skeletal muscle atrophy , ....
> >> CUI : C1447749 , Name : AR protein , human
> >> Definition : Androgen receptor ( 919 aa , ~ 99 kDa ) is encoded by the human AR gene .
This protein plays a role in the modulation of steroid - dependent gene transcription .
> >> TUI ( s ): T116 , T192
>> > Aliases ( abbreviated , total : 16 ):
AR protein , human , Androgen Receptor , Dihydrotestosterone Receptor , AR , DHTR , NR3C4 , ...ส่วนประกอบนี้ใช้การตอบสนองของ hyponyms โดยอัตโนมัติจากข้อความขนาดใหญ่โดยใช้คอมโพเนนต์เครื่องจับคู่ Spacy
Passing extended=True ไปยัง HyponymDetector จะใช้ชุดรูปแบบการขยายของรูปแบบ Hearst ซึ่งรวมถึงการเรียกคืนที่สูงขึ้น
ส่วนประกอบนี้สร้างแอตทริบิวต์ระดับ DOC ใน Spacy DOC: doc._.hearst_patterns ซึ่งเป็นรายการที่มี tuples ของคู่ hyponym สกัด tuples มี:
str )spacy.Span )spacy.Span ) import spacy
from scispacy . hyponym_detector import HyponymDetector
nlp = spacy . load ( "en_core_sci_sm" )
nlp . add_pipe ( "hyponym_detector" , last = True , config = { "extended" : False })
doc = nlp ( "Keystone plant species such as fig trees are good for the soil." )
print ( doc . _ . hearst_patterns )
> >> [( 'such_as' , Keystone plant species , fig trees )]หากคุณใช้ scispacy ในการวิจัยของคุณโปรดอ้างถึง Scispacy: แบบจำลองที่รวดเร็วและแข็งแกร่งสำหรับการประมวลผลภาษาธรรมชาติชีวการแพทย์ นอกจากนี้โปรดระบุรุ่นและรูปแบบของการ scispacy ที่คุณใช้เพื่อให้การวิจัยของคุณสามารถทำซ้ำได้
@inproceedings{neumann-etal-2019-scispacy,
title = "{S}cispa{C}y: {F}ast and {R}obust {M}odels for {B}iomedical {N}atural {L}anguage {P}rocessing",
author = "Neumann, Mark and
King, Daniel and
Beltagy, Iz and
Ammar, Waleed",
booktitle = "Proceedings of the 18th BioNLP Workshop and Shared Task",
month = aug,
year = "2019",
address = "Florence, Italy",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/W19-5034",
doi = "10.18653/v1/W19-5034",
pages = "319--327",
eprint = {arXiv:1902.07669},
abstract = "Despite recent advances in natural language processing, many statistical models for processing text perform extremely poorly under domain shift. Processing biomedical and clinical text is a critically important application area of natural language processing, for which there are few robust, practical, publicly available models. This paper describes scispaCy, a new Python library and models for practical biomedical/scientific text processing, which heavily leverages the spaCy library. We detail the performance of two packages of models released in scispaCy and demonstrate their robustness on several tasks and datasets. Models and code are available at https://allenai.github.io/scispacy/.",
}
Scispacy เป็นโครงการโอเพ่นซอร์สที่พัฒนาโดย Allen Institute เพื่อปัญญาประดิษฐ์ (AI2) AI2 เป็นสถาบันที่ไม่แสวงหาผลกำไรที่มีภารกิจในการสนับสนุนมนุษยชาติผ่านการวิจัยและวิศวกรรม AI ที่มีผลกระทบสูง