Sentence Similarity
PEFT
Safetensors
English
text-embedding
embeddings
information-retrieval
beir
text-classification
language-model
text-clustering
text-semantic-similarity
text-evaluation
text-reranking
feature-extraction
Sentence Similarity
natural_questions
ms_marco
fever
hotpot_qa
mteb
Eval Results
Update README.md
Browse files
README.md
CHANGED
@@ -45,30 +45,47 @@ from transformers import AutoTokenizer, AutoModel, AutoConfig
|
|
45 |
from peft import PeftModel
|
46 |
|
47 |
# 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.
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
-
# Loading
|
55 |
-
model = PeftModel.from_pretrained(
|
|
|
|
|
56 |
|
57 |
# Wrapper for encoding and pooling operations
|
58 |
l2v = LLM2Vec(model, tokenizer, pooling_mode="mean", max_length=512)
|
59 |
|
60 |
# Encoding queries using instructions
|
61 |
-
instruction =
|
|
|
|
|
62 |
queries = [
|
63 |
-
[instruction,
|
64 |
-
[instruction,
|
65 |
]
|
66 |
q_reps = l2v.encode(queries)
|
67 |
|
68 |
# Encoding documents. Instruction are not required for documents
|
69 |
documents = [
|
70 |
"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.",
|
71 |
-
"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."
|
72 |
]
|
73 |
d_reps = l2v.encode(documents)
|
74 |
|
@@ -79,8 +96,8 @@ cos_sim = torch.mm(q_reps_norm, d_reps_norm.transpose(0, 1))
|
|
79 |
|
80 |
print(cos_sim)
|
81 |
"""
|
82 |
-
tensor([[0.
|
83 |
-
[0.
|
84 |
"""
|
85 |
```
|
86 |
|
|
|
45 |
from peft import PeftModel
|
46 |
|
47 |
# 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.
|
48 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
49 |
+
"McGill-NLP/LLM2Vec-Llama-2-7b-chat-hf-mntp"
|
50 |
+
)
|
51 |
+
config = AutoConfig.from_pretrained(
|
52 |
+
"McGill-NLP/LLM2Vec-Llama-2-7b-chat-hf-mntp", trust_remote_code=True
|
53 |
+
)
|
54 |
+
model = AutoModel.from_pretrained(
|
55 |
+
"McGill-NLP/LLM2Vec-Llama-2-7b-chat-hf-mntp",
|
56 |
+
trust_remote_code=True,
|
57 |
+
config=config,
|
58 |
+
torch_dtype=torch.bfloat16,
|
59 |
+
device_map="cuda" if torch.cuda.is_available() else "cpu",
|
60 |
+
)
|
61 |
+
model = PeftModel.from_pretrained(
|
62 |
+
model,
|
63 |
+
"McGill-NLP/LLM2Vec-Llama-2-7b-chat-hf-mntp",
|
64 |
+
)
|
65 |
+
model = model.merge_and_unload() # This can take several minutes on cpu
|
66 |
|
67 |
+
# 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).
|
68 |
+
model = PeftModel.from_pretrained(
|
69 |
+
model, "McGill-NLP/LLM2Vec-Llama-2-7b-chat-hf-unsup-simcse"
|
70 |
+
)
|
71 |
|
72 |
# Wrapper for encoding and pooling operations
|
73 |
l2v = LLM2Vec(model, tokenizer, pooling_mode="mean", max_length=512)
|
74 |
|
75 |
# Encoding queries using instructions
|
76 |
+
instruction = (
|
77 |
+
"Given a web search query, retrieve relevant passages that answer the query:"
|
78 |
+
)
|
79 |
queries = [
|
80 |
+
[instruction, "how much protein should a female eat"],
|
81 |
+
[instruction, "summit define"],
|
82 |
]
|
83 |
q_reps = l2v.encode(queries)
|
84 |
|
85 |
# Encoding documents. Instruction are not required for documents
|
86 |
documents = [
|
87 |
"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.",
|
88 |
+
"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.",
|
89 |
]
|
90 |
d_reps = l2v.encode(documents)
|
91 |
|
|
|
96 |
|
97 |
print(cos_sim)
|
98 |
"""
|
99 |
+
tensor([[0.6231, 0.1744],
|
100 |
+
[0.1670, 0.4732]])
|
101 |
"""
|
102 |
```
|
103 |
|