Skip to main content
https://travis-ci.org/jantrienes/nereval.svg?branch=master

Evaluation script for named entity recognition (NER) systems based on entity-level F1 score.

Definition

The metric as implemented here has been described by Nadeau and Sekine (2007) and was widely used as part of the Message Understanding Conferences (Grishman and Sundheim, 1996). It evaluates an NER system according to two axes: whether it is able to assign the right type to an entity, and whether it finds the exact entity boundaries. For both axes, the number of correct predictions (COR), the number of actual predictions (ACT) and the number of possible predictions (POS) are computed. From these statistics, precision and recall can be derived:

precision = COR/ACT
recall = COR/POS

The final score is the micro-averaged F1 measure of precision and recall of both type and boundary axes.

Installation

pip install nereval

Usage

The script can either be used from within Python or from the command line when classification results have been written to a JSON file.

Usage from Command Line

Assume we have the following classification results in input.json:

[
  {
    "text": "CILINDRISCHE PLUG",
    "true": [
      {
        "text": "CILINDRISCHE PLUG",
        "type": "Productname",
        "start": 0
      }
    ],
    "predicted": [
      {
        "text": "CILINDRISCHE",
        "type": "Productname",
        "start": 0
      },
      {
        "text": "PLUG",
        "type": "Productname",
        "start": 13
      }
    ]
  }
]

Then the script can be executed as follows:

python nereval.py input.json
F1-score: 0.33

Usage from Python

Alternatively, the evaluation metric can be directly invoked from within python. Example:

import nereval
from nereval import Entity

# Ground-truth:
# CILINDRISCHE PLUG
# B_PROD       I_PROD
y_true = [
    Entity('CILINDRISCHE PLUG', 'Productname', 0)
]

# Prediction:
# CILINDRISCHE PLUG
# B_PROD       B_PROD
y_pred = [
    # correct type, wrong text
    Entity('CILINDRISCHE', 'Productname', 0),
    # correct type, wrong text
    Entity('PLUG', 'Productname', 13)
]

score = nereval.evaluate([y_true], [y_pred])
print('F1-score: %.2f' % score)
F1-score: 0.33

Note on Symmetry

The metric itself is not symmetric due to the inherent problem of word overlaps in NER. So evaluate(y_true, y_pred) != evaluate(y_pred, y_true). This comes apparent if we consider the following example (tagger uses an BIO scheme):

# Example 1:
Input:     CILINDRISCHE PLUG     DIN908  M10X1   Foo
Truth:     B_PROD       I_PROD   B_PROD  B_DIM   O
Predicted: B_PROD       B_PROD   B_PROD  B_PROD  B_PROD

Correct Text: 2
Correct Type: 2

# Example 2 (inversed):
Input:     CILINDRISCHE PLUG     DIN908  M10X1   Foo
Truth:     B_PROD       B_PROD   B_PROD  B_PROD  B_PROD
Predicted: B_PROD       I_PROD   B_PROD  B_DIM   O

Correct Text: 2
Correct Type: 3

Notes and References

Used in a student research project on natural language processing at University of Twente, Netherlands.

References

Metadata

Release files for nereval 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nereval 0.2.5
File Size Uploaded Provenance Actions
nereval-0.2.5.tar.gz 4.4 kB Without provenance Details for nereval-0.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nereval 0.2.5
File Interpreter ABI Platform Actions
nereval-0.2.5-py2.py3-none-any.whl Python 3, Python 2 none any Details for nereval-0.2.5-py2.py3-none-any.whl

Total release size: 8.8 kB

Release files / nereval-0.2.5.tar.gz

Download URL nereval-0.2.5.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0815d461c0ae9cb0aef74f63554d940f203eb7ce7fc68edd3f0c92babf431349
BLAKE2b-256 checksum
How to use checksums
73fc63f506f1a8cc796428c04bcbaf3ef1c5287e7df031053f21e7fec2675239
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / nereval-0.2.5-py2.py3-none-any.whl

Download URL nereval-0.2.5-py2.py3-none-any.whl
Size 4.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b1c8dbc9851746405c8ca57397b8b70e23661e347acb0058d095bc405590637b
BLAKE2b-256 checksum
How to use checksums
7ec12964c11404decf05adf677890c741a65f54c4954f3b441b79a7db241430b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for nereval 0.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page