


# spaCy Custom Spancat trained on Diderot & d’Alembert’s Encyclopédie entries


<!-- Provide a quick summary of what the model is/does. -->

This model is designed to identify and classify text spans corresponding to named entities (such as Spatial, Person, and MISC), as well as nested named entities (including Spatial, Person, and MISC), spatial relations, and other relevant information within French encyclopedic entries.

The spans detected by this model are:
- **NC-Spatial**: a common noun that identifies a spatial entity (nominal spatial entity) including natural features, e.g. `ville`, `la rivière`, `royaume`.
- **NP-Spatial**: a proper noun identifying the name of a place (spatial named entities), e.g. `France`, `Paris`, `la Chine`.
- **ENE-Spatial**: nested spatial entity , e.g. `ville de France`, `royaume de Naples`, `la mer Baltique`.
- **Relation**: spatial relation, e.g. `dans`, `sur`, `à 10 lieues de`.
- **Latlong**: geographic coordinates, e.g. `Long. 19. 49. lat. 43. 55. 44.`
- **NC-Person**: a common noun that identifies a person (nominal spatial entity), e.g. `roi`, `l'empereur`, `les auteurs`.
- **NP-Person**: a proper noun identifying the name of a person (person named entities), e.g. `Louis XIV`, `Pline`, `les Romains`.
- **ENE-Person**: nested people entity, e.g. `le czar Pierre`, `roi de Macédoine`
- **NP-Misc**: a proper noun identifying entities not classified as spatial or person, e.g. `l'Eglise`, `1702`, `Pélasgique`.
- **ENE-Misc**: nested named entity not classified as spatial or person, e.g. `l'ordre de S. Jacques`, `la déclaration du 21 Mars 1671`.
- **Head**: entry name
- **Domain-Mark**: words indicating the knowledge domain (usually after the head and between parenthesis), e.g. `Géographie`, `Geog.`, `en Anatomie`.

  
## Model Description

<!-- Provide a longer summary of what this model is. -->

- **Developed by:** [Ludovic Moncla](https://ludovicmoncla.github.io), [Katherine McDonough](https://www.lancaster.ac.uk/dsi/about-us/members/katherine-mcdonough#projects) and [Denis Vigier](http://www.icar.cnrs.fr/membre/dvigier/) in the framework of the [GEODE](https://geode-project.github.io) project.
- **Model type:** spaCy Span Categorization
- **spaCy**: `>=3.7.2,<3.8.0`
- **Components**: `tok2vec`, `spancat`
- **Repository:** [https://github.com/GEODE-project/ner-spancat-edda](https://github.com/GEODE-project/ner-spancat-edda)
- **Language(s) (NLP):** French
- **License:** cc-by-nc-4.0
- **Dataset:** https://zenodo.org/records/10530178


## Bias, Risks, and Limitations

<!-- This section is meant to convey both technical and sociotechnical limitations. -->

This model was trained entirely on French encyclopaedic entries and will likely not perform well on text in other languages or other corpora. 


## How to Get Started with the Model

Use the code below to get started with the model.

```bash
pip install https://huggingface.co/GEODE/fr_spacy_custom_spancat_edda/resolve/main/fr_spacy_custom_spancat_edda-any-py3-none-any.whl
```

```python
# Using spacy.load().
import spacy
nlp = spacy.load("fr_spacy_custom_spancat_edda")

# Importing as module.
import fr_spacy_custom_spancat_edda
nlp = fr_spacy_custom_spancat_edda.load()
doc = nlp("* ALBI, (Géog.) ville de France, capitale de  l'Albigeois, dans le haut Languedoc : elle est sur le Tarn. Long. 19. 49. lat. 43. 55. 44.")

spans = []

for span in doc.spans['sc']:
  spans.append({
      "start": span.start_char,
      "end": span.end_char,
      "labels": [span.label_],
      "text": span.text
  })

print(spans)

# Output
[{'start': 2, 'end': 6, 'labels': ['Head'], 'text': 'ALBI'},
 {'start': 16, 'end': 21, 'labels': ['NC-Spatial'], 'text': 'ville'},
 {'start': 25, 'end': 31, 'labels': ['NP-Spatial'], 'text': 'France'},
 {'start': 33, 'end': 41, 'labels': ['NC-Spatial'], 'text': 'capitale'},
 {'start': 59, 'end': 63, 'labels': ['Relation'], 'text': 'dans'},
 {'start': 93, 'end': 96, 'labels': ['Relation'], 'text': 'sur'},
 {'start': 9, 'end': 14, 'labels': ['Domain-mark'], 'text': 'Géog.'},
 {'start': 46, 'end': 57, 'labels': ['NP-Spatial'], 'text': "l'Albigeois"},
 {'start': 97, 'end': 104, 'labels': ['NP-Spatial'], 'text': 'le Tarn'},
 {'start': 16,
  'end': 31,
  'labels': ['ENE-Spatial'],
  'text': 'ville de France'},
 {'start': 64,
  'end': 81,
  'labels': ['NP-Spatial'],
  'text': 'le haut Languedoc'},
 {'start': 33,
  'end': 57,
  'labels': ['ENE-Spatial'],
  'text': "capitale de  l'Albigeois"},
 {'start': 33,
  'end': 81,
  'labels': ['ENE-Spatial'],
  'text': "capitale de  l'Albigeois, dans le haut Languedoc"},
 {'start': 16,
  'end': 81,
  'labels': ['ENE-Spatial'],
  'text': "ville de France, capitale de  l'Albigeois, dans le haut Languedoc"}]
```


## Training Details

### Training Data

<!-- This should link to a Data Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->

The model was trained using a set of 2200 paragraphs randomly selected out of 2001 Encyclopédie's entries. 
All paragraphs were written in French and are distributed as follows among the Encyclopédie knowledge domains:

| Knowledge domain | Paragraphs | 
|---|:---:|
| Géographie | 1096 | 
| Histoire | 259 | 
| Droit Jurisprudence | 113 | 
| Physique | 92 | 
| Métiers | 92 | 
| Médecine | 88 | 
| Philosophie | 69 | 
| Histoire naturelle | 65 | 
| Belles-lettres | 65 | 
| Militaire | 62 | 
| Commerce | 48 | 
| Beaux-arts | 44 | 
| Agriculture | 36 | 
| Chasse | 31 | 
| Religion | 23 | 
| Musique | 17 | 


The spans/entities were labeled by the project team along with using pre-labelling with early models to speed up the labelling process. 
A train/val/test split was used.
Validation and test sets are composed of 200 paragraphs each: 100 classified as 'Géographie' and 100 from another knowledge domain.
The datasets have the following breakdown of tokens and spans/entities. 

|   | Train | Validation | Test|
|---|:---:|:---:|:---:|
|Paragraphs| 1,800 | 200 | 200|
| Tokens | 134,254 | 15,167 | 14,079 |
| NC-Spatial | 3,268 | 358 | 357 |
| NP-Spatial | 4,719 | 464 | 522 |
| ENE-Spatial | 3,044 | 326 | 334 |
| Relation | 2,101 | 220 | 226 |
| Latlong | 553 | 66 | 72 |
| NC-Person | 1,378 | 132 | 133 |
| NP-Person | 1,603 | 170 | 150 |
| ENE-Person | 491 | 49 | 57 |
| NP-Misc | 953 | 108 | 96 |
| ENE-Misc | 255 | 31 | 22 |
| Head | 1,264 | 143 | 154 |
| Domain-Mark | 1,069 | 122 | 133 |


### Training Procedure 

<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->

For full training details and results please see the GitHub repository: [github.com/GEODE-project/ner-spancat-edda](https://github.com/GEODE-project/ner-spancat-edda)


### Evaluation

Evaluation is performed using the spacy [evaluate](https://spacy.io/api/cli#evaluate) command line interface:

* Overall model performances (Test set)

|   | Precision | Recall | F-score |
|---|:---:|:---:|:---:|
|     | 94.24   | 79.83   | 86.44 | 



* Model performances by entity (Test set)

|   | Precision | Recall | F-score |
|---|:---:|:---:|:---:|
| NC-Spatial    |  97.08  |  93.28  |  95.14 |
| NP-Spatial    |  92.74  |  95.40  |  94.05 |
| ENE-Spatial   |  92.22  |  95.81  |  93.98 |
| Relation      |  96.69  |  64.60  |  77.45 |
| Latlong       |  0.00   |  0.00   |  0.00  |
| NC-Person     |  93.07  |  70.68  |  80.34 |
| NP-Person     |  92.41  |  89.33  |  90.85 |
| ENE-Person    |  92.16  |  82.46  |  87.04 |
| NP-Misc       |  93.24  |  71.88  |  81.18 |
| ENE-Misc      |  0.00   |  0.00   |  0.00  |
| Head          |  97.44  |  24.68  |  39.38 |
| Domain-mark   |  99.19  |  91.73  |  95.31 |


## Acknowledgement


The authors are grateful to the [ASLAN project](https://aslan.universite-lyon.fr) (ANR-10-LABX-0081) of the Université de Lyon, for its financial support within the French program "Investments for the Future" operated by the National Research Agency (ANR).
Data courtesy the [ARTFL Encyclopédie Project](https://artfl-project.uchicago.edu), University of Chicago.

{"language": ["fr"], "license": "cc-by-nc-4.0", "library_name": "spacy", "tags": ["spacy", "token-classification"], "metrics": ["accuracy", "recall", "precision", "f1"], "pipeline_tag": "token-classification", "widget": [{"text": "* ALBI, (G\u00e9og.) ville de France, capitale de l'Albigeois, dans le haut Languedoc : elle est sur le Tarn. Long. 19. 49. lat. 43. 55. 44."}]}
spacy token-classification fr doi:10.57967/hf/1764 license:cc-by-nc-4.0 model-index region:us