Introduction
This is a zero-shot relation extractor based on the paper Exploring the zero-shot limit of FewRel.
Installation
$ pip install zero-shot-re
Run the Extractor
from transformers import AutoTokenizer
from zero_shot_re import RelTaggerModel, RelationExtractor
model = RelTaggerModel.from_pretrained("fractalego/fewrel-zero-shot")
tokenizer = AutoTokenizer.from_pretrained("fractalego/fewrel-zero-shot")
relations = ['noble title', 'founding date', 'occupation of a person']
extractor = RelationExtractor(model, tokenizer, relations)
ranked_rels = extractor.rank(text='John Smith received an OBE', head='John Smith', tail='OBE')
print(ranked_rels)
with results
[('noble title', 0.9690611883997917),
('occupation of a person', 0.0012609362602233887),
('founding date', 0.00024014711380004883)]
Accuracy
The results as in the paper are
| Model | 0-shot 5-ways | 0-shot 10-ways |
|---|---|---|
| (1) Distillbert | 70.1±0.5 | 55.9±0.6 |
| (2) Bert Large | 80.8±0.4 | 69.6±0.5 |
| (3) Distillbert + SQUAD | 81.3±0.4 | 70.0±0.2 |
| (4) Bert Large + SQUAD | 86.0±0.6 | 76.2±0.4 |
This version uses the (4) Bert Large + SQUAD model
Cite as
@inproceedings{cetoli-2020-exploring,
title = "Exploring the zero-shot limit of {F}ew{R}el",
author = "Cetoli, Alberto",
booktitle = "Proceedings of the 28th International Conference on Computational Linguistics",
month = dec,
year = "2020",
address = "Barcelona, Spain (Online)",
publisher = "International Committee on Computational Linguistics",
url = "https://www.aclweb.org/anthology/2020.coling-main.124",
doi = "10.18653/v1/2020.coling-main.124",
pages = "1447--1451",
abstract = "This paper proposes a general purpose relation extractor that uses Wikidata descriptions to represent the relation{'}s surface form. The results are tested on the FewRel 1.0 dataset, which provides an excellent framework for training and evaluating the proposed zero-shot learning system in English. This relation extractor architecture exploits the implicit knowledge of a language model through a question-answering approach.",
}
Metadata
Release files for zero-shot-re 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zero-shot-re-0.0.4.tar.gz | 4.0 kB | Without provenance | Details for zero-shot-re-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zero_shot_re-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for zero_shot_re-0.0.4-py3-none-any.whl |
Total release size: 10.6 kB
Release files / zero-shot-re-0.0.4.tar.gz
| Download URL | zero-shot-re-0.0.4.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8963c6b186a0582b200c8afdc17f5a9ec3ef399ff1f7a2107ddeea59c4ab989d
|
|
BLAKE2b-256 checksum How to use checksums |
c98a088aa86607c062543fcb0d990b6aa1d22a6c9e8d338184c7bc3b6b7cf861
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.6.9
|
Release files / zero_shot_re-0.0.4-py3-none-any.whl
| Download URL | zero_shot_re-0.0.4-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb185bb86d3116fd320f3e1e92bcbd248087c737b0a635556d77de62095adeb6
|
|
BLAKE2b-256 checksum How to use checksums |
3a30fb452a4ae973eb13f18afd90d0437c1e953bf7824fa0a64025b861be576d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.6.9
|
Security for zero-shot-re 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.