Named Entity Recognition - ELECTRA Small (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 electra_small_uncased embeddgings 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

How to use

...
embeddings = BertEmbeddings.pretrained("electra_small_uncased", "en") \
      .setInputCols("sentence", "token") \
      .setOutputCol("embeddings")
ner_onto = NerDLModel.pretrained("onto_electra_small_uncased", "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(pd.DataFrame({'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."""]})))
...
val embeddings = BertEmbeddings.pretrained("electra_small_uncased", "en")
      .setInputCols(Array("sentence", "token"))
      .setOutputCol("embeddings")
val ner_onto = NerDLModel.pretrained("onto_electra_small_uncased", "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 result = pipeline.fit(Seq.empty["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."].toDS.toDF("text")).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.electra.uncased_small').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     |
|1970s                  |DATE     |
|1980s                  |DATE     |
|Seattle                |GPE      |
|Washington             |GPE      |
|Gates                  |PERSON   |
|Microsoft              |ORG      |
|Paul Allen             |PERSON   |
|1975                   |DATE     |
|Albuquerque            |GPE      |
|New Mexico             |GPE      |
|Gates                  |PERSON   |
|January 2000           |DATE     |
|the late 1990s         |DATE     |
+-----------------------+---------+

Model Information

Model Name: onto_electra_small_uncased
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.87234557, rec: 0.8584134, f1: 0.8653234 

CoNLL Eval:

processed 152728 tokens with 11257 phrases; found: 11149 phrases; correct: 9598.
accuracy:  97.22%; 9598 11257 11149 precision:  86.09%; recall:  85.26%; FB1:  85.67
         CARDINAL:  789  935  948 precision:  83.23%; recall:  84.39%; FB1:  83.80  948
             DATE:  1400  1602  1659 precision:  84.39%; recall:  87.39%; FB1:  85.86  1659
            EVENT:   31   63   50 precision:  62.00%; recall:  49.21%; FB1:  54.87  50
              FAC:   72  135  111 precision:  64.86%; recall:  53.33%; FB1:  58.54  111
              GPE:  2086  2240  2197 precision:  94.95%; recall:  93.12%; FB1:  94.03  2197
         LANGUAGE:    8   22   10 precision:  80.00%; recall:  36.36%; FB1:  50.00  10
              LAW:   21   40   34 precision:  61.76%; recall:  52.50%; FB1:  56.76  34
              LOC:  114  179  201 precision:  56.72%; recall:  63.69%; FB1:  60.00  201
            MONEY:  282  314  321 precision:  87.85%; recall:  89.81%; FB1:  88.82  321
             NORP:  786  841  848 precision:  92.69%; recall:  93.46%; FB1:  93.07  848
          ORDINAL:  180  195  227 precision:  79.30%; recall:  92.31%; FB1:  85.31  227
              ORG:  1359  1795  1616 precision:  84.10%; recall:  75.71%; FB1:  79.68  1616
          PERCENT:  312  349  349 precision:  89.40%; recall:  89.40%; FB1:  89.40  349
           PERSON:  1852  1988  2059 precision:  89.95%; recall:  93.16%; FB1:  91.52  2059
          PRODUCT:   32   76   69 precision:  46.38%; recall:  42.11%; FB1:  44.14  69
         QUANTITY:   86  105  105 precision:  81.90%; recall:  81.90%; FB1:  81.90  105
             TIME:  124  212  207 precision:  59.90%; recall:  58.49%; FB1:  59.19  207
      WORK_OF_ART:   64  166  138 precision:  46.38%; recall:  38.55%; FB1:  42.11  138