如何下载和导入(最好使用spacy和hugginface)最新训练有素的biobert官方版本来对医学文本执行ner

问题描述 投票:0回答:1

张等人。 2020年的研究比较了biobert和scispacy ner模型的准确性,总体来说biobert获胜。如何下载和导入(最好使用 spacy 和从 Huggin Face)最新的 **经过训练的 ** 官方版本的 Biobert,以在 **无壳 ** 医学文本上执行 ner。如果有性能更好的医学文本ner模型,请告知。目标是确定诊断、手术和*可选*药物提及。

查看了很多拥抱面部代码,但不支持预训练模型的使用

spacy huggingface-transformers named-entity-recognition huggingface spacy-transformers
1个回答
0
投票

回答我自己的问题,我创建了一个 conda 环境并安装了一些软件包..

conda create --name biobertner python=3.11
conda activate biobertner
pip3 install torch torchvision torchaudio --index-url 
https://download.pytorch.org/whl/cu121
pip3 install transformers

我使用了来自https://huggingface.co/alvaroalon2/biobert_diseases_ner的biobert模型。 对于 python,我做了以下操作..

    from transformers import AutoTokenizer, AutoModelForTokenClassification
    from transformers import pipeline
    tokenizer = AutoTokenizer.from_pretrained("alvaroalon2/biobert_diseases_ner")
    model = AutoModelForTokenClassification.from_pretrained("alvaroalon2/biobert_diseases_ner")
    nlp = pipeline("ner", model=model, tokenizer=tokenizer)
    example = "she had a cold on the day she was diagnosed with cancer in her left lung on June 2023"
    ner_results = nlp(example)
    for ent in ner_results:
        print(ent)
© www.soinside.com 2019 - 2024. All rights reserved.