[6c353a]: / medacy / pipelines / fda_nano_drug_label_pipeline.py

Download this file

37 lines (26 with data), 1.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import spacy
from medacy.pipeline_components.feature_extractors.discrete_feature_extractor import FeatureExtractor
from medacy.pipeline_components.feature_overlayers.metamap.metamap_component import MetaMapOverlayer
from medacy.pipeline_components.learners.crf_learner import get_crf
from medacy.pipeline_components.tokenizers.clinical_tokenizer import ClinicalTokenizer
from medacy.pipelines.base.base_pipeline import BasePipeline
class FDANanoDrugLabelPipeline(BasePipeline):
"""
A pipeline for named entity recognition of FDA nanoparticle drug labels. This pipeline was designed over-top of
the TAC 2018 SRIE track challenge.
Created by Andriy Mulyar (andriymulyar.com) of NLP@VCU
"""
def __init__(self, entities, metamap=None, **kwargs):
"""
:param entities: a list of Entities
:param metamap: an instance of MetaMap
"""
super().__init__(entities, spacy_pipeline=spacy.load("en_core_web_sm"), **kwargs)
if metamap:
self.add_component(MetaMapOverlayer, metamap)
def get_learner(self):
return "CRF_l2sgd", get_crf()
def get_tokenizer(self):
return ClinicalTokenizer(self.spacy_pipeline) # Best run with SystematicReviewTokenizer
def get_feature_extractor(self):
return FeatureExtractor(window_size=6, spacy_features=['pos_', 'shape_', 'prefix_', 'suffix_', 'like_num', 'text'])