零样本和少样本命名实体与关系识别
Documentation: https://ibm.github.io/zshot
Source Code: https://github.com/IBM/zshot
Paper: https://aclanthology.org/2023.acl-demo.34/
Zshot is a highly customisable framework for performing Zero and Few shot named entity recognition.
Can be used to perform:
Python 3.6+
spacy - Zshot rely on Spacy for pipelining and visualization
torch - PyTorch is required to run pytorch models.
transformers - Required for pre-trained language models.
evaluate - Required for evaluation.
datasets - Required to evaluate over datasets (e.g.: OntoNotes).
| Example | Notebook |
|---|---|
| Installation and Visualization | |
| Knowledge Extractor | |
| Wikification | |
| Custom Components | |
| Evaluation |
ZShot contains two different components, the mentions extractor and the linker.
The mentions extractor will detect the possible entities (a.k.a. mentions), that will be then linked to a data source (e.g.: Wikidata) by the linker.
Currently, there are 7 different mentions extractors supported, SMXM, TARS, GLiNER, 2 based on SpaCy, and 2 that are based on Flair. The two different versions for SpaCy and Flair are similar, one is based on Named Entity Recognition and Classification (NERC) and the other one is based on the linguistics (i.e.: using Part Of the Speech tagging (PoS) and Dependency Parsing(DP)).
The NERC approach will use NERC models to detect all the entities that have to be linked. This approach depends on the model that is being used, and the entities the model has been trained on, so depending on the use case and the target entities it may be not the best approach, as the entities may be not recognized by the NERC model and thus won't be linked.
The linguistic approach relies on the idea that mentions will usually be a syntagma or a noun. Therefore, this approach detects nouns that are included in a syntagma and that act like objects, subjects, etc. This approach do not depend on the model (although the performance does), but a noun in a text should be always a noun, it doesn't depend on the dataset the model has been trained on.
The linker will link the detected entities to a existing set of labels. Some of the linkers, however, are end-to-end, i.e. they don't need the mentions extractor, as they detect and link the entities at the same time.
Again, there are 6 linkers available currently, 4 of them are end-to-end and 2 are not.
| Linker Name | end-to-end | Source Code | Paper |
|---|---|---|---|
| Blink | X | Source Code | Paper |
| GENRE | X | Source Code | Paper |
| SMXM | ✓ | Source Code | Paper |
| TARS | ✓ | Source Code | Paper |
| GLINER | ✓ | Source Code | Paper |
| RELIK | ✓ | Source Code | Paper |
The relations extractor will extract relations among different entities previously extracted by a linker..
Currently, the is only one Relation Extractor available:
The knowledge extractor will perform at the same time the extraction and classification of named entities and the extraction of relations among them. The pipeline with this component doesn't need any mentions extractor, linker or relation extractor to work.
Currently, there are only two Knowledge Extractor available:
pip install -r requirements.txtpython -m spacy download en_core_web_smmain.py with the pipeline configuration and entities definition (Wikipedia abstract are usually a good starting point for descriptions):…Run with
$ python main.py
Using the 'ent' visualizer
Serving on http://0.0.0.0:5000 ...The script will annotate the text using Zshot and use Displacy for visualising the annotations
Open your browser at http://127.0.0.1:5000 .
You will see the annotated sentence:
If you want to implement your own mentions_extractor or linker and use it with ZShot you can do it. To make it easier for the user to implement a new component, some base classes are provided that you have to extend with your code.
It is as simple as create a new class extending the base class (MentionsExtractor or Linker). You will have to implement the predict method, which will receive the SpaCy Documents and will return a list of zshot.utils.data_models.Span for each document.
This is a simple mentions_extractor that will extract as mentions all words that contain the letter s:
…Evaluation is an important process to keep improving the performance of the models, that's why ZShot allows to evaluate the component with two predefined datasets: OntoNotes and MedMentions, in a Zero-Shot version in which the entities of the test and validation splits don't appear in the train set.
The package evaluation contains all the functionalities to evaluate the ZShot components. The main function is zshot.evaluation.zshot_evaluate.evaluate, that will take as input the SpaCy nlp model and the dataset to evaluate. It will return a str containing a table with the results of the evaluation. For instance the evaluation of the TARS linker in ZShot for the Ontonotes validation set would be:
……暂无开放 Issues,或尚未同步最近议题。