Views
No views yet
| Average | Doc2Dial | QuAC | QReCC | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| top-1 | top-5 | top-20 | top-1 | top-5 | top-20 | top-1 | top-5 | top-20 | top-1 | top-5 | top-20 | |
| bge-large-en-v1.5 | 37.75 | 71.55 | 91.54 | 32.55 | 66.13 | 86.98 | 47.93 | 74.26 | 92.02 | 32.76 | 74.27 | 95.63 |
| bge-synthesisQA | 51.72 | 83.12 | 95.02 | 38.72 | 71.39 | 88.86 | 50.71 | 83.57 | 97.13 | 65.73 | 94.41 | 99.07 |
1import torch
2from transformers import AutoTokenizer, AutoModel
3
4tokenizer = AutoTokenizer.from_pretrained('abu1111/bge-synthesisQA-query-encoder')
5query_encoder = AutoModel.from_pretrained('abu1111/bge-synthesisQA-query-encoder')
6context_encoder = AutoModel.from_pretrained('abu1111/bge-synthesisQA-context-encoder')
7
8query = [
9 {"role": "user", "content": "Can you help me understand how to choose a health insurance plan?"},
10 {"role": "agent", "content": "Sure, are you looking for individual coverage or a family plan?"},
11 {"role": "user", "content": "I need a family plan."}
12]
13contexts = [
14 "Health Insurance Guide | Choosing the Right Plan \nWhen selecting a health insurance plan, it's important to consider your family's specific needs. Factors such as the number of family members, medical history, and budget should all play a role in your decision. Plans are typically divided into categories: Bronze, Silver, Gold, and Platinum, with each offering different levels of coverage and premiums. For families with frequent medical visits, a plan with a higher premium but lower out-of-pocket costs (like a Gold or Platinum plan) might make sense. Conversely, if your family is generally healthy, a Bronze plan with lower premiums might be more cost-effective.",
15 "Health Insurance Basics | Individual vs. Family Coverage \nIndividual health insurance plans cover only one person, while family plans provide coverage for an entire household. Family plans usually have a higher premium but include shared deductibles and out-of-pocket maximums. When choosing a family plan, consider factors like the total coverage provided, the network of doctors and hospitals, and whether the plan includes benefits such as pediatric care. Understanding these distinctions can help you make an informed decision about the best option for you and your loved ones."
16]
17
18## convert query into a format as follows:
19## user: {user}\nagent: {agent}\nuser: {user}
20formatted_query = '\n'.join([turn['role'] + ": " + turn['content'] for turn in query]).strip()
21
22## get query and context embeddings
23query_input = tokenizer(formatted_query, return_tensors='pt')
24ctx_input = tokenizer(contexts, padding=True, truncation=True, max_length=512, return_tensors='pt')
25query_emb = query_encoder(**query_input).last_hidden_state[:, 0, :]
26ctx_emb = context_encoder(**ctx_input).last_hidden_state[:, 0, :]
27
28## Compute similarity scores using dot product
29similarities = query_emb.matmul(ctx_emb.transpose(0, 1)) # (1, num_ctx)
30
31## rank the similarity (from highest to lowest)
32ranked_results = torch.argsort(similarities, dim=-1, descending=True) # (1, num_ctx)