Matryoshka Representation Learning
Paper • 2205.13147 • Published • 28
How to use bugBug04S/legal-embed-modernbert-v1 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("bugBug04S/legal-embed-modernbert-v1")
sentences = [
"search_query: Can you \"make\" an insurer fix a total loss vehicle? In state of Missouri my friend was hit from behind. Driver that him stated to police that it was her fault - no issues with fault as this is in police report. He had an older car with body issues but the engine and maintenance was very well maintained. Meaning a junker that drove well. Bluebook value is 2.5-3k. He has 4-5k in damages. The problem is that the other driver's insurance wants to give him 1400. Finding a car that runs similar to this car even with body damage is 4-6k and who really knows how it was maintained. So my question is, legally is there anything this party can do to make the insurance company fix the car vs. handing over a check for the total loss? It is my opinion that he is in a much much worse predicament than before an accident that was not his fault. Not sure how someone can cause an accident and put the victim in a worse situation but I am not sure on the legal recourse. Please let me know what other info you need.",
"search_document: If you take away insurance, the basic legal rule is that if one person wrongfully causes damage to another, the wrong-doer can be compelled to make the other part \"whole\", that is, undo the damage that they caused. If you have an item of property that would cost $3,000 to fix or repair, then you could be compelled to pay for that repair or replacement. Even if it is decided that the wrong-doing party is entirely liable for the damage, there can be disputes over what that amount of damage actually is. \"Bluebook\" is one means of standardizing value, but it is not an actual legal definition of what a given car is worth. Really, it just depends on whose evidence about value is most persuasive. An insurance company is motivated to pay the least, and the aggrieved party is motivated to receive the maximum. A jury can weigh the arguments and decide on a figure. If indeed the cost of repair is objectively around $5,000 and the cost of replacement is similar, then a jury would most likely find that that is what the at-fault party is liable for. So the way to \"force\" an insurance company to increase their offer is to persuade them of two facts: that the costs really is about $5,000, and that you are willing to sue their client to recover that $5,000. An insurance company simply covers their client's liability, so if the damage is $5,000, you don't sue the insurance company to get more, you sue their client. You have no obligation to accept an offer from either the insurance company or from their client: but if you don't accept some offer, you will have to sue the client to get anything. Bear in mind that in Missouri, they follow the theory of \"comparative negligence\" which means that if A is found to be 75% at fault and B is 25% at fault, A is liable for 75% of B's losses. The police report does not decide that, rather that is determined by the trial. The police report is relevant to determining who gets a ticket, if anyone: civil liability is determined via a lawsuit. Puttin",
"search_document: The relevant regulations in 49 CFR 1540 refer to weapons, not firearms, and unless you are specifically permitted, you cannot carry a weapon in your carry-on luggage. The interpretation of \"weapon\" is given here , which says Weapons are objects that may be used to attack another. TSA considers an item to be a weapon under 49 CFR 1540.111 if it is created for use as a weapon or is so similar to an item created as a weapon that it appears to be, or is easily used as, a weapon. Weapons include firearms, as well as realistic replicas of firearms that may reasonably be thought to be actual weapons. Such realistic replicas are prohibited because their similarity in appearance to real weapons may allow them to be used to intimidate passengers and flight crew. The screener has the discretion to determine when a replica is so realistic that it should be prohibited. Other toy weapons will be allowed in the sterile areas and cabin. Partial weapons and parts of weapons also are prohibited because they may be carried separately by collaborators for assembly subsequent to entry or boarding. In addition, partial weapons may appear to be operative and could be used to intimidate passengers and flight crew.",
"search_document: Certainly in Australia it would be legal to ask; it would also be legal to discriminate on this basis (i.e. it is not discrimination on a protected basis). However, it would be culturally inappropriate. It is probably both legal and appropriate in Japan. It is worth noting that a great chunk of culturally inappropriate behavior is not illegal. For example, it would generally be legal for a current or previous employer who was not subject to the Privacy Act (most small business) to disclose your salary; they just don't."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from nomic-ai/modernbert-embed-base. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for retrieval.
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'ModernBertModel'})
(1): Pooling({'embedding_dimension': 768, 'pooling_mode': 'mean', '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("bugBug04S/legal-embed-modernbert-v1")
# Run inference
sentences = [
"search_query: Can I add a deadlock to the front door of my unit? I have recently bought a unit in a rough area. The front door to the apartment complex does not click shut properly so anyone from the general public can walk in. The door to my unit has one of those cheap push button door handle locks. I have spoken to the body corporate and the building manager and there are currently no plans to fix the apartment complex door. I asked about adding some more security to the door of my unit, namely a good quality (fire rated) deadlock. But they replied back that deadlocks are not permitted for fire and aesthetic reasons, even locks that are fire rated. What is the legality of prohibiting deadlocks? Are fire rated deadlocks permitted legally on fire exits? They mentioned something about fire safety laws changing in 2019 but I didn't get a full understanding. Is this documented anywhere?",
'search_document: National Construction Code For Class 2 Buildings (apartments) the relevant volume is No 2. Door hardware on fire doors must comply with AS 1905.1 (Specification C3.4 Clause 2), that is, it has to be "fire-rated". There are plenty of fire-rated deadlocks available. Normally, a door in a path of travel to an exit cannot be key operated in the direction of travel, however, there are a number of exceptions. One is if it "serves only, or is within— (A) a sole-occupancy unit in a Class 2 building" - like yours. So there is no regulatory obstacle to this. Strata Law The door (and its hardware) is part of the common property - it belongs to the body corporate, not you. Technically, you own the paint on the inside, they own everything else. So, even if you paid for the lock, it would belong to the body-corporate and they would bear all the risk of loss and damage including if it wasn\'t installed properly. They may be unwilling to take this risk. They can legally prevent you from doing anything to their property. However, you can insist that the body-corporate repair the front door. Having "no plans" is not an excuse for failing in their legal duty to repair and maintain the common property. If they refuse, you can use the dispute resolution process.',
'search_document: Are the reasons (mom can\'t stay because of covid-19 and the son is too young to live by himself) legally justifiable reasons? Unfortunately, not in this case. The landlord can prevail by arguing that the mom, insofar as a holder of a non-immigrant visa, knew or should have known of the risks of being denied entry in the US. In terms of the Restatement (Second) of Contracts at § 154 (a) & (b), the mom is the " Party [who] Bears the Risk of a Mistake ". Since the risks of which the mom was aware include even arbitrary ones such as the USCIS officer\'s discretion , an allegation of "supervening circumstances" as per the coronavirus crisis is very unlikely to add any merit to the mom\'s legal position. Is the 8 months compensate reasonable? Although this is admittedly subjective, at first glance it appears reasonable or perhaps even generous (the landlord is proposing the midpoint: half of the remaining 16 months) considering that the landlord is entitled to the completion of the lease. The " 8 months as compensation " is essentially the landlord\'s proposal to settle his otherwise viable claim of breach of contract . You as lease holders can always attempt to negotiate and make alternative proposals, which is what you are doing already . Here, the landlord seeks to obviate court proceedings that can be a drag for both him and especially for the mom because she would be unable even to present her arguments in court and/or quasi-judicial proceedings. A settlement would benefit the landlord also from the standpoint that he would no longer be required to prove mitigation of damages (if that is a requirement in his jurisdiction). And, unless the settlement provides otherwise, the landlord would be free to immediately re-rent the unit without having to reimburse the mom (or the person(s) whose name is in the lease). That being said, it is important for the lease holder(s) to secure in writing (specifically in the settlement document) a statement from the landlord in the sense t',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.7668, 0.1163],
# [0.7668, 1.0000, 0.1873],
# [0.1163, 0.1873, 1.0000]])
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| anchor | positive |
|---|---|
search_query: Does Mojang break the law with restrictions in their EULA for Minecraft? Minecraft is a world building game that is produced/sold by Mojang AB. Minecraft may be played both offline (local data) or online (connecting to a server). Minecraft's EULA says that you may not sell items to players (real money) that give them in-game benefits outside of cosmetics. However, that is Minecraft's clients EULA. How can they enforce servers to follow that rule if the servers are not owned by Mojang and they are not using Mojang's proprietary software. Wouldn't this be like selling a television set and saying to broadcasters they must follow any rules I impose. |
search_document: The rule you are alluding to with respect to a television set is called the " first sale doctrine " which basically prohibits copyright and trademark owners from limiting the ability of a buyer of a good (like a CD or authorized logo T-Shirt) protected by copyright or trademark, from limiting further sales of that good (or the manner in which the good is used by its new owner) after a first retail sale of the good with copyright or trademark protections. This doctrine was derived from an old common law rule that invalidated "restraints on alienation" of property other than intellectual property on public policy grounds, and like the "restrain on alienation" rule for tangible property, the first sale doctrine that applies to intellectual property was also (at least originally) a court created common law rule. But Minecraft isn't, conceptually, a good. It is a continuing service provided over the Internet, and firms that provide continuing services on a licensed basis, a... |
search_query: Can I post edited comedy images of Indian politician in social website I edited an image of an Indian politician. Added some comedy picture taken from a Tamil movie. And also wrote some thing funny about that politicians. Is that legal. Can I post that image to a social website.. Do I face any problem in future for posting such images. What does the law say. |
search_document: Legally you face no problem. The section 66A of the Indian IT Act, which used to be previously misused for penalizing anyone who dared insult a politician, has been struck down as unconstitutional by the Supreme Court of India. But the police could still detain you for 48 hours (legally) without giving any grounds; they are required to do that, but the police are seldom held accountable. The supporters of the said politician can vandalize your home and office without fear of legal action. I am not a lawyer. Whatever is posted above is my opinion and data that I believe to be true to the best of my knowledge and resources available to me. Please contact a lawyer for professional advice. |
search_query: Are CuddleFix participants engaged in prostitution? Is CuddleFix ( http://www.cuddlefix.com ) prostitution, or not? If not, where (or at what actions) is the line drawn exactly? In brief: you pay them to come to your house and lie in bed with you and spoon. With clothes on. No kissing. Regarding jurisdiction – let's say Alabama, then the U.S. at large, and finally "the West" generally. |
search_document: See http://codes.lp.findlaw.com/alcode/13A/12/3/2 . Is the cuddling or spooning a sexual act or sexual contact? A court would have to decide. Perhaps there is some binding precedent on the books; I do not know. The answer to this question could be different for different jurisdictions in Alabama, since local ordinances might exist. It will almost certainly be different for different states in the US, let alone "the west" generally, whatever that means. |
MatryoshkaLoss with these parameters:{
"loss": "CachedMultipleNegativesRankingLoss",
"matryoshka_dims": [
768,
512,
256,
128,
64
],
"matryoshka_weights": [
1,
1,
1,
1,
1
],
"n_dims_per_step": -1
}
per_device_train_batch_size: 64num_train_epochs: 1learning_rate: 1e-05warmup_steps: 0.1fp16: Trueper_device_train_batch_size: 64num_train_epochs: 1max_steps: -1learning_rate: 1e-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: Noneremove_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: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.0992 | 25 | 1.8452 |
| 0.1984 | 50 | 0.9378 |
| 0.2976 | 75 | 0.8986 |
| 0.3968 | 100 | 0.7386 |
| 0.4960 | 125 | 0.7398 |
| 0.5952 | 150 | 0.7222 |
| 0.6944 | 175 | 0.7030 |
| 0.7937 | 200 | 0.5992 |
| 0.8929 | 225 | 0.6804 |
| 0.9921 | 250 | 0.6471 |
@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{kusupati2024matryoshka,
title={Matryoshka Representation Learning},
author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
year={2024},
eprint={2205.13147},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
@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}
}
Base model
answerdotai/ModernBERT-base