Sequence Tagger for Partially Annotated Dataset in spaCy
Project description
spacy-partial-tagger
This is a library to build a CRF tagger for a partially annotated dataset in spaCy. You can build your own NER tagger only from dictionary. The algorithm of this tagger is based on Effland and Collins. (2021).
Overview
Dataset Preparation
Prepare spaCy binary format file to train your tagger. If you are not familiar with spaCy binary format, see this page.
You can prepare your own dataset with spaCy's entity ruler as follows:
import spacy
from spacy.tokens import DocBin
nlp = spacy.blank("en")
patterns = [{"label": "LOC", "pattern": "Tokyo"}, {"label": "LOC", "pattern": "Japan"}]
ruler = nlp.add_pipe("entity_ruler")
ruler.add_patterns(patterns)
doc = nlp("Tokyo is the capital of Japan.")
doc_bin = DocBin()
doc_bin.add(doc)
# Replace /path/to/data.spacy with your own path
doc_bin.to_disk("/path/to/data.spacy")
Training
Train your tagger as follows:
python -m spacy train config.cfg --output outputs --paths.train /path/to/train.spacy --paths.dev /path/to/dev.spacy --gpu-id 0
This library is implemented as a trainable component in spaCy, so you could control the training setting via spaCy's configuration system. We provide you the default configuration file here. Or you could setup your own. If you are not familiar with spaCy's config file format, please check the documentation.
Don't forget to replace /path/to/train.spacy
and /path/to/dev.spacy
with your own.
Evaluation
Evaluate your tagger as follows:
python -m spacy evaluate outputs/model-best /path/to/test.spacy --gpu-id 0
Don't forget to replace /path/to/test.spacy
with your own.
Installation
pip install spacy-partial-tagger
If you use M1 Mac, you might have problems installing fugashi
. In that case, please try brew install mecab
before the installation.
References
- Thomas Effland and Michael Collins. 2021. Partially Supervised Named Entity Recognition via the Expected Entity Ratio Loss. Transactions of the Association for Computational Linguistics, 9:1320–1335.
Project details
Release history Release notifications | RSS feed
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
Hashes for spacy_partial_tagger-0.15.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e640f9f0a5a2ee458f8e5937eec6b762f5f712ac46780f823a0c4b89b6df0dde |
|
MD5 | c8fa080b9afb15579e690b3f929c59e5 |
|
BLAKE2b-256 | fc5441be759fd1bc9cad38c66b9b18706bfc1c561abdeeb526f1e25601532a87 |
Hashes for spacy_partial_tagger-0.15.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c4f492d47c33c1aee789db93d3e4d1ed5c5f324111f2ce67136a633f42e5b38 |
|
MD5 | 8eff68862c550254d72f8031a3286277 |
|
BLAKE2b-256 | e6b0baab6155b66adea6d7fa8968cd593035769b04600228173243ddcd9534b5 |