span-marker pytorch safetensors token-classification ner named-entity-recognition en dataset:conll2003 dataset:tomaarsen/conll2003 base_model:FacebookAI/xlm-roberta-large base_model:finetune:FacebookAI/xlm-roberta-large license:apache-2.0 model-index region:us
---
base_model: xlm-roberta-large
datasets:
- conll2003
- tomaarsen/conll2003
language:
- en
library_name: span-marker
license: apache-2.0
metrics:
- f1
- recall
- precision
pipeline_tag: token-classification
tags:
- span-marker
- token-classification
- ner
- named-entity-recognition
widget:
- text: Amelia Earhart flew her single engine Lockheed Vega 5B across the Atlantic
    to Paris.
  example_title: Amelia Earhart
model-index:
- name: SpanMarker w. xlm-roberta-large on CoNLL03 with document-level context by
    Tom Aarsen
  results:
  - task:
      type: token-classification
      name: Named Entity Recognition
    dataset:
      name: CoNLL03 w. document context
      type: conll2003
      split: test
      revision: 01ad4ad271976c5258b9ed9b910469a806ff3288
    metrics:
    - type: f1
      value: 0.9442
      name: F1
    - type: precision
      value: 0.9411
      name: Precision
    - type: recall
      value: 0.9473
      name: Recall
---

# SpanMarker for Named Entity Recognition

This is a [SpanMarker](https://github.com/tomaarsen/SpanMarkerNER) model that can be used for Named Entity Recognition. In particular, this SpanMarker model uses [xlm-roberta-large](https://huggingface.co/xlm-roberta-large) as the underlying encoder. See [train.py](train.py) for the training script.
Note that this model was trained with document-level context, i.e. it will primarily perform well when provided with enough context. It is recommended to call `model.predict` with a 🤗 Dataset with `tokens`, `document_id` and `sentence_id` columns.
See the [documentation](https://tomaarsen.github.io/SpanMarkerNER/api/span_marker.modeling.html#span_marker.modeling.SpanMarkerModel.predict) of the `model.predict` method for more information.

## Usage

To use this model for inference, first install the `span_marker` library:

```bash
pip install span_marker
```

You can then run inference with this model like so:

```python
from span_marker import SpanMarkerModel

# Download from the 🤗 Hub
model = SpanMarkerModel.from_pretrained("tomaarsen/span-marker-xlm-roberta-large-conll03-doc-context")
# Run inference
entities = model.predict("Amelia Earhart flew her single engine Lockheed Vega 5B across the Atlantic to Paris.")
```

### Limitations

**Warning**: This model works best when punctuation is separated from the prior words, so 
```python
# ✅
model.predict("He plays J. Robert Oppenheimer , an American theoretical physicist .")
# ❌
model.predict("He plays J. Robert Oppenheimer, an American theoretical physicist.")

# You can also supply a list of words directly: ✅
model.predict(["He", "plays", "J.", "Robert", "Oppenheimer", ",", "an", "American", "theoretical", "physicist", "."])
```
The same may be beneficial for some languages, such as splitting `"l'ocean Atlantique"` into `"l' ocean Atlantique"`.

See the [SpanMarker](https://github.com/tomaarsen/SpanMarkerNER) repository for documentation and additional information on this library.