
이 저장소에는 과학 문서에 Spacy 사용과 관련된 맞춤형 파이프 및 모델이 포함되어 있습니다.
특히, Spacy의 규칙 기반 토큰 화기 위에 토큰 화 규칙, POS Tagger 및 Syntactic Parser가 생의학 데이터 및 엔터티 스팬 탐지 모델에 대해 훈련 된 맞춤형 토큰 화기가 있습니다. 별도로보다 구체적인 작업을위한 NER 모델도 있습니다.
데이터의 모델을 테스트하려고합니까? 데모를 확인하십시오 (참고 :이 데모는 이전 버전의 SCISPacy를 실행하고 있으며 최신 버전과 다른 결과를 생성 할 수 있습니다).
SCISPACY를 설치하려면 라이브러리 설치 및 모델을 강화하는 두 단계가 필요합니다. 라이브러리를 설치하려면 실행하십시오.
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참고 : SCISPACY를 설치하기 위해 고립 된 파이썬 환경 (예 : VirtualEnV 또는 Conda)을 사용하는 것이 좋습니다. 도움이 필요한 경우 "가상 환경 설정"섹션에서 아래를 살펴보십시오. 또한 SCISPacy는 Python의 최신 기능을 사용하므로 Python 3.6 이상 에서만 사용할 수 있습니다.
수년에 걸쳐 NMSLIB를 설치하는 것은 매우 어려워졌습니다. SCISPACY 및 NMSLIB Repo 자체에 대한 많은 GitHub 문제가 있습니다. 이 매트릭스는 사용자가 어떤 환경에서든 NMSLIB를 설치하도록 도와주는 시도입니다. 모든 유형의 환경에 액세스 할 수 없으므로 무언가를 테스트 할 수 있다면 문제를 열거나 요청을 당기십시오!
| Windows 11 | Linux 용 Windows 하위 시스템 | Mac M1 | Mac M2 | Mac M3 | Mac M4 | 인텔 맥 | |
|---|---|---|---|---|---|---|---|
| 파이썬 3.8 | ✅ | ✅ | ❓ | ❓ | ? | ❓ | |
| 파이썬 3.9 | ? | ✅ | ? | ❓ | ? | ❓ | |
| 파이썬 3.10 | ? | ✅ | ❓ | ❓ | ❓ | ? | ✅ |
| 파이썬 3.11 | ? | ? | ❓ | ❓ | ❓ | ? | |
| 파이썬 3.12 | ? | ?? | ❓ | ❓ | ❓ | ? | ❓ |
scispacy의 PIP 설치와 함께 정상적으로 작동합니다
= SCISPACI의 PIP 설치에서 정상적으로 작동하지 않습니다.
? = 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는 Scispacy에 필요한 Python 버전으로 가상 환경을 설정할 수 있습니다. 이미 사용하려는 파이썬 환경이있는 경우 'PIP를 통해 설치'섹션으로 건너 뛸 수 있습니다.
Mamba의 설치 지침을 따르십시오.
Python 3.9를 사용하여 "Scispacy"라는 콘다 환경을 만듭니다 (모든 버전> = 3.6이 작동합니다) :
mamba create -n scispacy python=3.10맘바 환경을 활성화하십시오. scispacy를 사용하려는 각 터미널에서 Conda 환경을 활성화해야합니다.
mamba activate scispacy 이제 위의 단계를 사용하여 scispacy 및 모델 중 하나를 설치할 수 있습니다.
위의 단계를 완료하고 아래 모델 중 하나를 다운로드 한 후에는 다른 스파이 모델과 마찬가지로 SCISPACY 모델을로드 할 수 있습니다. 예를 들어:
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 | JNLPBA 코퍼스에 대한 스파이 NER 모델. | 다운로드 |
| en_ner_bc5cdr_md | BC5CDR 코퍼스에서 훈련 된 스파크 네르 모델. | 다운로드 |
| en_ner_bionlp13cg_md | Spacy Ner 모델은 Bionlp13cg 코퍼스를 훈련시켰다. | 다운로드 |
약어 페이션 검출기는 "생의학 텍스트에서 약어 정의를 식별하기위한 간단한 알고리즘"에서 약어 감지 알고리즘을 구현하는 스파크 구성 요소입니다. (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 지식 기반에 링크를 수행하는 스파크 구성 요소입니다. 링커는 단순히 이름이 지정된 이웃 검색을 사용하여 지식 기반의 개념과 비교하여 명명 된 엔티티에서 문자열 중첩 - 기반 검색 (char -3grams)을 수행합니다.
현재 (v2.5.0), 5 개의 지원되는 링커가 있습니다.
umls : 통합 의료 언어 시스템, 레벨 0,1,2 및 9에 대한 링크. 여기에는 ~ 3m 개념이 있습니다.mesh : 의료 대상 제목에 대한 링크. 여기에는 PubMed에서 인덱싱에 사용되는 소규모 고품질 엔티티 세트가 포함되어 있습니다. 메쉬에는 ~ 30k 엔티티가 포함되어 있습니다. 참고 : 메쉬 KB는 메쉬 자체에서 직접 파생되며, 따라서 다른 KBS와 다른 고유 식별자를 사용합니다.rxnorm : rxnorm 온톨로지 링크. rxnorm에는 임상 약물의 정규화 된 이름에 중점을 둔 ~ 100k 개념이 포함되어 있습니다. 그것은 첫 번째 데이터 뱅크, 마이크로 메덱스 및 골드 표준 약물 데이터베이스를 포함한 약국 관리 및 약물 상호 작용에 일반적으로 사용되는 몇 가지 다른 약물 어휘로 구성됩니다.go : 유전자 온톨로지에 대한 링크. 유전자 온톨로지에는 유전자의 기능에 중점을 둔 ~ 67K 개념이 포함되어 있습니다.hpo : 인간 표현형 온톨로지와의 연결. 인간 표현형 온톨로지에는 인간 질병에서 발생하는 표현형 이상에 중점을 둔 16K 개념이 포함되어 있습니다.사용 사례에 적응하기 위해 아래의 일부 매개 변수를 가지고 놀 수 있습니다 (더 높은 정밀도, 높은 리콜 등).
resolve_abbreviations : bool = True, optional (default = False) 링크를 수행하기 전에 문서에서 식별 된 약어를 해결할지 여부. 이 매개 변수는 Spacy 파이프 라인에 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 가장 가까운 이웃이 발견되는지에 관계없이 주어진 언급을 위해 반환 될 최대 엔티티 수입니다. 이 클래스는 Spacy Spans에서 ._.kb_ents 속성을 설정하며, 이는 KB Concept_ID에 해당하는 목록 [tuple [str, float]]로 구성되어 있으며 max_entities_per_mention untities의 목록에 대한 관련 점수로 구성됩니다.
이 클래스의 KB 속성을 사용하여 주어진 ID에 대한 자세한 정보를 찾을 수 있습니다.
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 , ...이 구성 요소는 Spacy Matcher 구성 요소를 사용하여 큰 Text Corpora의 Hyponyms의 자동 Aquisition을 구현합니다.
HyponymDetector 에 extended=True 확장 된 Hearst 패턴 세트를 사용합니다. 여기에는 높은 리콜이지만 정밀성 저명 관계 (예 : y와 비교하여 x, y와 유사한 x 등)를 포함하는 확장 된 Hearst 패턴 세트가 사용됩니다.
이 구성 요소는 Spacy doc : doc._.hearst_patterns 에서 Doc 레벨 속성을 생성합니다. 여기에는 추출 된 hyponm 쌍의 튜플이 포함 된 목록입니다. 튜플에는 다음이 포함되어 있습니다.
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 : Biomedical Natural Language Processing을위한 빠르고 강력한 모델을 인용하십시오. 또한 연구를 재현 할 수 있도록 사용한 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 for 인공 지능 (AI2)이 개발 한 오픈 소스 프로젝트입니다. AI2는 고 충격적인 AI 연구 및 엔지니어링을 통해 인류에게 기여하는 사명을 가진 비영리 기관입니다.