|
| 1 | +import unittest |
| 2 | +import nlu |
| 3 | +import sys |
| 4 | + |
| 5 | + |
| 6 | +class Test341(unittest.TestCase): |
| 7 | + |
| 8 | + def test_341_models(self): |
| 9 | + import pandas as pd |
| 10 | + te = [ |
| 11 | + 'en.embed.longformer.clinical', |
| 12 | + 'en.classify.emotion.bert', |
| 13 | + 'en.classify.typos.distilbert', |
| 14 | + 'de.classify.news_sentiment.bert', |
| 15 | + 'xx.embed.albert.indic', |
| 16 | + 'xx.ner.masakhaner', |
| 17 | + 'fr.embed.word2vec_wiki_1000', |
| 18 | + 'fr.embed.word2vec_wac_200', |
| 19 | + 'fr.embed.w2v_cc_300d', |
| 20 | + 'vi.embed.distilbert.cased', |
| 21 | + ] |
| 22 | + |
| 23 | + fails = [] |
| 24 | + for t in te: |
| 25 | + try: |
| 26 | + print(f'Testing spell = {t}') |
| 27 | + pipe = nlu.load(t, verbose=True) |
| 28 | + df = pipe.predict(['Peter love pancaces. I hate Mondays', 'I love Fridays']) |
| 29 | + for c in df.columns: print(df[c]) |
| 30 | + except Exception as err: |
| 31 | + print(f'Failure for spell = {t} ', err) |
| 32 | + e = sys.exc_info() |
| 33 | + print(e[0]) |
| 34 | + print(e[1]) |
| 35 | + fails.append(t) |
| 36 | + |
| 37 | + fail_string = "\n".join(fails) |
| 38 | + print(f'Done testing, failures = {fail_string}') |
| 39 | + if len(fails) > 0: |
| 40 | + raise Exception("Not all new spells completed successfully") |
| 41 | + |
| 42 | + def test_341_HC_models(self): |
| 43 | + import tests.secrets as sct |
| 44 | + |
| 45 | + SPARK_NLP_LICENSE = sct.SPARK_NLP_LICENSE |
| 46 | + AWS_ACCESS_KEY_ID = sct.AWS_ACCESS_KEY_ID |
| 47 | + AWS_SECRET_ACCESS_KEY = sct.AWS_SECRET_ACCESS_KEY |
| 48 | + JSL_SECRET = sct.JSL_SECRET |
| 49 | + nlu.auth(SPARK_NLP_LICENSE, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, JSL_SECRET) |
| 50 | + te = [ |
| 51 | + 'en.med_ner.supplement_clinical', |
| 52 | + 'en.resolve.rxnorm.augmented_re', |
| 53 | + 'en.classify.gender.seq_biobert', |
| 54 | + 'es.embed.sciwiki_300d', |
| 55 | + 'en.classify.ade.seq_biobert', |
| 56 | + 'en.classify.pico.seq_biobert', |
| 57 | + 'en.classify.ade.seq_distilbert', |
| 58 | + 'es.med_ner.deid.generic', |
| 59 | + 'es.med_ner.deid.subentity', |
| 60 | + |
| 61 | + 'en.relation.temporal_events_clinical', |
| 62 | + 'en.relation.adverse_drug_events.clinical', |
| 63 | + 'en.relation.adverse_drug_events.clinical.biobert', |
| 64 | + |
| 65 | + ] |
| 66 | + sample_texts = [""" |
| 67 | + Antonio Pérez Juan, nacido en Cadiz, España. Aún no estaba vacunado, se infectó con Covid-19 el dia 14/03/2020 y tuvo que ir al Hospital. Fue tratado con anticuerpos monoclonales en la Clinica San Carlos.. |
| 68 | + """, |
| 69 | + """ |
| 70 | + Datos del paciente. Nombre: Jose . Apellidos: Aranda Martinez. NHC: 2748903. NASS: 26 37482910. |
| 71 | + """, |
| 72 | + """The patient was given metformin 500 mg, 2.5 mg of coumadin and then ibuprofen""", |
| 73 | + """he patient was given metformin 400 mg, coumadin 5 mg, coumadin, amlodipine 10 MG""", |
| 74 | + """To compare the results of recording enamel opacities using the TF and modified DDE indices.""", |
| 75 | + """I felt a bit drowsy and had blurred vision after taking Aspirin.""", |
| 76 | + ] |
| 77 | + fails = [] |
| 78 | + succs = [] |
| 79 | + for t in te: |
| 80 | + try: |
| 81 | + print(f'Testing spell = {t}') |
| 82 | + pipe = nlu.load(t, verbose=True) |
| 83 | + df = pipe.predict(sample_texts, drop_irrelevant_cols=False, metadata=True, ) |
| 84 | + print(df.columns) |
| 85 | + for c in df.columns: |
| 86 | + print(df[c]) |
| 87 | + succs.append(t) |
| 88 | + except Exception as err: |
| 89 | + print(f'Failure for spell = {t} ', err) |
| 90 | + fails.append(t) |
| 91 | + break |
| 92 | + fail_string = '\n'.join(fails) |
| 93 | + succ_string = '\n'.join(succs) |
| 94 | + print(f'Done testing, failures = {fail_string}') |
| 95 | + print(f'Done testing, successes = {succ_string}') |
| 96 | + if len(fails) > 0: |
| 97 | + raise Exception("Not all new spells completed successfully") |
| 98 | + |
| 99 | +if __name__ == '__main__': |
| 100 | + unittest.main() |
0 commit comments