McGill-NLP / LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse

huggingface.co
Total runs: 163
24-hour runs: 0
7-day runs: 32
30-day runs: 127
Model's Last Updated: April 12 2024
sentence-similarity

Introduction of LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse

Model Details of LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse

LLM2Vec: Large Language Models Are Secretly Powerful Text Encoders

LLM2Vec is a simple recipe to convert decoder-only LLMs into text encoders. It consists of 3 simple steps: 1) enabling bidirectional attention, 2) masked next token prediction, and 3) unsupervised contrastive learning. The model can be further fine-tuned to achieve state-of-the-art performance.

Installation
pip install llm2vec
Usage
from llm2vec import LLM2Vec

import torch
from transformers import AutoTokenizer, AutoModel, AutoConfig
from peft import PeftModel

# Loading base Mistral model, along with custom code that enables bidirectional connections in decoder-only LLMs. MNTP LoRA weights are merged into the base model.
tokenizer = AutoTokenizer.from_pretrained(
    "McGill-NLP/LLM2Vec-Sheared-LLaMA-mntp"
)
config = AutoConfig.from_pretrained(
    "McGill-NLP/LLM2Vec-Sheared-LLaMA-mntp", trust_remote_code=True
)
model = AutoModel.from_pretrained(
    "McGill-NLP/LLM2Vec-Sheared-LLaMA-mntp",
    trust_remote_code=True,
    config=config,
    torch_dtype=torch.bfloat16,
    device_map="cuda" if torch.cuda.is_available() else "cpu",
)
model = PeftModel.from_pretrained(
    model,
    "McGill-NLP/LLM2Vec-Sheared-LLaMA-mntp",
)
model = model.merge_and_unload()  # This can take several minutes on cpu

# Loading unsupervised SimCSE model. This loads the trained LoRA weights on top of MNTP model. Hence the final weights are -- Base model + MNTP (LoRA) + SimCSE (LoRA).
model = PeftModel.from_pretrained(
    model, "McGill-NLP/LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse"
)

# Wrapper for encoding and pooling operations
l2v = LLM2Vec(model, tokenizer, pooling_mode="mean", max_length=512)

# Encoding queries using instructions
instruction = (
    "Given a web search query, retrieve relevant passages that answer the query:"
)
queries = [
    [instruction, "how much protein should a female eat"],
    [instruction, "summit define"],
]
q_reps = l2v.encode(queries)

# Encoding documents. Instruction are not required for documents
documents = [
    "As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",
    "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.",
]
d_reps = l2v.encode(documents)

# Compute cosine similarity
q_reps_norm = torch.nn.functional.normalize(q_reps, p=2, dim=1)
d_reps_norm = torch.nn.functional.normalize(d_reps, p=2, dim=1)
cos_sim = torch.mm(q_reps_norm, d_reps_norm.transpose(0, 1))

print(cos_sim)
"""
tensor([[0.5964, 0.1270],
        [0.0698, 0.2394]])
"""
Questions

If you have any question about the code, feel free to email Parishad ( [email protected] ) and Vaibhav ( [email protected] ).

Runs of McGill-NLP LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse on huggingface.co

163
Total runs
0
24-hour runs
0
3-day runs
32
7-day runs
127
30-day runs

More Information About LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse huggingface.co Model

More LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse license Visit here:

https://choosealicense.com/licenses/mit

LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse huggingface.co

LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse huggingface.co is an AI model on huggingface.co that provides LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse's model effect (), which can be used instantly with this McGill-NLP LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse model. huggingface.co supports a free trial of the LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse model, and also provides paid use of the LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse. Support call LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse model through api, including Node.js, Python, http.

LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse huggingface.co Url

https://huggingface.co/McGill-NLP/LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse

McGill-NLP LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse online free

LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse huggingface.co is an online trial and call api platform, which integrates LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse's modeling effects, including api services, and provides a free online trial of LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse, you can try LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse online for free by clicking the link below.

McGill-NLP LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse online free url in huggingface.co:

https://huggingface.co/McGill-NLP/LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse

LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse install

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

LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse install url in huggingface.co:

https://huggingface.co/McGill-NLP/LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse

Url of LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse

LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse huggingface.co Url

Provider of LLM2Vec-Sheared-LLaMA-mntp-unsup-simcse huggingface.co

McGill-NLP
ORGANIZATIONS

Other API from McGill-NLP

huggingface.co

Total runs: 19
Run Growth: 10
Growth Rate: 52.63%
Updated:December 21 2024