数据集概述
确保您的数据集格式与损失函数匹配(或者选择一个与您的数据集格式匹配的损失函数)非常重要。请参阅训练概述 > 数据集格式,了解如何验证数据集格式是否适用于某个损失函数。
实际上,大多数数据集配置将采用以下四种形式之一:
正例对:一对相关的句子。这既可用于对称任务(如语义文本相似度),也可用于非对称任务(如语义搜索),示例包括转述句对、全文及其摘要对、重复问题对、(
查询
,响应
)对,或(源语言
,目标语言
)对。自然语言推断(NLI)数据集也可以通过配对蕴含(entailing)的句子来格式化。三元组:由(锚点文本、正例文本、负例文本)组成的文本三元组。这些数据集不需要标签。
带相似度分数的句子对:一对句子,并带有一个表示其相似度的分数。常见的例子是“语义文本相似度”(Semantic Textual Similarity)数据集。
带类别的文本:一个文本及其对应的类别。这种数据格式可以被损失函数轻松地转换为三个句子(三元组),其中第一个是“锚点”,第二个是与锚点同类的“正例”,第三个是不同类的“负例”。
示例: trec, yahoo_answers_topics。
请注意,将数据集从一种格式转换为另一种格式通常很简单,这样它就可以与您选择的损失函数一起使用。
提示
您可以使用 mine_hard_negatives()
将正例对数据集转换为三元组数据集。它使用一个 SentenceTransformer
模型来寻找难负例:这些文本与数据集的第一列相似,但相似度不如第二列的文本。带有难三元组的数据集通常比仅有正例对的数据集表现更好。
例如,我们从 sentence-transformers/gooaq 中挖掘了难负例,生成了 tomaarsen/gooaq-hard-negatives,并分别在这两个数据集上训练了 tomaarsen/mpnet-base-gooaq 和 tomaarsen/mpnet-base-gooaq-hard-negatives。遗憾的是,这两个模型使用了不同的评估集划分,因此它们的性能无法直接比较。
Hugging Face Hub 上的数据集
Datasets 库 (pip install datasets
) 允许您使用 load_dataset()
函数从 Hugging Face Hub 加载数据集:
from datasets import load_dataset
# Indicate the dataset id from the Hub
dataset_id = "sentence-transformers/natural-questions"
dataset = load_dataset(dataset_id, split="train")
"""
Dataset({
features: ['query', 'answer'],
num_rows: 100231
})
"""
print(dataset[0])
"""
{
'query': 'when did richmond last play in a preliminary final',
'answer': "Richmond Football Club Richmond began 2017 with 5 straight wins, a feat it had not achieved since 1995. A series of close losses hampered the Tigers throughout the middle of the season, including a 5-point loss to the Western Bulldogs, 2-point loss to Fremantle, and a 3-point loss to the Giants. Richmond ended the season strongly with convincing victories over Fremantle and St Kilda in the final two rounds, elevating the club to 3rd on the ladder. Richmond's first final of the season against the Cats at the MCG attracted a record qualifying final crowd of 95,028; the Tigers won by 51 points. Having advanced to the first preliminary finals for the first time since 2001, Richmond defeated Greater Western Sydney by 36 points in front of a crowd of 94,258 to progress to the Grand Final against Adelaide, their first Grand Final appearance since 1982. The attendance was 100,021, the largest crowd to a grand final since 1986. The Crows led at quarter time and led by as many as 13, but the Tigers took over the game as it progressed and scored seven straight goals at one point. They eventually would win by 48 points – 16.12 (108) to Adelaide's 8.12 (60) – to end their 37-year flag drought.[22] Dustin Martin also became the first player to win a Premiership medal, the Brownlow Medal and the Norm Smith Medal in the same season, while Damien Hardwick was named AFL Coaches Association Coach of the Year. Richmond's jump from 13th to premiers also marked the biggest jump from one AFL season to the next."
}
"""
有关如何操作数据集的更多信息,请参阅 Datasets 文档。
提示
Hugging Face 数据集通常包含多余的列,例如 sample_id、metadata、source、type 等。您可以使用 Dataset.remove_columns
来移除这些列,否则它们将被用作输入。您也可以使用 Dataset.select_columns
来仅保留所需的列。
预先存在的数据集
Hugging Face Hub 托管了超过 15 万个数据集,其中许多可以转换为用于训练嵌入模型。我们的目标是为所有能够直接与 Sentence Transformers 一起使用的 Hugging Face 数据集打上 sentence-transformers
标签,让您可以通过浏览 https://hugging-face.cn/datasets?other=sentence-transformers 轻松找到它们。我们强烈建议您浏览这些数据集,以寻找可能对您的任务有用的训练数据集。
以下是一些被标记为 sentence-transformers
的流行预存数据集,可用于训练和微调 SentenceTransformer 模型:
数据集 | 描述 |
---|---|
GooAQ | 来自 Google 自动建议的 (问题, 答案) 对 |
Yahoo Answers | 来自 Yahoo Answers 的 (标题+问题, 答案)、(标题, 答案)、(标题, 问题)、(问题, 答案) 对 |
MS MARCO 三元组 (msmarco-distilbert-base-tas-b) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
MS MARCO 三元组 (msmarco-distilbert-base-v3) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
MS MARCO 三元组 (msmarco-MiniLM-L6-v3) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
MS MARCO 三元组 (distilbert-margin-mse-cls-dot-v2) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
MS MARCO 三元组 (distilbert-margin-mse-cls-dot-v1) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
MS MARCO 三元组 (distilbert-margin-mse-mean-dot-v1) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
MS MARCO 三元组 (mpnet-margin-mse-mean-v1) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
MS MARCO 三元组 (co-condenser-margin-mse-cls-v1) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
MS MARCO 三元组 (distilbert-margin-mse-mnrl-mean-v1) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
MS MARCO 三元组 (distilbert-margin-mse-sym-mnrl-mean-v1) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
MS MARCO 三元组 (distilbert-margin-mse-sym-mnrl-mean-v2) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
MS MARCO 三元组 (co-condenser-margin-mse-sym-mnrl-mean-v1) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
MS MARCO 三元组 (BM25) | 来自 MS MARCO 段落数据集的 (问题, 答案, 负例) 三元组,其中负例是挖掘出来的 |
Stack Exchange 重复项 | 来自 StackExchange 的重复问题对,包括 (标题, 标题)、(标题+正文, 标题+正文)、(正文, 正文) |
ELI5 | 来自 ELI5 数据集的 (问题, 答案) 对 |
SQuAD | 来自 SQuAD 数据集的 (问题, 答案) 对 |
WikiHow | 来自 WikiHow 的 (摘要, 文本) 对 |
Amazon Reviews 2018 | 来自 Amazon Reviews 的 (标题, 评论) 对 |
Natural Questions | 来自 Natural Questions 数据集的 (查询, 答案) 对 |
Amazon QA | 来自 Amazon 的 (问题, 答案) 对 |
S2ORC | 科学论文的 (标题, 摘要)、(摘要, 引用)、(标题, 引用) 对 |
Quora 重复项 | 来自 Quora 的重复问题对 |
WikiAnswers | 来自 WikiAnswers 的重复问题对 |
AGNews | 来自 AG News 数据集的新闻文章 (标题, 描述) 对 |
AllNLI | 来自 SNLI + MultiNLI 的 (锚点, 蕴含, 矛盾) 三元组 |
NPR | 来自 npr.org 网站的 (标题, 正文) 对 |
SPECTER | 来自 Specter 的科学出版物 (标题, 正例标题, 负例标题) 三元组 |
Simple Wiki | 来自维基百科的 (英语, 简单英语) 对 |
PAQ | 来自 Probably-Asked Questions 数据集的 (查询, 答案) |
altlex | 来自维基百科的 (英语, 简单英语) 对 |
CC News | 来自 CC News 数据集的 (标题, 文章) 对 |
CodeSearchNet | 来自 GitHub 开源库的 (注释, 代码) 对 |
句子压缩 | 来自句子压缩数据集的 (长文本, 短文本) 对 |
Trivia QA | 来自 TriviaQA 数据集的 (查询, 答案) 对 |
Flickr30k 标题 | 来自 Flickr30k 数据集的重复标题 |
xsum | 来自 XSUM 数据集的 (新闻文章, 摘要) 对 |
Coco 标题 | 来自 Coco Captions 数据集的重复标题 |
平行句子: Europarl | 多种语言的 (英语, 非英语) 对 |
平行句子: Global Voices | 多种语言的 (英语, 非英语) 对 |
平行句子: MUSE | 多种语言的 (英语, 非英语) 对 |
平行句子: JW300 | 多种语言的 (英语, 非英语) 对 |
平行句子: News Commentary | 多种语言的 (英语, 非英语) 对 |
平行句子: OpenSubtitles | 多种语言的 (英语, 非英语) 对 |
平行句子: Talks | 多种语言的 (英语, 非英语) 对 |
平行句子: Tatoeba | 多种语言的 (英语, 非英语) 对 |
平行句子: WikiMatrix | 多种语言的 (英语, 非英语) 对 |
平行句子: WikiTitles | 多种语言的 (英语, 非英语) 对 |
注意
我们建议用户为可用于训练嵌入模型的数据集添加 sentence-transformers
标签,方法是添加 tags: sentence-transformers
。我们也乐于接受高质量的数据集加入到上述列表中,供所有人查看和使用。