百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
Z

zshot

> 数据库
开源

零样本和少样本命名实体与关系识别

400 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

零样本和少样本命名实体与关系识别

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:

  • Mentions extraction: Identify globally relevant mentions or mentions relevant for a given domain
  • Wikification: The task of linking textual mentions to entities in Wikipedia
  • Zero and Few Shot named entity recognition: using language description perform NER to generalize to unseen domains
  • Zero and Few Shot named relationship recognition
  • Visualization: Zero-shot NER and RE extraction

Requirements

  • 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).

Optional Dependencies

  • flair - Required if you want to use Flair mentions extractor and for TARS linker and TARS Mentions Extractor.
  • blink - Required if you want to use Blink for linking to Wikipedia pages.
  • gliner - Required if you want to use GLiNER Linker or GLiNER Mentions Extractor.
  • relik - Required if you want to use Relik Linker.

Installation

Examples

Example Notebook
Installation and Visualization
Knowledge Extractor
Wikification
Custom Components
Evaluation

Zshot Approach

ZShot contains two different components, the mentions extractor and the linker.

Mentions Extractor

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.

Linker

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

Relations Extractor

The relations extractor will extract relations among different entities previously extracted by a linker..

Currently, the is only one Relation Extractor available:

  • ZS-Bert
    • Paper
    • Source Code

Knowledge Extractor

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:

  • KnowGL

    • Rossiello et al. (AAAI 2023)
    • Mihindukulasooriya et al. (ISWC 2022)
  • Relik

    • Paper
    • Source Code

How to use it

  • Install requirements: pip install -r requirements.txt
  • Install a spacy pipeline to use it for mentions extraction: python -m spacy download en_core_web_sm
  • Create a file main.py with the pipeline configuration and entities definition (Wikipedia abstract are usually a good starting point for descriptions):
…

Run it

Run with

bash
$ 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

Check it

Open your browser at http://127.0.0.1:5000 .

You will see the annotated sentence:

How to create a custom component

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:

…

How to evaluate ZShot

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:

…

Citation

…

Issues· 6 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Pythonaideep-learningfew-shotfew-shot-learning

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库