Views
No views yet
| Model (FR/FR) | Top-mean | Top-std | Top-1 (%) | Top-5 (%) | Top-10 (%) | MRR (%) |
|---|---|---|---|---|---|---|
| BM25 | 16.8 | 100.8 | 71.7 | 88.3 | 91.8 | 79.2 |
| CamemBERT | 269.6 | 303.0 | 5.6 | 12.5 | 16.5 | 9.7 |
| STS-CamemBERT | 23.1 | 85.5 | 36.0 | 63.0 | 74.0 | 48.5 |
| Sentence-BERT | 10.2 | 40.1 | 43.9 | 73.9 | 84.0 | 57.3 |
| E5-base | 6.1 | 29.7 | 59.9 | 84.9 | 91.0 | 71.1 |
| E5-large | 5.2 | 29.2 | 67.0 | 89.2 | 93.7 | 76.7 |
| Bloomz-560m-retriever | 10.2 | 46.6 | 51.5 | 78.1 | 86.2 | 63.5 |
| Bloomz-3b-retriever | 8.8 | 36.4 | 49.2 | 77.5 | 86.1 | 62.0 |
| Bloomz-560m-retriever-v2 | 4.0 | 17.1 | 68.0 | 89.9 | 94.4 | 77.7 |
| Bloomz-3b-retriever-v2 | 2.8 | 14.8 | 76.5 | 94.4 | 97.2 | 84.4 |
| Model (EN/FR) | Top-mean | Top-std | Top-1 (%) | Top-5 (%) | Top-10 (%) | MRR (%) |
|---|---|---|---|---|---|---|
| BM25 | 280.7 | 371.8 | 23.9 | 37.4 | 43.3 | 30.4 |
| CamemBERT | 355.0 | 328.3 | 0.9 | 3.7 | 6.4 | 3.13 |
| STS-CamemBERT | 102.2 | 196.9 | 13.1 | 30.5 | 40.7 | 22.1 |
| Sentence-BERT | 10.6 | 41.2 | 43.3 | 72.4 | 82.7 | 56.5 |
| E5-base | 9.9 | 38.1 | 49.8 | 77.2 | 85.4 | 62.6 |
| E5-large | 5.6 | 26.9 | 62.9 | 86.9 | 92.5 | 73.8 |
| Bloomz-560m-retriever | 11.0 | 47.8 | 48.3 | 75.7 | 84.7 | 60.4 |
| Bloomz-3b-retriever | 8.9 | 37.6 | 48.8 | 77.4 | 86.1 | 61.6 |
| Bloomz-560m-retriever-v2 | 4.4 | 18.9 | 66.6 | 89.3 | 94.1 | 76.6 |
| Bloomz-3b-retriever-v2 | 2.7 | 14.2 | 75.7 | 94.5 | 97.1 | 83.9 |
1from typing import Union, List
2
3import numpy as np
4import torch
5from transformers import AutoTokenizer, AutoModel
6from scipy.spatial.distance import cdist
7
8tokenizer = AutoTokenizer.from_pretrained('cmarkea/bloomz-3b-retriever-v2')
9model = AutoModel.from_pretrained('cmarkea/bloomz-3b-retriever-v2')
10
11def infer(txt: Union[str, List[str]]):
12 tok = tokenizer(txt, padding=True, return_tensors='pt')
13 with torch.inference_mode():
14 embedding = model(**tok)
15 # Inportant: take only last token!
16 return embedding.get('last_hidden_state')[:,-1,:].numpy()
17
18list_of_contexts: List[str] = [...]
19emb_contexts = infer(list_of_contexts)
20list_of_queries: List[str] = [...]
21emb_queries = infer(list_of_queries)
22
23# Important: take cosine distance!
24dist = cdist(emb_queries, emb_contexts, 'cosine')
25top_k = lambda x: [
26 [list_of_contexts[qq] for qq in ii]
27 for ii in dist.argsort(axis=-1)[:,:x]
28]
29
30# top 5 nearest contexts for each queries
31top_contexts = top_k(5)1import numpy as np
2from transformers import pipeline
3from scipy.spatial.distance import cdist
4
5retriever = pipeline('feature-extraction', 'cmarkea/bloomz-3b-retriever-v2')
6
7# Inportant: take only last token!
8infer = lambda x: [np.array(ii[0][-1]).reshape(1,-1) for ii in retriever(x)]
9
10list_of_contexts: List[str] = [...]
11emb_contexts = np.concatenate(infer(list_of_contexts), axis=0)
12list_of_queries: List[str] = [...]
13emb_queries = np.concatenate(infer(list_of_queries), axis=0)
14
15# Important: take cosine distance!
16dist = cdist(emb_queries, emb_contexts, 'cosine')
17top_k = lambda x: [
18 [list_of_contexts[qq] for qq in ii]
19 for ii in dist.argsort(axis=-1)[:,:x]
20]
21
22# top 5 nearest contexts for each queries
23top_contexts = top_k(5)1@online{DeBloomzRetv2,
2 AUTHOR = {Cyrile Delestre},
3 ORGANIZATION = {Cr{\'e}dit Mutuel Ark{\'e}a},
4 URL = {https://huggingface.co/cmarkea/bloomz-3b-retriever-v2},
5 YEAR = {2024},
6 KEYWORDS = {NLP ; Transformers ; LLM ; Bloomz},
7}