👑 GLiNER:通用轻量级命名实体识别模型
GLiNER是一个能够使用双向transformer编码器(类似BERT)识别任何实体类型的命名实体识别(NER)模型。它为传统NER模型提供了一种实用的替代方案,传统模型仅限于预定义的实体,而大型语言模型(LLMs)虽然灵活,但在资源受限的场景下成本高昂且体积庞大。
📄 论文 • 📢 Discord • 🤗 演示 • 🤗 可用模型 •
示例笔记本
探索各种示例,包括微调、ONNX转换和合成数据生成。
- 示例笔记本
- 在Colab上微调
🛠 安装和使用
安装
!pip install gliner
使用
安装GLiNER库后,导入GLiNER
类。然后,您可以使用GLiNER.from_pretrained
加载所选模型,并使用predict_entities
识别文本中的实体。
from gliner import GLiNER
# 使用基础模型初始化GLiNER
model = GLiNER.from_pretrained("urchade/gliner_mediumv2.1")
# 用于实体预测的示例文本
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.
"""
# 实体预测的标签
# 大多数GLiNER模型在实体类型为小写或标题格式时效果最佳
labels = ["Person", "Award", "Date", "Competitions", "Teams"]
# 执行实体预测
entities = model.predict_entities(text, labels, threshold=0.5)
# 显示预测的实体及其标签
for entity in entities:
print(entity["text"], "=>", entity["label"])
预期输出
Cristiano Ronaldo dos Santos Aveiro => person
5 February 1985 => date
Al Nassr => teams
Portugal national team => teams
Ballon d'Or => award
UEFA Men's Player of the Year Awards => award
European Golden Shoes => award
UEFA Champions Leagues => competitions
UEFA European Championship => competitions
UEFA Nations League => competitions
European Championship => competitions
👨💻 模型作者
模型作者是:
- Urchade Zaratiana
- Nadi Tomeh
- Pierre Holat
- Thierry Charnois
📚 引用
如果您在研究中发现GLiNER有用,请考虑引用我们的论文:
@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}
}
支持和资助
本项目得到了FI Group和巴黎北部信息学实验室的支持和资助。
在过去20年里,FI Group已成为R&D&I²(研究、开发、创新和投资)公共资金策略的专家。FI Group的顾问都是工程师或博士,他们为客户提供从研发到创新生产的全程支持。
我们也衷心感谢开源社区的宝贵贡献,这对本项目的成功至关重要。