kshitijzutshi / BERT-NER-API

Created BERT Named Entity Relation(NER) API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BERT Named Entity Recognition API

Created BERT Named Entity Relation(NER) API deployed on AWS ECR

Hugging Face model

Following Hugging face model was used : dslim/bert-base-NER 🚀

Model description

bert-base-NER is a fine-tuned BERT model that is ready to use for Named Entity Recognition and achieves state-of-the-art performance for the NER task. It has been trained to recognize four types of entities: location (LOC), organizations (ORG), person (PER) and Miscellaneous (MISC).

Specifically, this model is a bert-base-cased model that was fine-tuned on the English version of the standard CoNLL-2003 Named Entity Recognition dataset.

How to use

You can use this model with Transformers pipeline for NER.

from transformers import AutoTokenizer, AutoModelForTokenClassification
from transformers import pipeline

tokenizer = AutoTokenizer.from_pretrained("dslim/bert-base-NER")
model = AutoModelForTokenClassification.from_pretrained("dslim/bert-base-NER")

nlp = pipeline("ner", model=model, tokenizer=tokenizer)
example = "My name is Wolfgang and I live in Berlin"

ner_results = nlp(example)
print(ner_results)

This model was fine-tuned on English version of the standard CoNLL-2003 Named Entity Recognition dataset.

The training dataset distinguishes between the beginning and continuation of an entity so that if there are back-to-back entities of the same type, the model can output where the second entity begins. As in the dataset, each token will be classified as one of the following classes:

image

image

AWS deployed ECR - Lambda function

The API is deployed and REST POST call was 200 OK

image

Streamlit integration

Following steps can be done to integrate the REST API response to get the UI on streamlit

https://blog.jcharistech.com/2019/11/28/summarizer-and-named-entity-checker-app-with-streamlit-and-spacy/

Screenshot

image

References

https://github.com/philschmid/serverless-bert-huggingface-aws-lambda-docker