Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup
Paper • 2101.06983 • Published • 3
How to use dataisgod/bge-large-fiqa-financial with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("dataisgod/bge-large-fiqa-financial")
sentences = [
"Withdraw funds with penalty or bear high management fees for 10 years?",
"I personally invest in 4 different ETFs. I have $1000 to invest every month. To save on transaction costs, I invest that sum in only one ETF each month, the one that is most underweight at the time. For example, I invest in XIC (30%), VTI (30%), VEA (30%), and VWO (10%). One month, I'll buy XIC, next month VTA, next month, VEA, then XIC again. Eventually I'll buy VWO when it's $1000 underweight. If one ETF tanks, I may buy it twice in a row to reach my target allocation, or if it shoots up, I may skip buying it for a while. My actual asset allocation never ends up looking exactly like the target, but it trends towards it. And I only pay one commission a month. If this is in a tax-sheltered account (main TFSA or RRSP), another option is to invest in no-load index mutual funds that match the ETFs each month (assuming there's no commission to buy them). Once they reach a certain amount, sell and buy the equivalent ETFs. This is not a good approach in a non-registered account because you will have to pay tax on any capital gains when selling the mutual funds.",
"Emergency funds are good to keep yourself out of debt, for whatever reason. Job loss is a big place where an emergency fund can help you out. It buys you time to find another job before hauling out the credit cards for your groceries, falling behind on your mortgage and car payments, etc. But it can just as easily be used for major car repairs, serious medical issues, home repairs, etc. ... anything that needs to be done quickly, and isn't a discretionary item. The bigger your cash reserves, the better, especially now that the economy is bad.",
"Here's the purely mathematical answer for which fees hurt more. You say taking the money out has an immediate cost of $60,000. We need to calculate the present value of the future fees and compare it against that number. Let's assume that the investment will grow at the same rate either with or without the broker. That's actually a bit generous to the broker, since they're probably investing it in funds that in turn charge unjustifiable fees. We can calculate the present cost of the fees by calculating the difference between: As it turns out, this number doesn't depend on how much we should expect to get as investment returns. Doing the math, the fees cost: 220000 - 220000 * (1-0.015)^40 = $99809 That is, the cost of the fees is comparable to paying nearly $100,000 right now. Nearly half the investment! If there are no other options, I strongly recommend taking the one-time hit and investing elsewhere, preferably in low-cost index funds. Details of the derivation. For simplicity, assume that both fees and growth compound continuously. (The growth does compound continuously. We don't know about the fees, but in any case the distinction isn't very significant.) Fees occur at a (continuous) rate of rf = ln((1-0.015)^4) (which is negative), and growth occurs at rate rg. The OPs current principal is P, and the present value of the fees over time is F. We therefore have the equation P e^((rg+rf)t) = (P-F) e^(rg t) Solving for F, we notice that the e^rg*t components cancel, and we obtain F = P - P e^(rf t) = P - P e^(ln((1-0.015)^4) t) = P - P (1-0.015)^(4t)"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from BAAI/bge-large-en-v1.5. It maps sentences & paragraphs to a 1024-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'BertModel'})
(1): Pooling({'embedding_dimension': 1024, 'pooling_mode': 'cls', 'include_prompt': True})
(2): Normalize({})
)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import SentenceTransformer
# Download from the 🤗 Hub
model = SentenceTransformer("dataisgod/bge-large-fiqa-financial")
# Run inference
queries = [
'Why is day trading considered riskier than long-term trading?',
]
documents = [
"In day trading, you're trying to predict the immediate fluctuations of an essentially random system. In long-term investing, you're trying to assess the strength of a company over a period of time. You also have frequent opportunities to assess your position and either add to it or get out.",
"It is a general truism but the reasons are that the rules change dramatically when you simply have more capital. Here are some examples, limited to particular kinds of markets: Under $2,000 in capital Nobody is going to offer you a margin account, and if you do get one it isn't with the best broker on commissions and other capabilities. So this means cash only trading, enjoy your 3 business day settlement periods. This means no shorting, confining a trader to only buy and hold strategies, making them more dependent on luck than a more capable trader. This means it is more expensive to buy stock, since you have to put down 100% of the cash to hold a share, whereas someone with more money puts down less capital to hold the exact same number of shares. This means no covered options strategies or spreads, again limiting the market directions where a trader could earn Under $25,000 in capital In the stock market, the pattern day trader rule applies to retail margin accounts with a balance under $25,000 and this severally limits the kinds of trades you are able to take because of the limit in the number of trades you can take in a given time period. Forget managing a multi-leg option position when the market isn't moving your direction. Under $125,000 in capital Worse margin rules. You excluded portfolio margin from your post, but it is a key part of the answer Over $1,000,000 in capital Participate in private placements, regulation D offerings reserved for accredited investors. These days, as buy and hold investments, these generally have more growth potential than publicly traded offerings. Over $5,000,000 in capital You can easily get the compliance and risk manager to turn the other way on margin rules. This is not conjecture, leverage up to infinity, try not to bankrupt yourself and the trading firm.",
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 1024] [2, 1024]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.7313, 0.5647]])
fiqa-testInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.5417 |
| cosine_accuracy@3 | 0.6883 |
| cosine_accuracy@5 | 0.7469 |
| cosine_accuracy@10 | 0.821 |
| cosine_precision@1 | 0.5417 |
| cosine_precision@3 | 0.3338 |
| cosine_precision@5 | 0.2466 |
| cosine_precision@10 | 0.1556 |
| cosine_recall@1 | 0.2784 |
| cosine_recall@3 | 0.4531 |
| cosine_recall@5 | 0.5312 |
| cosine_recall@10 | 0.6298 |
| cosine_ndcg@10 | 0.5516 |
| cosine_mrr@10 | 0.632 |
| cosine_map@100 | 0.4843 |
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| anchor | positive |
|---|---|
New to investing — I have $20,000 cash saved, what should I do with it? |
My advice to you is not to take any advice from anyone when it comes to investing, especially when you don't know much about what you are investing in. mbhunter is correct, take your time to learn about what you want to invest in. If your goal at the moment is short term don't invest in stocks unless you really know what you are doing. Put your money where you can get the highest interest rate, continue saving and do a lot of research on the house you wish to buy. Even if you are not ready to buy a house yet, start looking so that by the time you are ready to buy, you know how much the house is really worth. Before buying our house we spent about 7 months looking and researching and looked at more than 100 houses. |
Are you preparing for a possible dollar (USD) collapse? (How?) |
"Buying gold, silver, palladium, copper and platinum. The first two I am thinking about new currencies. The last three for the perpetual need for the metals in industry. I also have invested in Numismatic coins. They are small portable and easy to hide around the house. I only collect silver coins, so even if the world really blows up and numismatics goes out the window, I can depend on them forming a barter system through the content value of the silver. The problem with collectable items is that they are easy to see. For example, a nice painting just shouts out ""steal me!"". I don't buy large gold coins. As long as the coin is below 1/4 Oz gold I collect it. If the dollar does finaly collapse, to be honest it will be so bad that I think weapons will be order of the day. Do I think it will collapse...nah never." |
Can an unmarried couple buy a home together with only one person on the mortgage? |
In this case can the title of the home still be held by both? Yes, it is possible to have additional people on title that are not on the mortgage. Would the lender (bank) have any reservations about this since a party not on the mortgage has ownership of the property? Possibly, but there is a very simple way to avoid this. Clayton could simply purchase the home himself, and add Emma to the title after closing by recording a quitclaim deed. The lender can't stop that, and from their point of view it's actually better, since they have two people to go after in the case of default. (But despite it being better they often make it difficult to purchase Tip, when you have an attorney draft the quitclaim document, have them draft the reverse document too. (Emma relinquishing the property back to Clayton.) There is usually no extra charge for this and then you have it if you need it. For example, you may need to file the reverse forms if you want to refinance. As a side note, I agree with Gra... |
CachedMultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"mini_batch_size": 8,
"mini_batch_num_tokens": null,
"gather_across_devices": false,
"directions": [
"query_to_doc"
],
"partition_mode": "joint",
"hardness_mode": null,
"hardness_strength": 0.0
}
per_device_train_batch_size: 64num_train_epochs: 1learning_rate: 2e-05warmup_steps: 0.1fp16: Truebatch_sampler: no_duplicatesper_device_train_batch_size: 64num_train_epochs: 1max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Falsefp16: Truebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Nonetorch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneuse_liger_kernel: Falseliger_kernel_config: Noneuse_cache: Falseneftune_noise_alpha: Nonetorch_empty_cache_steps: Noneauto_find_batch_size: Falselog_on_each_node: Truelogging_nan_inf_filter: Trueinclude_num_input_tokens_seen: nolog_level: passivelog_level_replica: warningdisable_tqdm: Falseproject: huggingfacetrackio_space_id: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 8prediction_loss_only: Trueeval_on_start: Falseeval_do_concat_batches: Trueeval_use_gather_object: Falseeval_accumulation_steps: Noneinclude_for_metrics: []batch_eval_metrics: Falsesave_only_model: Falsesave_on_each_node: Falseenable_jit_checkpoint: Falsepush_to_hub: Falsehub_private_repo: Nonehub_model_id: Nonehub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Falseignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 42data_seed: Noneuse_cpu: Falseaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedataloader_drop_last: Falsedataloader_num_workers: 0dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_prefetch_factor: Nonedataloader_multiprocessing_context: Nonedataloader_in_order: Trueremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonelocal_rank: -1prompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}warmup_ratio: None| Epoch | Step | Training Loss | fiqa-test_cosine_ndcg@10 |
|---|---|---|---|
| 0.2252 | 50 | 0.9249 | - |
| 0.4505 | 100 | 0.6445 | - |
| 0.6757 | 150 | 0.5890 | - |
| 0.9009 | 200 | 0.5528 | - |
| -1 | -1 | - | 0.5516 |
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}
@misc{gao2021scaling,
title={Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup},
author={Luyu Gao and Yunyi Zhang and Jiawei Han and Jamie Callan},
year={2021},
eprint={2101.06983},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
@misc{oord2019representationlearningcontrastivepredictive,
title={Representation Learning with Contrastive Predictive Coding},
author={Aaron van den Oord and Yazhe Li and Oriol Vinyals},
year={2019},
eprint={1807.03748},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/1807.03748},
}
Base model
BAAI/bge-large-en-v1.5