We introduce the Bloomz-3b-retriever-v2 model, based on the
Bloomz-3b-dpo-chat
model. This bi-encoder projects articles and queries into the same vector space, ensuring the proximity of queries to related articles. The model is language-agnostic for French and English, meaning a query in either language will be close to an article regardless of whether it is in French or English. This model is ideal for Open Domain Question Answering (ODQA) and can be complemented by the rerankers
Bloomz-560m-reranking
or
Bloomz-3b-reranking
.
Training
The training dataset used is a variant of
mMARCO
enabling contrastive learning and filtering out false negatives. The filtering threshold was set at 0.8, and a positive observation is confronted with 10 hard negatives, ordered by decreasing score (the 10 hardest). The model was trained on a uniform distribution of languages (1/4 French-French, 1/4 French-English, 1/4 English-French, 1/4 English-English). The learning objective is of the InfoNCE type with a trainable temperature parameter as presented for the
CLIP
model.
Note
Unlike the
Bloomz-3b-retriever
, this much more efficient model uses cosine distance as its metric (instead of L2 distance as previously).
Benchmark
The performance evaluation is based on the evaluation portion of SQuAD (5921 queries over 1204 articles across 35 different topics). One interesting aspect of this dataset is having multiple articles associated with a single theme, representing challenging contexts where a query may be close to several relevant articles. On average, there are about thirty articles per theme (see
Bloomz-3b-reranking
for the exact distribution).
We compare the performances using the average top rank of the articles targeted by a query (Top-mean), the standard deviation of the top ranks (Top-std), the percentage of correct articles within Top-1, Top-5, and Top-10, and finally, the mean reciprocal rank (MRR) across the 1204 articles.
from typing importUnion, Listimport numpy as np
import torch
from transformers import AutoTokenizer, AutoModel
from scipy.spatial.distance import cdist
tokenizer = AutoTokenizer.from_pretrained('cmarkea/bloomz-3b-retriever-v2')
model = AutoModel.from_pretrained('cmarkea/bloomz-3b-retriever-v2')
definfer(txt: Union[str, List[str]]):
tok = tokenizer(txt, padding=True, return_tensors='pt')
with torch.no_grad():
embedding = model(**tok)
# Inportant: take only last token!return embedding.get('last_hidden_state')[:,-1,:].numpy()
list_of_contexts = [...]
emb_contexts = infer(list_of_contexts)
list_of_queries = [...]
emb_queries = infer(list_of_queries)
# Important: take cosine distance!
dist = cdist(emb_queries, emb_contexts, 'cosine')
top_k = lambda x: [
[list_of_contexts[qq] for qq in ii]
for ii in dist.argsort(axis=-1)[:,:x]
]
# top 5 nearest contexts for each queries
top_contexts = top_k(5)
With Pipeline API:
import numpy as np
from transformers import pipeline
from scipy.spatial.distance import cdist
retriever = pipeline('feature-extraction', 'cmarkea/bloomz-3b-retriever-v2')
# Inportant: take only last token!
infer = lambda x: [ii[0][-1] for ii in retriever(x)]
list_of_contexts = [...]
emb_contexts = np.concatenate(infer(list_of_contexts), axis=0)
list_of_queries = [...]
emb_queries = np.concatenate(infer(list_of_queries), axis=0)
# Important: take cosine distance!
dist = cdist(emb_queries, emb_contexts, 'cosine')
top_k = lambda x: [
[list_of_contexts[qq] for qq in ii]
for ii in dist.argsort(axis=-1)[:,:x]
]
# top 5 nearest contexts for each queries
top_contexts = top_k(5)
bloomz-3b-retriever-v2 huggingface.co is an AI model on huggingface.co that provides bloomz-3b-retriever-v2's model effect (), which can be used instantly with this cmarkea bloomz-3b-retriever-v2 model. huggingface.co supports a free trial of the bloomz-3b-retriever-v2 model, and also provides paid use of the bloomz-3b-retriever-v2. Support call bloomz-3b-retriever-v2 model through api, including Node.js, Python, http.
bloomz-3b-retriever-v2 huggingface.co is an online trial and call api platform, which integrates bloomz-3b-retriever-v2's modeling effects, including api services, and provides a free online trial of bloomz-3b-retriever-v2, you can try bloomz-3b-retriever-v2 online for free by clicking the link below.
cmarkea bloomz-3b-retriever-v2 online free url in huggingface.co:
bloomz-3b-retriever-v2 is an open source model from GitHub that offers a free installation service, and any user can find bloomz-3b-retriever-v2 on GitHub to install. At the same time, huggingface.co provides the effect of bloomz-3b-retriever-v2 install, users can directly use bloomz-3b-retriever-v2 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
bloomz-3b-retriever-v2 install url in huggingface.co: