Instructions to use LuisRey6/es_ner_sm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- spaCy
How to use LuisRey6/es_ner_sm with spaCy:
!pip install https://huggingface.co/LuisRey6/es_ner_sm/resolve/main/es_ner_sm-any-py3-none-any.whl # Using spacy.load(). import spacy nlp = spacy.load("es_ner_sm") # Importing as module. import es_ner_sm nlp = es_ner_sm.load() - Notebooks
- Google Colab
- Kaggle
es_ner_sm
A small, CPU-friendly spaCy pipeline for Spanish named entity recognition (PER, ORG, LOC), tuned for Mexican legal text: court bulletins, case law, contracts, party names written in capitals. MIT-licensed, commercial use allowed.
| Feature | Value |
|---|---|
| Name | es_ner_sm |
| Version | 0.1.0 |
| spaCy | >=3.8.18,<3.9.0 |
| Pipeline | tok2vec, ner |
| Labels | PER, ORG, LOC |
| Vectors | none |
| License | MIT |
| Author | Luis Reyes Aldaco (legalatlas.io) |
Installation
pip install https://huggingface.co/LuisRey6/es_ner_sm/resolve/main/es_ner_sm-0.1.0-py3-none-any.whl
Usage
import spacy
nlp = spacy.load("es_ner_sm")
doc = nlp("El quejoso JUAN CARLOS PÉREZ LÓPEZ, vecino de Oaxaca de Juárez, demandó a Comercializadora "
"del Norte, S.A. de C.V. ante el Juzgado Quinto de lo Familiar de la Ciudad de México.")
print([(e.text, e.label_) for e in doc.ents])
# [('JUAN CARLOS PÉREZ LÓPEZ', 'PER'), ('Oaxaca de Juárez', 'LOC'),
# ('Comercializadora del Norte, S.A. de C.V.', 'ORG'),
# ('Juzgado Quinto de lo Familiar de la Ciudad de México', 'ORG')]
Annotation scheme
- PER: people, in any capitalization; a full name is one span. Titles and roles (C., Lic., ministro, quejoso) are not part of the span.
- ORG: companies with their legal form, courts and tribunals with their full name, public bodies, banks, parties, universities. Laws and codes are not ORG.
- LOC: countries, states, cities, municipalities, colonias (without the word "colonia"), streets.
Accuracy
CoNLL-2002 Spanish, test (news from Spain, 2000; used only for evaluation, never for training):
| F1 | PER | ORG | LOC |
|---|---|---|---|
| es_ner_sm 0.1.0 | 0.849 | 0.650 | 0.708 |
| es_core_news_md 3.8 (GPL-3.0) | 0.847 | 0.656 | 0.658 |
Mexican legal text (held out, never trained on; labels made by the same annotator as the training data): 1,016 sentences from 400 SJF tesis and 1,000 court-bulletin fragments. "Names left visible" is the share of characters of person names not covered by any PER span, which is what matters for anonymization.
| Tesis PER F1 | Tesis ORG F1 | Bulletin PER F1 | Bulletin ORG F1 | Bulletin: names left visible | |
|---|---|---|---|---|---|
| es_ner_sm 0.1.0 | 0.967 | 0.604 | 0.851 | 0.670 | 12.2 % |
| es_core_news_md 3.8 | 0.469 | 0.256 | 0.169 | 0.039 | 77.3 % |
Most bulletin names are written in capitals. If text in capitals is first converted to title case (as the Anonimizador app does), the share of bulletin names left visible drops to 4.8 % (es_core_news_md: 8.5 %).
Reference: Claude Haiku 5.5, the annotator, scores PER 0.966 / ORG 0.805 / LOC 0.917 on 400 sentences of CoNLL-2002 validation.
Training data
About 197,000 sentences, annotated automatically with Claude Haiku 5.5 (Anthropic, via the API) using a fixed annotation guide; no human correction.
| Source | Sentences | License |
|---|---|---|
| Spanish Wikinews | ~107,000 | CC BY 2.5 |
| Synthetic legal sentences (templates written by Claude Haiku, filled with invented names, companies and places) | ~28,600 | — |
| Tesis of the Semanario Judicial de la Federación (5,600 tesis) | ~14,700 (×2) | judicial text, not protected by copyright (art. 14 LFDA) |
| Mexican court-bulletin fragments | ~11,000 (×2) | judicial text, not protected by copyright (art. 14 LFDA) |
Court bulletins name real parties. Every person name in the bulletin fragments was replaced before training with a fictitious one: first names and surnames drawn at random from words that occur in at least five different fragments, recombined so that no real person is reproduced, keeping the shape and capitalization of the original. Plus 3 % of sentences copied in capitals and 6 % with only person names in capitals.
The pipeline does not contain or redistribute the training text: the vocabulary string store is empty (embeddings are hashed), and predictions were checked to be identical with and without it.
Limitations
- ORG is the weakest label; long court names are sometimes cut.
- The annotations are machine-made; systematic errors of the annotator are learned by the model, and the legal evaluation uses labels from the same annotator.
- Names written in capitals are less reliable than names in normal case.
- Tuned for Mexican usage; Spanish from other countries works (see CoNLL-2002) but was not the focus.
- Downloads last month
- 22
Evaluation results
- PER F1 on CoNLL-2002 Spanish (test)self-reported0.849
- ORG F1 on CoNLL-2002 Spanish (test)self-reported0.650
- LOC F1 on CoNLL-2002 Spanish (test)self-reported0.708