Posts

Showing posts from April, 2023

Bio Medical Named Entity Recognition Model

Image
  Image from https://www.pexels.com/@artempodrez/ This blog is about using a Named Entity Recognition model, biomedical-ner-all to identify entities in a statement. We use hugging-face to load the inference API and execute it via a pipeline. These are the dependencies. I am using Python 3.10 and MacOS . pip3 install torch pip3 install transformers and here is a simple code snippet import json from transformers import pipeline from transformers import AutoTokenizer, AutoModelForTokenClassification model = "d4data/biomedical-ner-all" tokenizer = AutoTokenizer.from_pretrained(model) model = AutoModelForTokenClassification.from_pretrained(model) pipe = pipeline( "ner", model=model, tokenizer=tokenizer, aggregation_strategy="simple" ) # not using gpu because Torch not compiled with CUDA enabled, otherwise we can # device=0 result = pipe("Patient took ibuprofen for 2 weeks with 200 mg per day.") for r in result: r["score"] = fl