
テキストの概念を否定するためのスペイシーパイプラインオブジェクト。 Negexアルゴリズムに基づいています。
Negex-退院の否定的な発見と病気を識別するための簡単なアルゴリズムChapman、Bridewell、Hanbury、Cooper、Buchanan https://doi.org/10.1006/jbin.2001.1029
バージョン1.0は、パイプラインコンポーネントを追加するためのSpacy 3.0の新しいインターフェイスをサポートするメジャーバージョンアップデートです。その結果、Negspacyの以前のバージョンと互換性がありません。
プロジェクトがSpacy 2.3.5以前を使用している場合、バージョン0.1.9を使用する必要があります。アーカイブされたreadmeを参照してください。
ライブラリをインストールします。
pip install negspacyライブラリとスペイシーをインポートします。
import spacy
from negspacy . negation import Negexスペイシー言語モデルをロードします。 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 FalseScispacyとペアリングして、テキストとプロセスの否定でUMLSの概念を見つけることを検討してください。
使用する用語セットを指定すると、 en_clinicalデフォルトで使用されます。
en =一般的な英語テキストのフレーズen_clinicalデフォルト=臨床ドメインに固有のフレーズを一般英語に追加する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 Universeで紹介されています。他の便利なライブラリとインスピレーションについては、それをチェックしてください。
指定されたエンティティ(生年月日、アカウント番号、または実験室の結果)に対応する値を抽出するスペイシーパイプラインオブジェクトを探している場合は、抽出物を見てください。
