Views
No views yet
[128, 256, 512, 768]| Q-Net Dimension | TREC DL '19 | TREC DL '20 | Q-Net Params | Avg. Latency Speedup* |
|---|---|---|---|---|
| 768 (Full) | 0.734 | 0.723 | 3.54M | 1.0x (Baseline) |
| 512 | 0.738 | 0.729 | 1.70M | 1.6x |
| 256 | 0.741 | 0.728 | 0.52M | 3.4x |
| 128 | 0.734 | 0.725 | 0.18M | 6.0x |
hypencoder-cb codebase to run. It cannot be used with standard transformers pipelines out-of-the-box.1git clone <URL_TO_YOUR_GITHUB_REPO> # Replace with your actual GitHub repo URL
2cd hypencoder-paper
3pip install -r requirements.txt1import torch
2from hypencoder_cb.modeling.hypencoder import HypencoderDualEncoder
3from transformers import AutoTokenizer
4
5model_id = "majdalkawaas/matryoshka-hypencoder"
6device = "cuda" if torch.cuda.is_available() else "cpu"
7
8# Load the custom model architecture and weights
9model = HypencoderDualEncoder.from_pretrained(model_id).to(device).eval()
10tokenizer = AutoTokenizer.from_pretrained(model_id)
11
12print(f"Model successfully loaded. Supported Q-Net sizes: {model.config.loss_kwargs[0]['matryoshka_dims']}")1from hypencoder_cb.modeling.q_net import MatryoshkaQNetFactory
2from hypencoder_cb.modeling.similarity_and_losses import _truncate_parameters
3
4query = "What is a hypernetwork?"
5target_dimension = 256
6
7# Tokenize the query
8inputs = tokenizer(query, return_tensors="pt", truncation=True).to(device)
9
10with torch.no_grad():
11 # 1. Generate the full-size parameters from the Hyper-head
12 query_output = model.query_encoder(**inputs)
13
14 # 2. Build the specific Q-Net using the Factory
15 factory = MatryoshkaQNetFactory(model.query_encoder.weight_to_model_converter)
16 q_nets = factory.build(
17 weight_matrices=query_output.generated_matrices,
18 bias_vectors=query_output.generated_vectors,
19 matryoshka_dims=[target_dimension],
20 is_training=False
21 )
22
23 # This is your highly efficient, query-specific scoring function
24 my_q_net = q_nets[target_dimension]
25
26# You can now use `my_q_net` to score pre-computed document embeddings!1
2@inproceedings{Alkawaas_2026,
3 title={The Matryoshka Hypencoder},
4 url={http://dx.doi.org/10.1145/3805712.3809980},
5 DOI={10.1145/3805712.3809980},
6 booktitle={Proceedings of the 49th International ACM SIGIR Conference on Research and Development in Information Retrieval},
7 publisher={ACM},
8 author={Alkawaas, Majd and MacAvaney, Sean},
9 year={2026},
10 month=July, pages={3574–3579} }
11
12