コード例 #1
0
ファイル: test.py プロジェクト: plandes/medaCy
def main(model: str, text: str = None, cuda: int = None):
    if text is None:
        text = "The patient was prescribed 1 capsule of Advil for five days."
    if model == 'crf':
        print('using CRF model')
        model = Model.load_external('medacy_model_clinical_notes')
    else:
        print('using BERT model')
        if cuda is not None:
            from medacy_bert_model_clinical_notes import medacy_bert_model_clinical_notes
            medacy_bert_model_clinical_notes.PIPELINE_ARGS[
                'cuda_device'] = cuda
        model = Model.load_external('medacy_bert_model_clinical_notes')
    anons = model.predict(text)
    for anon in anons:
        print(anon)
コード例 #2
0
df_filtered['tweet_text'] = df_filtered['tweet_text'].apply(
    lambda x: remove_emoji(x))

#Getting the annotations from each of the tweet's text
#Part of the following code was obtained from here:
#https://github.com/NLPatVCU/medaCy/

from medacy.model.model import Model

df_medacy_annotations = pd.DataFrame(columns=[
    'Tweet_id', 'Text_section', 'Span_start', 'Span_end', 'Annotation_type',
    'Extras'
])
df_medacy_tweets_tagged = pd.DataFrame(columns=['Tweet_id', 'Tweet_full_text'])

model = Model.load_external('medacy_model_clinical_notes')

print("Configuring the Medacy tagger. Please wait...")
for index, row in df_filtered.iterrows():

    annotation = model.predict(row['tweet_text'])

    if len(annotation) > 0:
        df_medacy_tweets_tagged.loc[len(df_medacy_tweets_tagged.index)] = [
            row['tweet_id'], row['tweet_text']
        ]

        for i in range(len(annotation)):
            df_medacy_annotations.loc[len(df_medacy_annotations)] = [
                row['tweet_id'], annotation.annotations[i][3],
                annotation.annotations[i][1], annotation.annotations[i][2],