Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 15
How to use dopaminemaximizer/rag_ubiza with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("dopaminemaximizer/rag_ubiza")
sentences = [
"Instruct: Given a question about a video transcript, retrieve the most relevant transcript passage.\nQuery: How does the speaker visually demonstrate maintaining eye contact and confident posture when delivering advanced public speaking tips?",
"Fourth, use hand gestures. I mentioned that you want to be firmly planted from the waist down most of the time. But from the waist up, you can be more animated. This is mainly about gesturing with your hands, your arms, your shoulders. Now speakers do all sorts of distracting behaviors with their hands that don't look confident. Don't wring your hands or keep them in your pockets. Don't put them on your hips or behind your back. Don't hold yourself or cross your arms. Don't hold objects like a pen. If there's an object in your hand that serves no purpose, you will start to fidget with it. And fidgeting does not create the impression of confidence. Instead of all this, find a comfortable home base for your hands. The best home base is to keep your hands loosely together, right about at waist level, as if you're holding a can of soda. Don't let them creep up. Keep them loose and then just make small gestures about once every sentence or so. That's all you need to do to get started. Just let your hands go to add emphasis to whatever you're saying. Easygoing gestures like this you can do with one hand or both hand. They look confident and composed. And don't swing your",
"Sixth, you can take a photo of the Aloha boat harbor. Seventh, if you're hungry, you can buy food from food trucks. Eighth, you can watch fireworks at Hilton Hawaiian Village. Eighth, you can watch fireworks at Hilton Hawaiian Village. Ninth, you can buy a fish.",
"You need to think up and forward. So don't go O Mio Papi. Don't cover with your upper lip. You want to make sure. O Mio Papi. Oh. Oh. Oh. Covered. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. And there's always a little bit of portamento. This is very much the bel canto area here. And this is a little later actually. But you want to include a very flowy flowy kind of phrasing here. And the way we do that is by doing a little bit of portamento. Now portamento again to remind you. It really moves at the speed of your vibrato. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh. Oh."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from Qwen/Qwen3-Embedding-0.6B. It maps sentences & paragraphs to a 1024-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': 512, 'do_lower_case': False, 'architecture': 'Qwen3Model'})
(1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': True, '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("sentence_transformers_model_id")
# Run inference
queries = [
"Instruct: Given a question about a video transcript, retrieve the most relevant transcript passage.\nQuery: How do you maintain an open throat and a lifted soft palate in opera as you ascend in pitch?",
]
documents = [
"Eeeeee! Too narrow in the throat. Too open, I can't make an E. Eeeeee! And then again. ZE FERE LTE LOSINGIARI DE VOLLO ZE FERE FE-E-E-I In the middle. ZE FERE LTE LOSINGIARI And then later it has E GYDITE. So... Eeeeee! Eeeeee! Eeeeee! Eeeeee! Eeeeee! Eeeeee! Eeeeee! Now I'm at an F sharp. Now comes the caveat. As you are actually getting higher, those closed vowels, now they do slightly open in the mouth.",
"As artists, we use lines a lot. We use them as placeholders in the early stages of our drawings to measure, indicate perspective, contour, and gesture. And we use them in the final stages of our drawings when we're shading tone or as a powerful visual element that can guide the eye. So bad line quality can quickly ruin a drawing and give off a really bad impression of your skill. You want to avoid building habits of poor line quality. The longer you practice bad lines, the stronger those habits will become and the harder it will be to break out of those bad habits. So I want to get you on the path to develop the good habits. And if you liked this video, make sure to check out the full drawing basics course at proko.com slash drawing. It's designed to give you the foundation you need to draw from observation or from imagination. Number one, avoid the common mistakes. Two very common mistakes are short scratchy lines and chaotic searching lines.",
"This whole area asserts Ottoman wealth and by the way guys I wore this blue shirt for the Blue Mosque today. Thinking about it now we probably would recommend you do a tour for all of this. To dive deeper into the history there's so much to learn. Day four. Since we did so much the day before we decided to do some mild sightseeing and lunch in the quaint area of Balant. It's wonderfully colourful and reminds us a lot of Bo Carp in Cape Town. Oh my word, it's so cute already. For that evening we booked a Bosphorus boat cruise through Get Your Guide once again. You can't come to Istanbul without cruising down the Bosphorus Strait. Tonight we're on a yacht to eat delicious Turkish food and watch live Turkish performances. I'm so excited and by the way guys look at the view behind me. Oh this is gonna be great. Honestly though it wasn't quite our cup of tea. It was just a little bit too touristy for us. But you might like it. The views were undoubtedly spectacular though. And that was basically the end of our time in Istanbul. There's so much to do in tea in this city. Like you could just spend the whole day counting cats if you wanted to. There's almost half a million strays here. But here's a list of other things that look great too.",
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 1024] [3, 1024]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.4922, 0.2266, 0.1797]], dtype=torch.bfloat16)
val_irInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.5238 |
| cosine_accuracy@3 | 0.746 |
| cosine_accuracy@5 | 0.836 |
| cosine_accuracy@10 | 0.9683 |
| cosine_precision@1 | 0.5238 |
| cosine_precision@3 | 0.3404 |
| cosine_precision@5 | 0.2772 |
| cosine_precision@10 | 0.1857 |
| cosine_recall@1 | 0.2904 |
| cosine_recall@3 | 0.4897 |
| cosine_recall@5 | 0.6495 |
| cosine_recall@10 | 0.8344 |
| cosine_ndcg@10 | 0.6498 |
| cosine_mrr@10 | 0.6582 |
| cosine_map@100 | 0.5579 |
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| details |
|
|
| anchor | positive |
|---|---|
Instruct: Given a question about a video transcript, retrieve the most relevant transcript passage. |
rap for sometimes being a bit too crowded, but sunset, the vibe is great. There's often live music. Everybody's just enjoying watching that sun go down. So it's a great place to start your vacation. You can even hop in one of the catamarans that has beach loading and go out sailing and watch the sunset that way. That's a great way to start. There you go. Gosh, we're good. Oh my gosh. You're lucky you found this channel. Day number two. And guess what? You are up early, my friend, because you have jet lag. Real bad. Real bad. Especially if you have kids with you. Wow. Good luck. So we are going to take advantage of that today and you are going to head up to the North Shore to go snorkeling at Kualima Cove or just enjoy a nice beach day up there. Kualima Cove is at Turtle Bay Resort, which is like five-star luxury resort that's been remodeled, but all beaches in Hawaii are public. And this is a great place to go snorkeling. It's well protected. And yeah, there's public parking. So enjoy ... |
Instruct: Given a question about a video transcript, retrieve the most relevant transcript passage. |
So are you going to Oahu, Hawaii and you're either too cheap or broke to get a rental car for your time there? There's no judgment in that question because that was my mentality and you definitely can have an amazing time in Oahu, Hawaii even for like a week or so without any rental car whatsoever. I was there for a month and mostly got by without a rental car so I'm definitely very qualified to give you an amazing seven-day one-week itinerary for Oahu, Hawaii with no rental car. That being said let's start off with day number zero or arrival day. So unless you're a very strong swimmer or taking a very fast speedboat you'll be arriving at the Daniel K. Inouye International Airport. Probably a little bit jet lagged. It's definitely a little bit tired so let's just get to your hotel and check in. I do recommend staying in Waikiki which people might kind of roll their eyes or scoff at because it's very touristic. It's like a little bit of a concrete jungle in the middle of Hawaii built on... |
Instruct: Given a question about a video transcript, retrieve the most relevant transcript passage. |
do you want to walk there and burn out your legs a little bit? It's up to you, depends on how much energy you have to spare. Either way the hike isn't so difficult. It costs about five dollars to enter, walking that is, which you'll be doing because you don't have a car of course, and I believe nowadays you have to either reserve a time slot or something like that. It's also very busy so the earlier you go the better. The hike itself is really cool, it's not too difficult like I said, you go through a little bit of a tunnel and at the end you will get some amazing views of Waikiki, Waikiki Beach, and some other parts of the island which you're probably super excited to explore which you'll definitely do on other days besides today. So once you finish hiking Diamond Head, return back down the way you came, it's an out and back trail, and head to the nearby neighborhood called Kaimuki. Now Kaimuki is a really cool and trendy sort of hip and sort of like a college town feel neighborhood w... |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"gather_across_devices": false,
"directions": [
"query_to_doc"
],
"partition_mode": "joint",
"hardness_mode": null,
"hardness_strength": 0.0
}
num_train_epochs: 10learning_rate: 0.0002warmup_steps: 0.1gradient_accumulation_steps: 4eval_strategy: stepsper_device_eval_batch_size: 32load_best_model_at_end: Trueremove_unused_columns: Falseper_device_train_batch_size: 8num_train_epochs: 10max_steps: -1learning_rate: 0.0002lr_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: 4average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Falsefp16: Falsebf16_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: trackioeval_strategy: stepsper_device_eval_batch_size: 32prediction_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: Trueignore_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: Falselabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_backend: Noneddp_timeout: 1800fsdp: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}deepspeed: 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 | val_ir_cosine_ndcg@10 |
|---|---|---|---|
| 0.3604 | 20 | 0.9475 | - |
| 0.7207 | 40 | 0.8095 | - |
| 1.0721 | 60 | 0.5994 | - |
| 1.4324 | 80 | 0.4689 | - |
| 1.7928 | 100 | 0.5015 | 0.6131 |
| 2.1441 | 120 | 0.4094 | - |
| 2.5045 | 140 | 0.3802 | - |
| 2.8649 | 160 | 0.3823 | - |
| 3.2162 | 180 | 0.3307 | - |
| 3.5766 | 200 | 0.3340 | 0.6115 |
| 3.9369 | 220 | 0.3041 | - |
| 4.2883 | 240 | 0.2975 | - |
| 4.6486 | 260 | 0.3046 | - |
| 5.0 | 280 | 0.2837 | - |
| 5.3604 | 300 | 0.2595 | 0.6423 |
| 5.7207 | 320 | 0.2558 | - |
| 6.0721 | 340 | 0.2673 | - |
| 6.4324 | 360 | 0.2468 | - |
| 6.7928 | 380 | 0.2649 | - |
| 7.1441 | 400 | 0.2285 | 0.6564 |
| 7.5045 | 420 | 0.2203 | - |
| 7.8649 | 440 | 0.2180 | - |
| 8.2162 | 460 | 0.1992 | - |
| 8.5766 | 480 | 0.1888 | - |
| 8.9369 | 500 | 0.1936 | 0.6498 |
| 9.2883 | 520 | 0.2144 | - |
| 9.6486 | 540 | 0.2128 | - |
| 10.0 | 560 | 0.2116 | - |
@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{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},
}