Named Entity Recognition - BERT Mini (OntoNotes)

Description

Onto is a Named Entity Recognition (or NER) model trained on OntoNotes 5.0. It can extract up to 18 entities such as people, places, organizations, money, time, date, etc.

This model uses the pretrained small_bert_L4_256 embeddings model from the BertEmbeddings annotator as an input.

Predicted Entities

CARDINAL, DATE, EVENT, FAC, GPE, LANGUAGE, LAW, LOC, MONEY, NORP, ORDINAL, ORG, PERCENT, PERSON, PRODUCT, QUANTITY, TIME, WORK_OF_ART.

Live Demo Open in Colab Download Copy S3 URI

How to use

...
ner_onto = NerDLModel.pretrained("onto_small_bert_L4_256", "en") \
.setInputCols(["document", "token", "embeddings"]) \
.setOutputCol("ner")
...        
nlp_pipeline = Pipeline(stages=[document_assembler, sentence_detector, tokenizer, embeddings, ner_onto, ner_converter])
pipeline_model = nlp_pipeline.fit(spark.createDataFrame([['']]).toDF('text'))

result = pipeline_model.transform(spark.createDataFrame([["William Henry Gates III (born October 28, 1955) is an American business magnate, software developer, investor, and philanthropist. He is best known as the co-founder of Microsoft Corporation. During his career at Microsoft, Gates held the positions of chairman, chief executive officer (CEO), president and chief software architect, while also being the largest individual shareholder until May 2014. He is one of the best-known entrepreneurs and pioneers of the microcomputer revolution of the 1970s and 1980s. Born and raised in Seattle, Washington, Gates co-founded Microsoft with childhood friend Paul Allen in 1975, in Albuquerque, New Mexico; it went on to become the world's largest personal computer software company. Gates led the company as chairman and CEO until stepping down as CEO in January 2000, but he remained chairman and became chief software architect. During the late 1990s, Gates had been criticized for his business tactics, which have been considered anti-competitive. This opinion has been upheld by numerous court rulings. In June 2006, Gates announced that he would be transitioning to a part-time role at Microsoft and full-time work at the Bill & Melinda Gates Foundation, the private charitable foundation that he and his wife, Melinda Gates, established in 2000. He gradually transferred his duties to Ray Ozzie and Craig Mundie. He stepped down as chairman of Microsoft in February 2014 and assumed a new post as technology adviser to support the newly appointed CEO Satya Nadella."]], ["text"]))
...
val ner_onto = NerDLModel.pretrained("onto_small_bert_L4_256", "en")
.setInputCols(Array("document", "token", "embeddings"))
.setOutputCol("ner")
...
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector, tokenizer, embeddings, ner_onto, ner_converter))

val data = Seq("William Henry Gates III (born October 28, 1955) is an American business magnate, software developer, investor, and philanthropist. He is best known as the co-founder of Microsoft Corporation. During his career at Microsoft, Gates held the positions of chairman, chief executive officer (CEO), president and chief software architect, while also being the largest individual shareholder until May 2014. He is one of the best-known entrepreneurs and pioneers of the microcomputer revolution of the 1970s and 1980s. Born and raised in Seattle, Washington, Gates co-founded Microsoft with childhood friend Paul Allen in 1975, in Albuquerque, New Mexico; it went on to become the world's largest personal computer software company. Gates led the company as chairman and CEO until stepping down as CEO in January 2000, but he remained chairman and became chief software architect. During the late 1990s, Gates had been criticized for his business tactics, which have been considered anti-competitive. This opinion has been upheld by numerous court rulings. In June 2006, Gates announced that he would be transitioning to a part-time role at Microsoft and full-time work at the Bill & Melinda Gates Foundation, the private charitable foundation that he and his wife, Melinda Gates, established in 2000. He gradually transferred his duties to Ray Ozzie and Craig Mundie. He stepped down as chairman of Microsoft in February 2014 and assumed a new post as technology adviser to support the newly appointed CEO Satya Nadella.").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu

text = ["""William Henry Gates III (born October 28, 1955) is an American business magnate, software developer, investor, and philanthropist. He is best known as the co-founder of Microsoft Corporation. During his career at Microsoft, Gates held the positions of chairman, chief executive officer (CEO), president and chief software architect, while also being the largest individual shareholder until May 2014. He is one of the best-known entrepreneurs and pioneers of the microcomputer revolution of the 1970s and 1980s. Born and raised in Seattle, Washington, Gates co-founded Microsoft with childhood friend Paul Allen in 1975, in Albuquerque, New Mexico; it went on to become the world's largest personal computer software company. Gates led the company as chairman and CEO until stepping down as CEO in January 2000, but he remained chairman and became chief software architect. During the late 1990s, Gates had been criticized for his business tactics, which have been considered anti-competitive. This opinion has been upheld by numerous court rulings. In June 2006, Gates announced that he would be transitioning to a part-time role at Microsoft and full-time work at the Bill & Melinda Gates Foundation, the private charitable foundation that he and his wife, Melinda Gates, established in 2000. He gradually transferred his duties to Ray Ozzie and Craig Mundie. He stepped down as chairman of Microsoft in February 2014 and assumed a new post as technology adviser to support the newly appointed CEO Satya Nadella."""]
ner_df = nlu.load('en.ner.onto.bert.small_l4_256').predict(text, output_level='chunk')
ner_df[["entities", "entities_class"]]

Results


+-----------------------+---------+
|chunk                  |ner_label|
+-----------------------+---------+
|William Henry Gates III|PERSON   |
|October 28, 1955       |DATE     |
|American               |NORP     |
|Microsoft Corporation  |ORG      |
|Microsoft              |ORG      |
|Gates                  |PERSON   |
|May 2014               |DATE     |
|one                    |CARDINAL |
|1970s and 1980s        |DATE     |
|Seattle                |GPE      |
|Washington             |GPE      |
|Gates                  |PERSON   |
|Paul Allen             |PERSON   |
|1975                   |DATE     |
|Albuquerque            |GPE      |
|New Mexico             |GPE      |
|Gates                  |ORG      |
|January 2000           |DATE     |
|the late 1990s         |DATE     |
|Gates                  |PERSON   |
+-----------------------+---------+

Model Information

Model Name: onto_small_bert_L4_256
Type: ner
Compatibility: Spark NLP 2.7.0+
License: Open Source
Edition: Official
Input Labels: [sentence, token, embeddings]
Output Labels: [ner]
Language: en

Data Source

The model is trained based on data from OntoNotes 5.0

Benchmarking

Micro-average:

prec: 0.8617996, rec: 0.85458803, f1: 0.8581787

CoNLL Eval:

processed 152728 tokens with 11257 phrases; found: 11191 phrases; correct: 9476.
accuracy:  97.05%; 9476 11257 11191 precision:  84.68%; recall:  84.18%; FB1:  84.43
CARDINAL:  771  935  934 precision:  82.55%; recall:  82.46%; FB1:  82.50  934
DATE:  1383  1602  1645 precision:  84.07%; recall:  86.33%; FB1:  85.19  1645
EVENT:   29   63   49 precision:  59.18%; recall:  46.03%; FB1:  51.79  49
FAC:   65  135  100 precision:  65.00%; recall:  48.15%; FB1:  55.32  100
GPE:  2054  2240  2211 precision:  92.90%; recall:  91.70%; FB1:  92.29  2211
LANGUAGE:   10   22   13 precision:  76.92%; recall:  45.45%; FB1:  57.14  13
LAW:   11   40   22 precision:  50.00%; recall:  27.50%; FB1:  35.48  22
LOC:  112  179  186 precision:  60.22%; recall:  62.57%; FB1:  61.37  186
MONEY:  272  314  317 precision:  85.80%; recall:  86.62%; FB1:  86.21  317
NORP:  781  841  856 precision:  91.24%; recall:  92.87%; FB1:  92.04  856
ORDINAL:  172  195  228 precision:  75.44%; recall:  88.21%; FB1:  81.32  228
ORG:  1383  1795  1749 precision:  79.07%; recall:  77.05%; FB1:  78.05  1749
PERCENT:  311  349  346 precision:  89.88%; recall:  89.11%; FB1:  89.50  346
PERSON:  1809  1988  2048 precision:  88.33%; recall:  91.00%; FB1:  89.64  2048
PRODUCT:   34   76   50 precision:  68.00%; recall:  44.74%; FB1:  53.97  50
QUANTITY:   83  105  106 precision:  78.30%; recall:  79.05%; FB1:  78.67  106
TIME:  138  212  228 precision:  60.53%; recall:  65.09%; FB1:  62.73  228
WORK_OF_ART:   58  166  103 precision:  56.31%; recall:  34.94%; FB1:  43.12  103