Granite镶嵌 107m多语言模型卡
granite-embedding-107m-multilingual模型是Granite 107M 参数密集型双编码器嵌入模型,可用于生成高质量的文本嵌入。 该模型生成大小为384的嵌入向量,并使用开源相关性对数据集与 IBM 收集和生成的数据集的组合进行训练,这些数据集具有宽松的企业友好型许可。 该模型的开发采用了对比微调、知识提炼和模型合并等技术,以提升性能。
- 开发人员 IBM Granite 嵌入团队
- GitHub 仓库 :ibm-granite/granite-embedding-models
- 网站 Granite
- 纸质 :即将推出
- 发布日期: 2024年12月18日
- 许可证: Apache 2.0
支持的语言
英语、德语、西班牙语、法语、日语、葡萄牙语、阿拉伯语、捷克语、意大利语、韩语、荷兰语和中文。 用户可对granite-embedding-107m-multilingual进行微调,以添加这12种语言之外的其他语言。
目标用途
该模型旨在为给定的文本生成固定长度的向量表示,可用于文本相似性、检索和搜索应用。
与句子转换器的搭配使用
该模型SentenceTransformer 库兼容,使用起来非常简单:
首先,安装句子转换库。
pip install sentence_transformers
然后,该模型可用于对文本对进行编码,并找出它们之间的相似性。
from sentence_transformers import SentenceTransformer, util
model_path = "ibm-granite/granite-embedding-107m-multilingual"
# Load the Sentence Transformer model
model = SentenceTransformer(model_path)
input_queries = [
' Who made the song My achy breaky heart? ',
'summit define'
]
input_passages = [
"Achy Breaky Heart is a country song written by Don Von Tress. Originally titled Don't Tell My Heart and performed by The Marcy Brothers in 1991. ",
"Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments."
]
# encode queries and passages
query_embeddings = model.encode(input_queries)
passage_embeddings = model.encode(input_passages)
# calculate cosine similarity
print(util.cos_sim(query_embeddings, passage_embeddings))
与Huggingface Transformers的搭配使用
这是一个简单的例子,展示了如何使用granite-embedding-107m-multilingual与变压器库和 PyTorch。
首先,安装所需的库文件。
pip install transformers torch
然后,该模型可用于对文本对进行编码。
import torch
from transformers import AutoModel, AutoTokenizer
model_path = "ibm-granite/granite-embedding-107m-multilingual"
# Load the model and tokenizer
model = AutoModel.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)
model.eval()
input_queries = [
' Who made the song My achy breaky heart? ',
'summit define'
]
# tokenize inputs
tokenized_queries = tokenizer(input_queries, padding=True, truncation=True, return_tensors='pt')
# encode queries
with torch.no_grad():
# Queries
model_output = model(**tokenized_queries)
# Perform pooling. granite-embedding-107m-multilingual uses CLS Pooling
query_embeddings = model_output[0][:, 0]
# normalize the embeddings
query_embeddings = torch.nn.functional.normalize(query_embeddings, dim=1)
评估:
granite-embedding-107m-multilingual模型在多语言奇迹(18种语言)、Mintaka检索(8种语言)和MTEB检索(英语15项任务)、德语(4个任务)、西班牙语(2个任务)、法语(5个任务)、日语(2个任务)、阿拉伯语(1个任务)、韩语(1个任务)和中文(8个任务)的测试结果如下。 这款granite-embedding-107m-multilingual模型的速度是其他类似镶嵌尺寸模型的两倍。
| 模型 | 参数(M) | 嵌入维度 | Miracl(18) | Mintaka检索(8) | MTEB 英语 (15) | MTEB 德语 (4) | MTEB 西班牙语(2) | MTEB 法语 (5) | MTEB 日语 (2) | MTEB 阿拉伯语(1) | MTEB 韩语 (1) | MTEB 中文 (8) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| granite-embedding-107m-multilingual | 107 | 384 | 55.9 | 22.6 | 45.3 | 70.3 | 48.7 | 51.1 | 59.0 | 63.2 | 70.5 | 40.8 |
模型 架构
这款granite-embedding-107m-multilingual模型基于仅XLM-RoBERTa ,采用 IBM 内部训练的变压器架构。
| 模型 | granite-embedding-30m-english | granite-embedding-125m-english | granite-embedding-107m-multilingual | granite-embedding-278m-multilingual |
|---|---|---|---|---|
| 嵌入大小 | 384 | 768 | 384 | 768 |
| 层数 | 6 | 12 个月 | 6 | 12 个月 |
| 关注人数 | 12 个月 | 12 个月 | 12 个月 | 12 个月 |
| 中等大小 | 1536 | 3072 | 1536 | 3072 |
| 激活功能 | GeLU | GeLU | GeLU | GeLU |
| 词汇量 | 50265 | 50265 | 250002 | 250002 |
| 最大序列长度 | 512 | 512 | 512 | 512 |
| 参数数量 | 30M | 125M | 107M | 278M |
训练数据
总的来说,训练数据由四个主要来源组成:(1)从网上抓取的标题-正文无监督配对数据;(2)公开可用且带有企业友好型许可的配对数据;(3) IBM针对特定技术领域的配对数据;以及(4) IBM合成数据。 数据如下:
| 数据集 | 编号 配对 |
|---|---|
| MC4 | 52,823,484 |
| 多语言网站 | 12,369,322 |
| 英文维基百科 | 20,745,403 |
| 多语言维基媒体 | 2,911,090 |
| Miracl Corpus(标题-正文) | 10,120,398 |
| Stack Exchange 重复问题(标题) | 304,525 |
| Stack Exchange 重复问题(标题) | 304,525 |
| Stack Exchange 重复问题(主体) | 250,519 |
| Stack Exchange的机器翻译 重复问题(标题) | 187,195 |
| Stack Exchange(标题、答案)对 | 4,067,139 |
| Stack Exchange(标题、正文)对 | 23,978,013 |
| Stack Exchange(标题、正文)对 | 23,978,013 |
| Stack Exchange的机器翻译(标题+正文、答案)对 | 1,827,15 |
| SearchQA | 582,261 |
| S2ORC (标题、摘要) | 41,769,185 |
| WikiAnswers重复的问题对 | 77,427,422 |
| CC新闻 | 614,664 |
| XSum | 226,711 |
| SimpleWiki | 102,225 |
| 机器翻译 跨语言平行语料库 | 28,376,115 |
| SPECTER引用三联 | 684,100 |
| SPECTER引文三联的机器翻译 | 4,104,600 |
| 自然提问(NQ) | 100,231 |
| SQuAD2.0 | 87599 |
| HotpotQA | 85,000 |
| 发烧 | 109,810 |
| PubMed | 2000万 |
| 多语言奇迹三倍 | 81409 |
| 多语言 MrTydi 三人组 | 48715 |
| Sadeeem 问题解答 | 4037 |
| DBPedia 标题-正文对 | 4,635,922 |
| 合成:英语 查询-维基百科 段落 | 1,879,093 |
| 合成:英语事实核查 | 9888 |
| 合成:多语言查询-维基百科段落 | 300,266 |
| 综合:多语种新闻摘要 | 37489 |
| IBM三重 | 40290 |
| IBM 内部标题-正文对 | 1,524,586 |
值得注意的是,由于MS-MARCO检索数据集的非商业许可,我们没有将其用于训练语料库,而其他开源模型则因其高质量而使用该数据集进行训练。
基础结构
我们使用 IBM 的计算集群认知计算集群 (配备 NVIDIA A100 80gb GPU) 训练 Granite 嵌入模型。 该集群为我们的模型提供了可扩展且高效的基础架构,可通过多个GPU进行训练。
道德考虑和限制
用于训练基础语言模型的英语数据经过过滤,去除了包含仇恨、辱骂和亵渎的文本。
资源
- 了解 Granite 的最新更新: IBM Granite 网站
- 开始使用教程、最佳实践和及时的工程建议: IBM Granite 文档
- 了解最新的 Granite 学习资源 IBM