bzantium / NV-Embed-v1

huggingface.co
Total runs: 19
24-hour runs: 0
7-day runs: 1
30-day runs: 10
Model's Last Updated: July 19 2024
feature-extraction

Introduction of NV-Embed-v1

Model Details of NV-Embed-v1

Introduction

This is fixed version of nvidia/NV-Embed-v1 to download model without error.

How to use

Here is an example of how to encode queries and passages using Huggingface-transformer and Sentence-transformer.

Usage (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('bzantium/NV-Embed-v1', 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)
# passage_embeddings = model._do_encode(passages, batch_size=batch_size, instruction=passage_prefix, max_length=max_length, num_workers=32)

scores = (query_embeddings @ passage_embeddings.T) * 100
print(scores.tolist())
#[[77.9402084350586, 0.4248958230018616], [3.757718086242676, 79.60113525390625]]
Usage (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('bzantium/NV-Embed-v1', 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())
Correspondence to

Chankyu Lee ( [email protected] ), Wei Ping ( [email protected] )

Citation

If you find this code useful in your research, please consider citing:

@misc{lee2024nvembed,
      title={NV-Embed: Improved Techniques for Training LLMs as Generalist Embedding Models}, 
      author={Chankyu Lee and Rajarshi Roy and Mengyao Xu and Jonathan Raiman and Mohammad Shoeybi and Bryan Catanzaro and Wei Ping},
      year={2024},
      eprint={2405.17428},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}
License

This model should not be used for any commercial purpose. Refer the license for the detailed terms.

Runs of bzantium NV-Embed-v1 on huggingface.co

19
Total runs
0
24-hour runs
0
3-day runs
1
7-day runs
10
30-day runs

More Information About NV-Embed-v1 huggingface.co Model

More NV-Embed-v1 license Visit here:

https://choosealicense.com/licenses/cc-by-nc-4.0

NV-Embed-v1 huggingface.co

NV-Embed-v1 huggingface.co is an AI model on huggingface.co that provides NV-Embed-v1's model effect (), which can be used instantly with this bzantium NV-Embed-v1 model. huggingface.co supports a free trial of the NV-Embed-v1 model, and also provides paid use of the NV-Embed-v1. Support call NV-Embed-v1 model through api, including Node.js, Python, http.

NV-Embed-v1 huggingface.co Url

https://huggingface.co/bzantium/NV-Embed-v1

bzantium NV-Embed-v1 online free

NV-Embed-v1 huggingface.co is an online trial and call api platform, which integrates NV-Embed-v1's modeling effects, including api services, and provides a free online trial of NV-Embed-v1, you can try NV-Embed-v1 online for free by clicking the link below.

bzantium NV-Embed-v1 online free url in huggingface.co:

https://huggingface.co/bzantium/NV-Embed-v1

NV-Embed-v1 install

NV-Embed-v1 is an open source model from GitHub that offers a free installation service, and any user can find NV-Embed-v1 on GitHub to install. At the same time, huggingface.co provides the effect of NV-Embed-v1 install, users can directly use NV-Embed-v1 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

NV-Embed-v1 install url in huggingface.co:

https://huggingface.co/bzantium/NV-Embed-v1

Url of NV-Embed-v1

NV-Embed-v1 huggingface.co Url

Provider of NV-Embed-v1 huggingface.co

bzantium
ORGANIZATIONS

Other API from bzantium