spacy-to-hf
A simple converter from Spacy Entities to Huggingface BILOU formatted data
I've always struggled to convert my spacy formatted spans into data that can be trained on using huggingface transformers. But Spacy's Entity format is the most intuitive format for tagging entities for NER.
This repo is a simple converter that leverages spacy.gold.biluo_tags_from_offsets
and the SpaCy tokenizations repo that creates a 1-line function to convert spacy
formatted spans to tokens and ner_tags that can be fed into any
Token Classification Transformer
Installation
pip install spacy-to-hf
python -m spacy download en_core_web_sm
Usage
from spacy_to_hf import spacy_to_hf
from datasets import Dataset
span_data = [
{
"text": "I have a BSc (Bachelors of Computer Sciences) from NYU",
"spans": [
{"start": 9, "end": 12, "label": "degree"},
{"start": 14, "end": 44, "label": "degree"},
{"start": 51, "end": 54, "label": "university"}
]
}
]
hf_data = spacy_to_hf(span_data, "bert-base-cased")
print(list(zip(hf_data["tokens"][0], hf_data["ner_tags"][0])))
ds = Dataset.from_dict(hf_data)
From here, you can label-index your ner_tags and prepare for fine-tuning
Project Setup
Project setup is credited to @anthonycorletti and his awesome repo https://github.com/anthonycorletti/python-project-template
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spacy-to-hf-0.0.1.tar.gz.
File metadata
- Download URL: spacy-to-hf-0.0.1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f9ae9953e42cd1c2c97d79cc957dac193ef3266186fdf748ab35dba6082cf17
|
|
| MD5 |
e0104922678f9bd48f08251001116f22
|
|
| BLAKE2b-256 |
d34993a259035adb4d699709ffa86ec6047d379b0905d27a8869613638876c82
|
File details
Details for the file spacy_to_hf-0.0.1-py3-none-any.whl.
File metadata
- Download URL: spacy_to_hf-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e98257194547e3aa10bc4a2ddb274744444d70cf5ceed66b83f0cece8c2e2426
|
|
| MD5 |
f6078e11f444f837994dd1c85b4f2790
|
|
| BLAKE2b-256 |
aecf8378588a60157acc79a231d6c1b2612abadc4bc75c041f48c8ace44fa352
|