pipeline_tag: 问答
tags:
- 语义搜索
- 句子相似度
- sentence-transformers
- transformers
- 人工智能
- 计算机科学
language:
- en
metrics:
- 准确率
datasets:
- Adel-Elwan/人工智能-IR系统数据集
model-index:
- name: Adel-Elwan/msmarco-bert-base-dot-v5微调-AI版
results:
- task:
type: 语义搜索
name: 语义搜索
dataset:
type: Adel-Elwan/人工智能-IR系统数据集
name: 面向IR系统的人工智能数据集
split: 测试集
metrics:
-
type: 准确率
value: 83.45%
name: 前5准确率
-
type: 准确率
value: 87.78%
name: 前10准确率
-
type: 精确率
value: 16.69%
name: 前5精确率
-
type: 召回率
value: 83.45%
name: 前5召回率
-
type: 召回率
value: 87.78%
name: 前10召回率
-
type: 平均倒数排名
value: 0.7327
name: MRR@10
verified: true
{MODEL_NAME}
这是一个sentence-transformers模型:可将句子和段落映射到768维稠密向量空间,适用于聚类或语义搜索等任务。
使用方法(Sentence-Transformers)
安装sentence-transformers后即可轻松使用:
pip install -U sentence-transformers
使用示例:
from sentence_transformers import SentenceTransformer
sentences = ["这是一个示例句子", "每个句子都会被转换"]
model = SentenceTransformer('{MODEL_NAME}')
embeddings = model.encode(sentences)
print(embeddings)
使用方法(HuggingFace Transformers)
若不使用sentence-transformers,可通过以下方式调用:先将输入传入transformer模型,再对上下文词嵌入执行正确的池化操作。
from transformers import AutoTokenizer, AutoModel
import torch
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0]
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
sentences = ['这是一个示例句子', '每个句子都会被转换']
tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
model = AutoModel.from_pretrained('{MODEL_NAME}')
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
model_output = model(**encoded_input)
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("句子嵌入向量:")
print(sentence_embeddings)
评估结果
该模型的自动化评估结果可参考句子嵌入基准测试:https://seb.sbert.net
训练参数
数据加载器:
长度6563的torch.utils.data.dataloader.DataLoader
,参数:
{'batch_size': 16, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
损失函数:
sentence_transformers.losses.MultipleNegativesRankingLoss.MultipleNegativesRankingLoss
,参数:
{'scale': 20.0, 'similarity_fct': 'dot_score'}
fit()方法参数:
{
"epochs": 1,
"evaluation_steps": 5000,
"evaluator": "sentence_transformers.evaluation.InformationRetrievalEvaluator.InformationRetrievalEvaluator",
"max_grad_norm": 1,
"optimizer_class": "<class 'transformers.optimization.AdamW'>",
"optimizer_params": {
"correct_bias": false,
"eps": 1e-06,
"lr": 2e-05
},
"scheduler": "WarmupLinear",
"steps_per_epoch": null,
"warmup_steps": 656,
"weight_decay": 0.01
}
完整模型架构
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
)