首页 > 其他分享 >英伟达发布最新屠榜 Embedding 模型——NV-Embed-v2

英伟达发布最新屠榜 Embedding 模型——NV-Embed-v2

时间:2024-09-04 12:21:24浏览次数:12  
标签:伟达 embeddings length passage v2 query model NV size

在这里插入图片描述

介绍

我们介绍的NV-Embed-v2是一种通用嵌入模型,它在大规模文本嵌入基准(MTEB benchmark)(截至2024年8月30日)的56项文本嵌入任务中以72.31的高分排名第一。

NV-Embed-v2 提出了几项新设计,包括让 LLM 关注潜在向量以获得更好的池化嵌入输出,并展示了一种两阶段指令调整方法,以提高检索和非检索任务的准确性。 此外,NV-Embed-v2 还采用了一种新颖的硬阴性挖掘方法,这种方法考虑了正相关性得分,能更好地去除假阴性。

有关更多技术细节,请参阅我们的论文: NV-Embed:将 LLM 训练为通用嵌入模型的改进技术。

https://arxiv.org/pdf/2405.17428

在这里插入图片描述

型号详情

  • 仅用于解码器的基本 LLM:Mistral-7B-v0.1
  • 池类型: Latent-Attention
  • 嵌入尺寸: 4096

演示

使用 HuggingFace Transformers

import torch
import torch.nn.functional as F
from transformers import AutoTokenizer, AutoModel

# Each query needs to be accompanied by an corresponding instruction describing the task.
task_name_to_instruct = {"example": "Given a question, retrieve passages that answer the question",}

query_prefix = "Instruct: "+task_name_to_instruct["example"]+"\nQuery: "
queries = [
    'are judo throws allowed in wrestling?', 
    'how to become a radiology technician in michigan?'
    ]

# No instruction needed for retrieval passages
passage_prefix = ""
passages = [
    "Since you're reading this, you are probably someone from a judo background or someone who is just wondering how judo techniques can be applied under wrestling rules. So without further ado, let's get to the question. Are Judo throws allowed in wrestling? Yes, judo throws are allowed in freestyle and folkstyle wrestling. You only need to be careful to follow the slam rules when executing judo throws. In wrestling, a slam is lifting and returning an opponent to the mat with unnecessary force.",
    "Below are the basic steps to becoming a radiologic technologist in Michigan:Earn a high school diploma. As with most careers in health care, a high school education is the first step to finding entry-level employment. Taking classes in math and science, such as anatomy, biology, chemistry, physiology, and physics, can help prepare students for their college studies and future careers.Earn an associate degree. Entry-level radiologic positions typically require at least an Associate of Applied Science. Before enrolling in one of these degree programs, students should make sure it has been properly accredited by the Joint Review Committee on Education in Radiologic Technology (JRCERT).Get licensed or certified in the state of Michigan."
]

# load model with tokenizer
model = AutoModel.from_pretrained('nvidia/NV-Embed-v2', trust_remote_code=True)

# get the embeddings
max_length = 4096
query_embeddings = model.encode(queries, instruction=query_prefix, max_length=max_length)
passage_embeddings = model.encode(passages, instruction=passage_prefix, max_length=max_length)

# normalize embeddings
query_embeddings = F.normalize(query_embeddings, p=2, dim=1)
passage_embeddings = F.normalize(passage_embeddings, p=2, dim=1)

# get the embeddings with DataLoader (spliting the datasets into multiple mini-batches)
# batch_size=2
# query_embeddings = model._do_encode(queries, batch_size=batch_size, instruction=query_prefix, max_length=max_length, num_workers=32, return_numpy=True)
# passage_embeddings = model._do_encode(passages, batch_size=batch_size, instruction=passage_prefix, max_length=max_length, num_workers=32, return_numpy=True)

scores = (query_embeddings @ passage_embeddings.T) * 100
print(scores.tolist())
# [[87.42692565917969, 0.462837278842926], [0.9652643203735352, 86.0372314453125]]

使用 Sentence-Transformers

import torch
from sentence_transformers import SentenceTransformer

# Each query needs to be accompanied by an corresponding instruction describing the task.
task_name_to_instruct = {"example": "Given a question, retrieve passages that answer the question",}

query_prefix = "Instruct: "+task_name_to_instruct["example"]+"\nQuery: "
queries = [
    'are judo throws allowed in wrestling?', 
    'how to become a radiology technician in michigan?'
    ]

# No instruction needed for retrieval passages
passages = [
    "Since you're reading this, you are probably someone from a judo background or someone who is just wondering how judo techniques can be applied under wrestling rules. So without further ado, let's get to the question. Are Judo throws allowed in wrestling? Yes, judo throws are allowed in freestyle and folkstyle wrestling. You only need to be careful to follow the slam rules when executing judo throws. In wrestling, a slam is lifting and returning an opponent to the mat with unnecessary force.",
    "Below are the basic steps to becoming a radiologic technologist in Michigan:Earn a high school diploma. As with most careers in health care, a high school education is the first step to finding entry-level employment. Taking classes in math and science, such as anatomy, biology, chemistry, physiology, and physics, can help prepare students for their college studies and future careers.Earn an associate degree. Entry-level radiologic positions typically require at least an Associate of Applied Science. Before enrolling in one of these degree programs, students should make sure it has been properly accredited by the Joint Review Committee on Education in Radiologic Technology (JRCERT).Get licensed or certified in the state of Michigan."
]

# load model with tokenizer
model = SentenceTransformer('nvidia/NV-Embed-v2', trust_remote_code=True)
model.max_seq_length = 4096
model.tokenizer.padding_side="right"

def add_eos(input_examples):
  input_examples = [input_example + model.tokenizer.eos_token for input_example in input_examples]
  return input_examples

# get the embeddings
batch_size = 2
query_embeddings = model.encode(add_eos(queries), batch_size=batch_size, prompt=query_prefix, normalize_embeddings=True)
passage_embeddings = model.encode(add_eos(passages), batch_size=batch_size, normalize_embeddings=True)

scores = (query_embeddings @ passage_embeddings.T) * 100
print(scores.tolist())

标签:伟达,embeddings,length,passage,v2,query,model,NV,size
From: https://blog.csdn.net/weixin_41446370/article/details/141882576

相关文章

  • H6922 低压升压恒压芯片 支持3.7V-5V-9V升12V24V30V48V54V60V72V100V 200W大功率
    H6922低压升压恒压芯片:高效能、多功能,应用于多种电源管理在当今的电子设备中,电源管理芯片扮演着至关重要的角色。其中,H6922作为一款好的低压升压恒压芯片,凭借其高效能、多功能以及应用领域,受到了市场的关注。产品概述H6922是一款外围电路简单的BOOST异步升压恒压控制驱动芯片,适用于......
  • MeshAnything V2来了!30秒生成建模师级Mesh!最大可生成面数提升至1600.
    GitHub已揽星1.9k的MeshAnything项目上新了V2版本,由来自南洋理工大学、清华大学、帝国理工学院、西湖大学等研究人员完成。MeshAnythingV2相比V1,使用了最新提出的AdjacentMeshTokenization(AMT)算法,将最大可生成面数从800提升到了1600。只需30秒,AI就能像3D建模师一样,在各种指示下......
  • 解决podman: ERRO[0000] running newuidmap: write to uid_map failed: Invalid argum
    报错ERRO[0000]running/usr/bin/newuidmap27115520100011100000655366553710000065537:newuidmap:writetouid_mapfailed:InvalidargumentError:cannotsetupnamespaceusing"/usr/bin/newuidmap":shouldhavesetuidorhavefilecapssetu......
  • DevExpress WinForms v24.1亮点- TreeList、折叠组件全新升级
    DevExpressWinForms拥有180+组件和UI库,能为WindowsForms平台创建具有影响力的业务解决方案。DevExpressWinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!DevExpressWinForms控件2024年第一个重大版本......
  • Windows 下 Node.js 版本管理指南:不使用 NVM 与使用 NVM 的两种方案
    文章目录方案一:不使用nvm管理NODEJS版本方案二:使用nvm管理NODEJS版本其他配置方案一:不使用nvm管理NODEJS版本NodeJs官网,NodeJs下载索引页下载较慢,不推荐这里使用v18.16.0版本,下载注意需要注册一个flowus账号登录才能下载node-v18.16.0-win-x64.zip下......
  • 免费解决《薄暮传说:终极版》nvwgf2umx.dll缺失或错误问题的方法
    免费解决《薄暮传说:终极版》中nvwgf2umx.dll缺失或错误问题的方法主要包括以下几种:一、使用系统文件检查器(SFC)打开命令提示符:在Windows搜索栏中输入“cmd”,然后以管理员身份运行命令提示符。运行SFC扫描:在命令提示符窗口中,输入sfc/scannow命令,并按回车键。这个命令会启动系......
  • vue2+html2canvas+jspdf 导出网页
    `asynchandlePreview(){constpdf=awaitthis.exportToPdf()//使用浏览器预览PDF-安全策略有缺陷constpdfDataURI=pdf.output('datauristring')window.open(pdfDataURI,'_blank','location=no');},asynchandleDown(){constpdf=awai......
  • YUV(NV12)与NHWC(BGRA)图像格式之间的区别联系
    NV12是一种视频编码格式,属于YUV颜色空间的一种采样方式。以下是关于NV12格式的具体介绍:YUV色彩空间:在数字图像处理中,YUV色彩空间将彩色图像分为亮度信息(Y)和色度信息(U、V)。这种分离使得图像处理更为灵活,尤其是在视频压缩和传输中非常有用。4:2:0采样:YUV4:2:0是指对亮度信息......
  • 【已解决】Invalid value type for attribute ‘factoryBeanObjectType‘: java.lang.
    一、问题描述Invalidvaluetypeforattribute‘factoryBeanObjectType‘:java.lang.String二、解决方案更新本地的Mybatisplus版本<dependency>  <groupId>com.baomidou</groupId>  <artifactId>mybatis-plus-spring-boot3-starter</artifactId> ......
  • 【Canvas与艺术】五种函数化回文边纹纹饰荟萃
    【成图】【代码】<!DOCTYPEhtml><htmllang="utf-8"><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><head><title>五种函数化回文边纹纹饰荟萃</title><styletype="text/css&......