CoolFace
Modelpublic

GEODE/bert-base-multilingual-cased-classification-ner

sourceHugging Facecc-by-nc-4.0updated 1y agoView on Hugging Face
0likes6downloads
Model Card

bert-base-multilingual-cased-classification-ner

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

This model is designed to classify place named entities recognized from geographic encyclopedia articles. It is a fine-tuned version of the bert-base-multilingual-cased model. It has been trained on GeoEDdA-TopoRel, a manually annotated subset of the French Encyclopédie ou dictionnaire raisonné des sciences des arts et des métiers par une société de gens de lettres (1751-1772) edited by Diderot and d'Alembert (provided by the ARTFL Encyclopédie Project).

Model Description

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

Class labels

The tagset is as follows:

  • City:
  • Country:
  • Human-made:
  • Island:
  • Lake:
  • Mountain:
  • Other:
  • Region:
  • River:
  • Sea:

Dataset

The model was trained using the GeoEDdA-TopoRel dataset. The dataset is splitted into train, validation and test sets which have the following distribution of entries among classes:

TrainValidationTest
City2,657276277
Country1,544239169
Human-made10477
Island55481109
Lake691511
Mountain2327670
Other2354739
Region2,706424440
River128944125
Sea1963757

Evaluation

  • Overall weighted-average model performances
PrecisionRecallF-score
0.840.840.84
  • Model performances (Test set)
PrecisionRecallF-scoreSupport
City0.820.880.85277
Country0.800.910.85169
Human-made0.500.710.597
Island0.790.760.78109
Lake1.000.640.7811
Mountain0.810.730.7770
Other0.680.490.5739
Region0.890.850.87440
River0.870.900.88125
Sea0.960.930.9557

How to Get Started with the Model

Use the code below to get started with the model.

python
import torch
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
device = torch.device("mps" if torch.backends.mps.is_available() else ("cuda" if torch.cuda.is_available() else "cpu"))

ner = pipeline("token-classification", model="GEODE/camembert-base-edda-span-classification", aggregation_strategy="simple", device=device)
placename_classifier = pipeline("text-classification", model="GEODE/bert-base-multilingual-cased-classification-ner", truncation=True, device=device)

def get_context(text, span, ngram_context_size=5):
    word = span["word"]
    start = span["start"]
    end = span["end"]
    label = span["entity_group"]

    # Extract context
    previous_text = text[:start].strip()
    next_text = text[end:].strip()
    previous_words = previous_text.split()[-ngram_context_size:]
    next_words = next_text.split()[:ngram_context_size]

    # Build context string
    context = f"[{word}]: {' '.join(previous_words)} {word} {' '.join(next_words)}"
    return word, context, label

content = "WINCHESTER, (Géog. mod.) ou plutôt Wintchester, ville d'Angleterre, capitale du Hampshire, sur le bord de l'Itching, à dix-huit milles au sud-est de Salisbury, & à soixante sud-ouest de Londres. Long. 16. 20. latit. 51. 3."

spans = ner(content)
for span in spans:
    if span['entity_group'] == 'NP_Spatial':
        word, context, label = get_context(content, span, ngram_context_size=5)
        print(f"Place name: {word}")

        label = placename_classifier(context)
        print(f"Predicted label: {label}")


# Output
Place name: Wintchester
Predicted label: [{'label': 'City', 'score': 0.9968810081481934}]
Place name: Angleterre
Predicted label: [{'label': 'Country', 'score': 0.9953059554100037}]
Place name: Hampshire
Predicted label: [{'label': 'Region', 'score': 0.9967537522315979}]
Place name: Itching
Predicted label: [{'label': 'River', 'score': 0.9929990768432617}]
Place name: Salisbury
Predicted label: [{'label': 'City', 'score': 0.9969013929367065}]
Place name: Londres
Predicted label: [{'label': 'City', 'score': 0.9969471096992493}]

Bias, Risks, and Limitations

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

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

Acknowledgement

The authors are grateful to the ASLAN project (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, University of Chicago.