Views
No views yet
| Model | Parameters | Embedding Dimension | Max Tokens | MTEB v2 Score |
|---|---|---|---|---|
| harrier-oss-v1-270m | 270M | 640 | 32,768 | 66.5 |
| harrier-oss-v1-0.6b | 0.6B | 1,024 | 32,768 | 69.0 |
| harrier-oss-v1-27b | 27B | 5,376 | 32,768 | 74.3 |
1from sentence_transformers import SentenceTransformer
2
3model = SentenceTransformer("microsoft/harrier-oss-v1-0.6b", model_kwargs={"dtype": "auto"})
4
5queries = [
6 "how much protein should a female eat",
7 "summit define",
8]
9documents = [
10 "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.",
11 "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."
12]
13
14query_embeddings = model.encode(queries, prompt_name="web_search_query")
15document_embeddings = model.encode(documents)
16
17scores = (query_embeddings @ document_embeddings.T) * 100
18print(scores.tolist())web_search_query, sts_query, and bitext_query. You can also use a custom instruction directly via e.g. model.encode(queries, prompt="Instruct: Retrieve semantically similar text\nQuery: ").1import torch
2import torch.nn.functional as F
3
4from torch import Tensor
5from transformers import AutoTokenizer, AutoModel
6
7
8def last_token_pool(last_hidden_states: Tensor, attention_mask: Tensor) -> Tensor:
9 left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])
10 if left_padding:
11 return last_hidden_states[:, -1]
12 else:
13 sequence_lengths = attention_mask.sum(dim=1) - 1
14 batch_size = last_hidden_states.shape[0]
15 return last_hidden_states[torch.arange(batch_size, device=last_hidden_states.device), sequence_lengths]
16
17
18def get_detailed_instruct(task_description: str, query: str) -> str:
19 return f'Instruct: {task_description}\nQuery: {query}'
20
21
22# Each query must come with a one-sentence instruction that describes the task
23task = 'Given a web search query, retrieve relevant passages that answer the query'
24queries = [
25 get_detailed_instruct(task, 'how much protein should a female eat'),
26 get_detailed_instruct(task, 'summit define')
27]
28# No need to add instruction for retrieval documents
29documents = [
30 "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.",
31 "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."
32]
33input_texts = queries + documents
34
35tokenizer = AutoTokenizer.from_pretrained('microsoft/harrier-oss-v1-0.6b')
36model = AutoModel.from_pretrained('microsoft/harrier-oss-v1-0.6b', dtype='auto')
37model.eval()
38model.cuda()
39
40max_length = 32768
41# Tokenize the input texts
42batch_dict = tokenizer(input_texts, max_length=max_length, padding=True, truncation=True, return_tensors='pt')
43batch_dict = {k: v.cuda() for k, v in batch_dict.items()}
44
45outputs = model(**batch_dict)
46embeddings = last_token_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
47
48# normalize embeddings
49embeddings = F.normalize(embeddings, p=2, dim=1)
50scores = (embeddings[:2] @ embeddings[2:].T) * 100
51print(scores.tolist())transformers and pytorch could cause negligible but non-zero performance differences.