Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 13
How to use ahmedHamdi/IR-pt-en-gemma_masked with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("ahmedHamdi/IR-pt-en-gemma_masked")
sentences = [
"PERSON owns a department store where he likes to employ convicts on parole, giving them a new opportunity. Among them are PERSON and PERSON, who fall in love. Since marriages between convicts are illegal, PERSON hides her condition from PERSON, and they get married. The marriage is happy until PERSON discovers PERSON's lie. Disillusioned, he reunites his old gang and plans to rob PERSON's store. Helen tries to dissuade them from the idea.",
"Mr. PERSON, owner of a large department store, hires offenders released on parole to give them a chance to rehabilitate. The other staff do not know. Among them is PERSON, who is resigning and leaving for GPE in order to end his growing friendship with fellow-employee PERSON, as he feels unworthy of her. With his violent past, he does not feel he could marry such a sweet and innocent girl. They spend a last evening together and, as he boards the ORG bus, she says that if he did ask to marry her the answer would be yes. They rush to an instant marriage bureau and then back to her room. The landlady emerges to throw PERSON out, but relents when PERSON shows her ring. PERSON says they must keep the wedding secret, because ORG does not approve of employees marrying each other. In fact he does not mind, but PERSON is not allowed to marry while on parole. When PERSON finds a ribboned bundle of what he assumes are love letters in GPE's room, but which are parole cards, he becomes jealous of her past, and meets up for a drink with some criminals from his own. They plan to ORG store at night, and recruit him to join the operation. But one of the gang is sorry for ORG, should PERSON end up back in prison, and, trying to disguise his voice on the telephone, encourages her to keep him away that night; but panicking, he fails to cover the telephone properly; she recognizes the voice, deduces why, and warns PERSON. When the robbers break into the store, they are surrounded by armed guards. PERSON says he will let them go once they have listened to what PERSON has to say. With considerable expertise, she outlines on a blackboard the full costs of the operation they had planned and the meager returns each individual would receive if it had succeeded. PERSON is not amused by ORG's role in the affair or by her sophisticated knowledge of heist planning. As he does not offer any reconciliation, she packs her things and disappears. PERSON and his colleagues search all over town, with no leads. From ORG's parole officer, PERSON learns that PERSON is pregnant and that her marriage was void as it breached her parole conditions. After looking everywhere for her, one of the gang realizes that she'd probably be in a hospital, and finds her. The film ends with their second, but this time valid, marriage.",
"In the 2000s, ORG, a spirited 10-year-old living in GPE, dreams of owning a green bicycle that she passes at a store every day on her way to school. She wants to race her friend PERSON, a boy from her neighborhood, but riding bikes is frowned upon for girls and ORG's mother refuses to buy one for her. The bike is expensive, costing SR800 (~$213). PERSON begins to earn the money herself by selling mixtapes, hand-braiding bracelets for classmates, and acting as a go-between for an older student. These activities get her into trouble with the strict headmistress. Her mother, meanwhile, is dealing with a job that has a terrible commute with a driver who often gets angry with her for making him wait. He tells ORG's mother that he will no longer drive her to work, but PERSON and PERSON find where the driver lives and visit his house to tell him to take her mother's business. After PERSON threatens to have his uncle deport the driver, he agrees. Meanwhile, ORG's grandmother on her father's side is looking for a second wife for her son because ORG's mother cannot have any more children and ORG's uncle wants a son. ORG's mother is angry and scared by this, so she tries on a beautiful red dress for her brother-in-law's wedding to gain support and to scare off any potential women who may consider marrying him. At school, ORG decides to join the religion club to participate in a GPE recital competition featuring a SR1,000 cash prize (equivalent of about US$270). Meanwhile, two girls at the madrasa caught by the headmistress for adorning themselves with nail polish and marker-drawn ankle tattoos are surprised when ORG, in keeping with her new pious image, does not stand with them by testifying in their favor. ORG's efforts at memorization impress her teacher, and she wins the competition. The staff and students are shocked when ORG announces her intention to buy a bicycle with the prize money. The headmistress is furious, and instead donates the reward to GPE against ORG's will. PERSON offers PERSON his bike (which she does not accept) and says he wants to marry her when they are older. PERSON returns home to find her father and begins crying when he says he is proud that she won the competition. After a brief conversation, he asks ORG to tell her mother that he loves her, and leaves the house to take a phone call. Later, ORG finds out that her father has taken a second wife as she joins her mother in viewing the wedding ceremony from their rooftop. ORG suggests that her mother could buy the red dress and win her father back again, but her mother reveals that she has instead spent the money on the green bike her daughter wants. The two hug as fireworks from the wedding light up the night sky behind them. The next day, ORG rides down the street on her new bike. The owner of the bike shop sees her passing and smiles. She races PERSON and wins.",
"PERSON, PERSON and PERSON are playing a game, known as PERSON, in which they create working plans to infiltrate and burgle various targets. They do not actually execute these heists, preferring to simply simulate them using necessary technical and physical abilities to carry out the tasks required for the heist. They adhere to some rules, such as using identical equipment and infrastructure as the target and using no firearms of any kind. All is fine until a famous criminal, PERSON, breaks into PERSON's apartment, steals the trio's plans for a jewelry warehouse heist and accomplishes it. He then blackmails the group into designing and executing a plan to steal $20 million in bonds from a bank. Since he has evidence incriminating them in the plans, they accept. Tension escalates within the group as PERSON befriends PERSON, while PERSON and PERSON attempt to hinder his plans. They get the security codes to the safe and successfully switch the bonds. But the situation turns against them when PERSON and PERSON force PERSON into an elevator and crash it. When they go to retrieve the bonds, PERSON shoots PERSON, then PERSON shoots PERSON. With the three friends dead, PERSON leaves with the bonds. It is later revealed that the friends had switched ORG gun, giving him one loaded with blanks. PERSON and PERSON get up and are greeted by PERSON. When PERSON gets back to his place, he sees a fire started by the gang to destroy evidence against them and planted evidence against PERSON on the latest burglary. PERSON is taken in custody by ORG, while the friends drive away in their car."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from google/embeddinggemma-300m. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'max_seq_length': 256, 'do_lower_case': False, 'architecture': 'Gemma3TextModel'})
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
)
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("ahmedHamdi/IR-pt-en-gemma_masked")
# Run inference
sentences = [
"The central story is the conflict between a group of poor miners and a powerful city man. It begins with a stranger defending a miner from a gang of thugs. To the miner's surprise, he is wearing a religious collar. The miner then invites this preacher to dinner at his home. As the film progresses, the preacher integrates into the poor community until the time comes for a confrontation with the forces of the powerful capitalist.",
"In LOC, outside GPE, GPE in GPE, mining baron ORG is waging a war of intimidation against independent prospectors and their families, including PERSON who is courting PERSON. PERSON's teenaged daughter, PERSON, desperate for deliverance from ORG after a gang of his men attack the mining camp and kill her dog, prays for a miracle. Shortly afterward, a man atop a pale horse rides into LOC. When PERSON heads to town to pick up supplies, four of ORG's men beat him with axe handles before the stranger fights them off with his own axe handle. Hull then invites his rescuer to dinner and, while the stranger is washing, notices what appears to be six bullet wounds in his back. When the stranger arrives at the dining table, he is wearing a clerical collar and is thereafter referred to as PERSON. ORG son, PERSON, attempts to scare off the PERSON with a gigantic workman named PERSON. PERSON, however, disables ORG with a sledgehammer blow to the groin. Coy returns from GPE, learns of the PERSON's arrival, and unsuccessfully attempts to bribe and then threaten him. At PERSON's suggestion, ORG then offers the miners $1,000 per claim provided they evacuate within 24 hours. ORG says he plans to hire the services of a corrupt marshal named PERSON to clear them out if they refuse. The miners ultimately reject ORG's offer, despite PERSON warning them about GPE. PERSON expresses her love for PERSON, but he gently rebuffs her. Megan angrily assumes PERSON is really in love with PERSON. ORG's men dam the creek forcing the miners to mine a dry bed. Megan rides into ORG's camp, where PERSON shows her the blasting operation before he attempts to rape her. Preacher arrives on horseback, disarms PERSON and shoots him through the hand. Stockburn and his deputies arrive in ORG. Coy gives him a rough description of the PERSON, which startles ORG, because the man PERSON is describing is dead. PERSON, one of the miners and ORG's former partner, discovers a large gold nugget in the dry creek bed and rides into town with his teenage sons, where he yells drunken abuse at ORG from the street. Stockburn and his deputies gun him down, and ORG sends a message that he wants PERSON to meet him in town the next morning. PERSON begs PERSON not to go, and tells him she will marry PERSON, despite her feelings for PERSON. The following day, PERSON and PERSON blow up ORG's mining site with dynamite. To stop Hull from following him, PERSON scares off PERSON's horse and rides into town alone. In the gunfight that follows, he kills all but the two of ORG's men who run away, and then, one by one, all six of ORG's deputies. In the final shootout, ORG recognizes PERSON in disbelief before he is shot in the chest five times, leaving five exitwounds in the back similar to the wounds on PERSON's back. Finally, PERSON kills him with a shot to the head. ORG, watching from his office, aims a rifle at the PERSON but is shot dead by Hull. Preacher nods at Hull and rides off toward the snow-capped mountains. Megan arrives and, seeing PERSON riding away, shouts her love and thanks to him.",
"In the mid-1970's, fake psychic ORG (PERSON) and her boyfriend PERSON (PERSON) attempt to locate the nephew of wealthy, guilt-ridden, elderly ORG (PERSON). ORG's recently-deceased sister gave the baby boy up for adoption, but GPE now wants to make him her heir and will pay ORG $10,000 to find him. Julia knows almost nothing about the infant. During his investigation PERSON discovers that the boy was given the name PERSON, and is thought to have died while still young. However George tracks down a man, PERSON (PERSON), who paid for PERSON's tombstone years after his supposed death, and PERSON comes to think the grave is empty. George and ORG bicker frequently, but he is as good an investigator as she is a psychic, and their relationship is solid. Meanwhile, it has been revealed to the viewers that Shoebridge murdered his adoptive parents and faked his own death, and is now a successful jeweler in GPE known as PERSON (PERSON). He and his live-in girlfriend PERSON (Karen Black) kidnap millionaires and dignitaries, confining them in a secure room in the cellar of their home, and return them in exchange for ransoms in the form of valuable gemstones. PERSON conceals the latest ransom, a large diamond, in plain sight within a crystal chandelier hanging above the home's main staircase. When PERSON learns that PERSON is investigating him, he enlists PERSON (the two had murdered PERSON's adoptive parents long ago) to kill ORG and PERSON. PERSON initially refuses to help, then contacts ORG and PERSON, telling them to meet him at a café on a mountain road. He cuts the brakeline of ORG's car, but they manage to survive their dangerous high-speed descent. Maloney tries to run them over, but dies in a fiery explosion when he swerves to avoid an oncoming car and his car goes over the edge. At ORG's funeral, his wife (PERSON) tearfully confesses, under pressure of PERSON's questioning, that PERSON's name is now PERSON. PERSON must go to work driving his taxi for an evening shift, so ORG tracks down various A. Adamsons in GPE, eventually reaching the jewelry store as it closes for the day. PERSON's assistant Mrs. PERSON (ORG) offers to let ORG leave a note. ORG tricks Mrs. PERSON into giving her his home address. PERSON and PERSON are bundling their latest kidnap victim, ORG (PERSON), into their car when ORG rings their doorbell. They attempt to drive out of their garage, but ORG's car blocks their way. She tells PERSON that his aunt wants to make him her heir, and for a moment everyone seems delighted with developments. Then ORG sees the unconscious bishop, and she is abducted by the couple. PERSON drugs her and leaves her in the cellar, to deal with after they exchange the bishop for ransom. Searching for ORG, PERSON finds her car outside GPE and ORG's house. When no one answers the door, he breaks in and searches for her. He finds her handbag with blood stains on it, and indications of a struggle. When PERSON and PERSON return home PERSON hides upstairs. He overhears PERSON telling PERSON about his plan to kill ORG and make her death seem a suicide. George manages to talk to ORG, who is faking unconsciousness in the cellar (left open by PERSON when he went to check on her) and they come up with a plan. PERSON and ORG enter to carry ORG out to the car, but she knocks them down and runs out and PERSON locks the kidnappers in. ORG then goes into what appears to be a genuine trance. She walks out of the basement and climbs halfway up the main staircase, stops, and points at the huge diamond hidden in the chandelier. ORG then wakes and asks PERSON what she is doing there. He excitedly tells her that she is indeed a real psychic. He calls the police to collect the reward for capturing the kidnappers and finding the jewels. A smiling ORG winks at the camera.",
]
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.8267, -0.2054],
# [ 0.8267, 1.0000, -0.0620],
# [-0.2054, -0.0620, 1.0000]])
sentence_0 and sentence_1| sentence_0 | sentence_1 | |
|---|---|---|
| type | string | string |
| details |
|
|
| sentence_0 | sentence_1 |
|---|---|
An American ballet student arrives at the prestigious German academy that accepted her to begin her studies, but soon realizes that the school is a front for a world of murder and witchcraft. |
PERSON, a young American ballet student, arrives in GPE, GPE, GPE during a torrential downpour to study at ORG, a prestigious German dance school. She sees another student, PERSON, flee the school in terror. Suzy is refused entry to the school and forced to stay in town overnight. PERSON takes refuge at a friend's apartment and tells her that something sinister happened at the school. PERSON is ambushed by a shadowy figure who stabs her repeatedly and drags her to the roof of the apartment building before hanging her with a noose by throwing her through the building's skylight. PERSON's friend is also killed after being impaled by a falling giant shard of glass while trying to alert other tenants to the murder. Suzy returns to the school the next morning, where she meets PERSON, the head instructor, and ORG, the deputy headmistress. Tanner introduces PERSON, one of the school's servants. She also meets classmates PERSON and PERSON, her new roommate. Suzy experiences an unsettling encou... |
PERSON (PERSON) is an executive who has grown accustomed to being alone, but doesn't particularly like it. Abandoned by her biological parents, she spent most of her childhood being raised by ORG), an adoptive father who never truly loved PERSON after her adoptive mother died. One day, PERSON learns that ORG has died. Alone in her apartment, after trying to feed her now-dead pet fish, she breaks down and cries uncontrollably. The next day at work, PERSON receives an unexpected flower delivery from a secret admirer. Intrigued, she presses the delivery man for information about who might have sent the flowers. He says the sender wishes to remain anonymous. PERSON asks her friends for names and visits the florist without success. After getting to know each other better, he confesses to sending them. PERSON (PERSON) runs a flower shop and often takes long walks around the neighborhood at night, trying to let go of memories of his deceased wife and son. He saw PERSON crying at her window an... |
PERSON (PERSON) is a business executive who has gotten used to being alone but doesn't like it very much. She was abandoned by her birth parents and then spent most of her childhood being raised by ORG), a foster father who never really loved PERSON after her adopted mother died. One day, PERSON gets word that ORG has died. Alone in her apartment, after attempting to feed her now dead pet fish, she breaks down and cries uncontrollably. The next day at work, PERSON gets an unexpected delivery of flowers from a secret admirer. Puzzled, she presses the delivery man for information on who might have sent her the flowers. He says the sender wants to remain anonymous. PERSON asks her friends for names and visits the flower shop to no avail. After getting to know each other better, the florist confesses that he sent them. PERSON (PERSON) runs a flower shop and often takes long walks through the neighborhood at night, trying to lose memories of his deceased wife and child. He saw PERSON crying... |
The story focuses on the relationship between two teenage friends, PERSON (Thora Birch) and GPE (PERSON), who have just finished high school and feel insecure about the future. While conflicts arise that test their friendship, ORG meets PERSON (PERSON), a lonely and shy record collector, through an advertisement and realizes she has a lot in common with him. |
Best friends PERSON and GPE face the summer after their high school graduation, with no plans for their future, other than to find jobs and live together. The girls are cynical social outcasts, but GPE is more popular with boys than Enid. ORG's diploma is withheld on the condition that she attend a remedial art class. Even though she is a talented artist, her art teacher, PERSON, believes that art must be socially meaningful and dismisses ORG's sketches as nothing more than light entertainment. The girls see a personal ad in which a lonely, middle-aged man named PERSON asks a woman he met recently to contact him. ORG makes a prank phone call to GPE, pretending to be the woman and inviting him to meet her at a diner. The two girls and their friend, PERSON, secretly watch PERSON at the diner and make fun of him. ORG soon begins to feel sympathy for PERSON, and they follow him to his apartment building. Later they find him selling vintage records in a garage sale. ORG buys an old blues al... |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"gather_across_devices": false
}
per_device_train_batch_size: 4per_device_eval_batch_size: 4multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 4per_device_eval_batch_size: 4per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 5e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1num_train_epochs: 3max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_ratio: 0.0warmup_steps: 0log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Truesave_safetensors: Truesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseno_cuda: Falseuse_cpu: Falseuse_mps_device: Falseseed: 42data_seed: Nonejit_mode_eval: Falsebf16: Falsefp16: Falsefp16_opt_level: O1half_precision_backend: autobf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: 0ddp_backend: Nonetpu_num_cores: Nonetpu_metrics_debug: Falsedebug: []dataloader_drop_last: Falsedataloader_num_workers: 0dataloader_prefetch_factor: Nonepast_index: -1disable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Falseignore_data_skip: Falsefsdp: []fsdp_min_num_params: 0fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}fsdp_transformer_layer_cls_to_wrap: Noneaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthproject: huggingfacetrackio_space_id: trackioddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Truedataloader_persistent_workers: Falseskip_memory_metrics: Trueuse_legacy_prediction_loop: Falsepush_to_hub: Falseresume_from_checkpoint: Nonehub_model_id: Nonehub_strategy: every_savehub_private_repo: Nonehub_always_push: Falsehub_revision: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseinclude_for_metrics: []eval_do_concat_batches: Truefp16_backend: autopush_to_hub_model_id: Nonepush_to_hub_organization: Nonemp_parameters: auto_find_batch_size: Falsefull_determinism: Falsetorchdynamo: Noneray_scope: lastddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: noneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseliger_kernel_config: Noneeval_use_gather_object: Falseaverage_tokens_across_devices: Trueprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: round_robinrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.3446 | 500 | 0.0573 |
| 0.6892 | 1000 | 0.111 |
| 1.0338 | 1500 | 0.1244 |
| 1.3784 | 2000 | 0.0655 |
| 1.7229 | 2500 | 0.0642 |
| 2.0675 | 3000 | 0.0371 |
| 2.4121 | 3500 | 0.0168 |
| 2.7567 | 4000 | 0.0096 |
@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{henderson2017efficient,
title={Efficient Natural Language Response Suggestion for Smart Reply},
author={Matthew Henderson and Rami Al-Rfou and Brian Strope and Yun-hsuan Sung and Laszlo Lukacs and Ruiqi Guo and Sanjiv Kumar and Balint Miklos and Ray Kurzweil},
year={2017},
eprint={1705.00652},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Base model
google/embeddinggemma-300m