File size: 2,625 Bytes
580ad90 e971d65 580ad90 beb273a 580ad90 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
---
base_model: cognitivecomputations/dolphin-2.9-llama3-8b
datasets: abideen/Cosmopedia-100k-pretrain
---
# dolphin-2.9-llama3-8b-emb
This is an embedding model created with llm2vec. Based on the paper [LLM2Vec: Large Language Models Are Secretly Powerful Text Encoders
](https://arxiv.org/abs/2404.05961)
Mostly just an experiment I will update the model card with any findings.
## Config
```json
{{
"model_name_or_path": "{MODEL_ID}",
"dataset_name": "{DATASET}",
"per_device_train_batch_size": 1,
"per_device_eval_batch_size": 1,
"gradient_accumulation_steps": 16,
"do_train": true,
"do_eval": true,
"max_seq_length": 512,
"mask_token_type": "blank",
"data_collator_type": "all_mask",
"mlm_probability": 0.8,
"overwrite_output_dir": true,
"output_dir": "out/adapter",
"evaluation_strategy": "steps",
"eval_steps": 100,
"num_train_epochs": {EPOCHS},
"save_steps": 200,
"lora_r": {LORA_RANK},
"gradient_checkpointing": true,
"torch_dtype": "bfloat16",
"attn_implementation": "flash_attention_2"
}}
```
## Usage
```python
import torch
from llm2vec import LLM2Vec
l2v = LLM2Vec.from_pretrained(
"macadeliccc/dolphin-2.9-llama3-8b-emb",
peft_model_name_or_path="macadeliccc/dolphin-2.9-llama3-8b-emb",
device_map="cuda" if torch.cuda.is_available() else "cpu",
torch_dtype=torch.bfloat16,
)
# 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.5485, 0.0551],
[0.0565, 0.5425]])
"""
``` |