Sequence Tagger for Partially Annotated Dataset in spaCy
Project description
spacy-partial-tagger
This is a CRF tagger for 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. This library expects tokenization is character-based. For more detail about 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
from spacy_partial_tagger.tokenizer import CharacterTokenizer
nlp = spacy.blank("en")
nlp.tokenizer = CharacterTokenizer(nlp.vocab) # Use a character-based tokenizer
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 model 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
You could download config.cfg
here.
Or you could setup your own. This library would train models through spaCy. 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 model 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 have problems installing pytokenizations
, please check this website and install Rust.
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.9.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0856cca177d9c2687ca70d41f171c84de32f8aeaabd100d0c214cc2dc6df6b70 |
|
MD5 | 1e398e846a22f523c6580557e74d4dbd |
|
BLAKE2b-256 | 01f3d95088142870c92dafc406574e810934d5f0ed6d49272c10c73c88e6f8f6 |
Hashes for spacy_partial_tagger-0.9.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e64347065a70f36a2702c9f5fedd7df8b8775aaa9976ffb87a395f4fffdea394 |
|
MD5 | a79b9482511f83ad29b47ee41e0a9d88 |
|
BLAKE2b-256 | badced2e6654e136316de7dc017df48800f2d86ddca0b166df35dc2da00d9de7 |