项目介绍:gliner_base
简介
GLiNER 是一种用于命名实体识别(NER)的模型,具有识别任何实体类型的能力,使用的是一种双向变压器编码器(类似于BERT)。它提供了一种实际可行的替代方案,适合传统NER模型受限于预定义实体,或大型语言模型(LLM)在资源受限场景下昂贵且庞大的情况。
可用的模型版本
项目提供了多个型号和版本的模型,如下所示:
发布版本 | 模型名称 | 参数数量 | 语言 | 许可证 |
---|---|---|---|---|
v0 | urchade/gliner_base urchade/gliner_multi | 209M 209M | 英语 多语言 | cc-by-nc-4.0 |
v1 | urchade/gliner_small-v1 urchade/gliner_medium-v1 urchade/gliner_large-v1 | 166M 209M 459M | 英语 英语 英语 | cc-by-nc-4.0 |
v2 | urchade/gliner_small-v2 urchade/gliner_medium-v2 urchade/gliner_large-v2 | 166M 209M 459M | 英语 英语 英语 | apache-2.0 |
v2.1 | urchade/gliner_small-v2.1 urchade/gliner_medium-v2.1 urchade/gliner_large-v2.1 urchade/gliner_multi-v2.1 | 166M 209M 459M 209M | 英语 英语 英语 多语言 | apache-2.0 |
安装指南
要使用这个模型,首先需要安装GLiNER Python库,只需执行以下命令:
!pip install gliner
使用方法
安装好GLiNER库之后,可以导入GLiNER类,并利用GLiNER.from_pretrained
方法加载模型,接着使用predict_entities
预测实体。下面是一个简单的使用示例:
from gliner import GLiNER
model = GLiNER.from_pretrained("urchade/gliner_base")
text = """
Cristiano Ronaldo dos Santos Aveiro (Portuguese pronunciation: [kɾiʃˈtjɐnu ʁɔˈnaldu]; born 5 February 1985) is a Portuguese professional footballer who plays as a forward for and captains both Saudi Pro League club Al Nassr and the Portugal national team. Widely regarded as one of the greatest players of all time, Ronaldo has won five Ballon d'Or awards,[note 3] a record three UEFA Men's Player of the Year Awards, and four European Golden Shoes, the most by a European player. He has won 33 trophies in his career, including seven league titles, five UEFA Champions Leagues, the UEFA European Championship and the UEFA Nations League. Ronaldo holds the records for most appearances (183), goals (140) and assists (42) in the Champions League, goals in the European Championship (14), international goals (128) and international appearances (205). He is one of the few players to have made over 1,200 professional career appearances, the most by an outfield player, and has scored over 850 official senior career goals for club and country, making him the top goalscorer of all time.
"""
labels = ["person", "award", "date", "competitions", "teams"]
entities = model.predict_entities(text, labels)
for entity in entities:
print(entity["text"], "=>", entity["label"])
模型作者
GLiNER模型由以下几位作者开发:
- Urchade Zaratiana
- Nadi Tomeh
- Pierre Holat
- Thierry Charnois
文献引用
如需引用GLiNER,请使用以下BibTex条目:
@misc{zaratiana2023gliner,
title={GLiNER: Generalist Model for Named Entity Recognition using Bidirectional Transformer},
author={Urchade Zaratiana and Nadi Tomeh and Pierre Holat and Thierry Charnois},
year={2023},
eprint={2311.08526},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
结论
GLiNER-base是一款强大的命名实体识别工具,不仅解决了传统模型的局限性,还在资源受限的条件下提供了更为经济的解决方案。其多版本、多语言的灵活选择,以及简单的使用流程,让各类用户都能轻松上手。