Views
No views yet
drama-1b is 2048, as we adopt Matryoshka Representation Learning, the dimionality can be flexiblely truncated to dimensionalities such as 768 or 256.drama-base to encode query and document examples from the MIRACL dataset, using either Transformers or Sentence Transformers:1import torch
2from transformers import AutoTokenizer, AutoModel
3
4
5queries = [
6 'What percentage of the Earth\'s atmosphere is oxygen?',
7 '意大利首都是哪里?',
8]
9documents = [
10 "The amount of oxygen in the atmosphere has fluctuated over the last 600 million years, reaching a peak of 35% during the Carboniferous period, significantly higher than today's 21%.",
11 "羅馬是欧洲国家意大利首都和罗马首都广域市的首府及意大利全国的政治、经济、文化和交通中心,位于意大利半島中部的台伯河下游平原地,建城初期在七座小山丘上,故又名“七丘之城”。按城市范围内的人口计算,罗马是意大利人口最多的城市,也是欧盟人口第三多的城市。",
12]
13
14model_name = "facebook/drama-1b"
15device = "cuda" if torch.cuda.is_available() else "cpu"
16tokenizer = AutoTokenizer.from_pretrained(model_name)
17model = AutoModel.from_pretrained(model_name, trust_remote_code=True).to(device)
18
19query_embs = model.encode_queries(tokenizer, queries)
20doc_embs = model.encode_documents(tokenizer, documents)
21
22scores = query_embs @ doc_embs.T
23print(scores.tolist())
24# Expected output: [[0.5062, 0.1475], [0.1837, 0.6331]]
25Thetrust_remote_codewill use our customizeddrama_modeling.pywith two details:
- We use bi-directional attention instead of uni-directional attention
- We add
"Query: "as prefix for query text. (No prefix added to document)
1query_embs = model.encode_queries(tokenizer, queries, dim=256)
2doc_embs = model.encode_documents(tokenizer, documents, dim=256)
3
4scores = query_embs @ doc_embs.T
5print(scores.tolist())
6# Expected output: [[0.6579, 0.3296], [0.3388, 0.7547]]1from sentence_transformers import SentenceTransformer
2
3queries = [
4 'What percentage of the Earth\'s atmosphere is oxygen?',
5 '意大利首都是哪里?',
6]
7documents = [
8 "The amount of oxygen in the atmosphere has fluctuated over the last 600 million years, reaching a peak of 35% during the Carboniferous period, significantly higher than today's 21%.",
9 "羅馬是欧洲国家意大利首都和罗马首都广域市的首府及意大利全国的政治、经济、文化和交通中心,位于意大利半島中部的台伯河下游平原地,建城初期在七座小山丘上,故又名“七丘之城”。按城市范围内的人口计算,罗马是意大利人口最多的城市,也是欧盟人口第三多的城市。",
10]
11
12model = SentenceTransformer("facebook/drama-1b", trust_remote_code=True)
13
14query_embs = model.encode(queries, prompt_name="query")
15doc_embs = model.encode(documents)
16
17scores = model.similarity(query_embs, doc_embs)
18print(scores.tolist())
19# Expected output: [[0.5062, 0.1475], [0.1837, 0.6331]]
- The
trust_remote_codewill use our customizeddrama_modeling.pywhich uses bi-directional attention instead of uni-directional attention.- For queries, you have to use
prompt_name="query"to select the prompt called "query", orprompt="Query: "to specify the prompt string manually.
1from sentence_transformers import SentenceTransformer
2
3queries = [
4 'What percentage of the Earth\'s atmosphere is oxygen?',
5 '意大利首都是哪里?',
6]
7documents = [
8 "The amount of oxygen in the atmosphere has fluctuated over the last 600 million years, reaching a peak of 35% during the Carboniferous period, significantly higher than today's 21%.",
9 "羅馬是欧洲国家意大利首都和罗马首都广域市的首府及意大利全国的政治、经济、文化和交通中心,位于意大利半島中部的台伯河下游平原地,建城初期在七座小山丘上,故又名“七丘之城”。按城市范围内的人口计算,罗马是意大利人口最多的城市,也是欧盟人口第三多的城市。",
10]
11
12model = SentenceTransformer("facebook/drama-1b", truncate_dim=256, trust_remote_code=True)
13
14query_embs = model.encode(queries, prompt_name="query")
15doc_embs = model.encode(documents)
16
17scores = model.similarity(query_embs, doc_embs)
18print(scores.tolist())
19# Expected output: [[0.6579, 0.3296], [0.3388, 0.7547]]
drama-1b released in this page is corresponidng to the line DRAMA-1B with 1B non-embedding parrameters.Arabic, Bengali, Chinese, English, Finnish, French, German, Hindi, Indonesian, Italian, Japanese, Korean, Persian, Portuguese, Russian, Spanish, Swahili, Telugu, Thai, Yoruba@article{drama,
title={{Drama}: Diverse Augmentation from Large Language Models To Smaller Dense Retrievers},
author={Ma, Xueguang and Lin, Victoria Xi and Oguz, Barlas and Lin, Jimmy and Yih, Wen-tau and Chen, Xilun},
journal={arXiv:2502.18460},
year={2025}
}