Package: income
:dollar: What is it?Index Compression Methods (INCOME) repository helps you easily train and evaluate differentmemory efficientdense retrievers across any custom dataset. The pre-trained models produce float embeddings of sizes from 512 to even upto 1024. However, when storing a large number of embeddings, this requires quite a lot of memory / storage. We focus on index compression and produce final embeddings which are binary and require less dimensions which help yousave both storage and moneyon hosting such models in practical setup.We currently support the following memory efficient dense retriever model architectures:BPR: Binary Passage Retriever(ACL 2021)JPQ: Jointly Optimizing Query Encoder and Product Quantization to Improve Retrieval Performance(CIKM 2021)For more information, checkout our publication:Domain Adaptation for Memory-Efficient Dense Retrieval(Arxiv preprint):dollar: InstallationOne can either install income viapippipinstallincomeor via source usinggit clone$gitclonehttps://github.com/Nthakur20/income.git
$cdincome
$pipinstall-e.With that, you should be ready to go!:dollar: Models SupportedWe currently support training and inference of these compressed dense retrievers within our repository:Models (on HF)BEIR (Avg. NDCG@10)Memory SizeQuery TimeGCP CloudCost per. Month (in $)No CompressionTAS-B(Hofstatter et al., 2021)TAS-B0.41565 GB (1x)456.9 msn2-highmem-8$306.05TAS-B + HNSW(Hofstatter et al., 2021)TAS-B0.415151 GB (1x)1.8 msn2-highmem-32$1224.19TAS-B + PQ(Hofstatter et al., 2021)TAS-B0.3612 GB (32x)44.0 msn1-standard-1$24.27Supervised CompressionBPR(Yamada et al., 2021)NQ (DPR)0.2012.2 GB (32x)38.1 msn1-standard-1$24.27BPR(Thakur et al., 2022)TAS-B0.3572.2 GB (32x)38.1 msn1-standard-1$24.27JPQ(Zhan et al., 2021)STAR(query)(doc)0.3892.2 GB (32x)44.0 msn1-standard-1$24.27JPQ(Thakur et al., 2022)TAS-B(query)(doc)0.4022.2 GB (32x)44.0 msn1-standard-1$24.27The Index size and costs are estimated for a user who wants to build a semantic search engine over the English Wikipedia containing about 21 million passages you need to encode.
Using float32 (and no further compression techniques) and 768 dimensions, the resulting embeddings have a size of about 65GB. Then2-highmem-8server can provide upto 64 GB of memory, whereas then1-standard-1server can provide upto 3.75 GB of memory.:dollar: Reproduction Scripts with TAS-BScriptBEIR (Avg. NDCG@10)Memory SizeBaselinesfp-16evaluate_fp16.py0.41433 GB (2x)fp-8evaluate_fp16.py0.40716 GB (4x)PCAevaluate_pca.py0.23522 GB (3x)TLDRevaluate_pca.py0.24022 GB (3x)PQevaluate_pq.py0.3612.2 GB (32x)Supervised CompressionBPRbpr_beir_evaluation.py0.3572.2 GB (32x)JPQjpq_beir_evaluation.py0.4022.2 GB (32x):dollar: Why should we do domain adaptation?ScriptBEIR (Avg. NDCG@10)Memory SizeSupervised CompressionBPR+GenQtrain_bpr_genq.sh0.3772.2 GB (32x)BPR+GPLtrain_bpr_gpl.sh0.3982.2 GB (32x)JPQ+GenQtrain_jpq_genq.sh0.4172.2 GB (32x)JPQ+GPLtrain_jpq_gpl.sh0.4352.2 GB (32x):dollar: Why should we do domain adaptation?:dollar: Inference:dollar: Training:dollar: BPRexportdataset="nfcorpus"python-mincome.bpr.train\--path_to_generated_data"generated/$dataset"\--base_ckpt"msmarco-distilbert-base-tas-b"\--gpl_score_function"dot"\--batch_size_gpl32\--gpl_steps10000\--new_size-1\--queries_per_passage-1\--output_dir"output/$dataset"\--generator"BeIR/query-gen-msmarco-t5-base-v1"\--retrievers"msmarco-distilbert-base-tas-b""msmarco-distilbert-base-v3""msmarco-MiniLM-L-6-v3"\--retriever_score_functions"dot""cos_sim""cos_sim"\--cross_encoder"cross-encoder/ms-marco-MiniLM-L-6-v2"\--qgen_prefix"gen-t5-base-2-epoch-default-lr-3-ques"\--evaluation_data"./$dataset"\--evaluation_output"evaluation/$dataset"\--do_evaluation\--use_amp# Use this for efficient training if the machine supports AMP:dollar: JPQ:dollar: DisclaimerFor reproducibility purposes, we work with the original code repositories and modify them in INCOME if they available, for eg.BPRandJPQ. It remains the user's responsibility to determine whether you as a user have permission to use the original models and to cite the right owner of each model. Check the below table for reference.If you're a model owner and wish to update any part of it, or do not want your model to be included in this library, feel free to post an issue here or make a pull request!Model/MethodCitationGitHubBPR(Yamada et al., 2021)https://github.com/studio-ousia/bprJPQ(Zhan et al., 2021)https://github.com/jingtaozhan/JPQGPL(Wang et al., 2021)https://github.com/UKPLab/gpl:dollar: Citing & AuthorsIf you find this repository helpful, feel free to cite our recent publication:Domain Adaptation for Memory-Efficient Dense Retrieval:@article{thakur2022domain,
  title={Domain Adaptation for Memory-Efficient Dense Retrieval},
  author={Thakur, Nandan and Reimers, Nils and Lin, Jimmy},
  journal={arXiv preprint arXiv:2205.11498},
  year={2022},
  url={https://arxiv.org/abs/2205.11498/}
}The main contributors of this repository are:Nandan Thakur, Personal Website:nandan-thakur.comContact person: Nandan Thakur,nandant@gmail.comDon't hesitate to send us an e-mail or report an issue, if something is broken (and it shouldn't be) or if you have further questions.This repository contains experimental software and is published for the sole purpose of giving additional background details on the respective publication.