Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 16
How to use schaitanya/modernbert-embed-base-transcript-documents-v1 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("schaitanya/modernbert-embed-base-transcript-documents-v1")
sentences = [
"What should you do if you experience any bleeding after 3 months of starting HRT?",
"So it is best used actually not alone but with the help of hair reduction laser as an adjuvant therapy. Then talking about the cosmetic treatments. So shaving, threading, waxing.\n\nThese methods are pretty good but they are temporary because they do not cause a permanent damage to the hair follicle. Does shaving leads to increased hair growth? So medically it has been proven with experiments, control experiments that that is not the case. Medically we have done shaving then after that we have checked the hair caliber, hair length, rate of growth.\n\nIt is bound to be the same. Then we have hair removal creams. They basically work by dissolving the shaft of the hair and once again these creams may cause allergies in some people.\n\nSo make sure that you do a patch test before using them. Then we have the bleaches. So this basically works by lightening the hair color and making it less noticeable against the skin and most of these bleaching agents contain a chemical called hydrogen peroxide.\n\nSo once again make sure that you do a patch test on the skin before using them. Then talking about the permanent method of the hair removal. So few years back people used to do electrolysis.\n\nSo it is difficult to target larger areas of skin with electrolysis and it can be very time consuming also. But now we have lasers available which are very effective. They can be used to target bigger areas of the skin.\n\nSo we asked Dr. Sachin about what types of lasers, how to choose where to go for laser, how many sitting and a lot more. Laser hair reduction treatment essentially involves a single wavelength of light which gets absorbed inside your hair follicle, the color inside it and partially causes damage so that it doesn't either produce hair or produces hair which is very thin and almost baby like or it delays the growth a lot. So let's say if you shave and your hair comes back in five days or ten days, once you do laser and you reach a certain point where you've done a certain number of sessions, it may not come for three months or four months and you only have to do maintenance sessions then.\n\nBut you have to realize the right candidate for doing laser hair reduction is somebody who's got terminal hair, somebody who's got thick, coarse hair.",
"(0:00 - 0:59)\nPeriods, Menses, Menstruation, Monthly, Maasik, Mahawari, so how can something which is so very essential for the survival of species be so dirty and impure? Something which is very normal, which happens to 50% of the population every month. Something which is the sign of womanhood, something which is the sign of motherhood. How can that be so impure? How can that be so dirty? So why don't people talk about it? As far as I know, even in schools, the sex education class or the e-production chapter is in 7th or 8th class.\n\n(0:59 - 1:33)\nBut these days, as a gynecologist, I see young girls as young as 8 or 9 years coming to me with the periods. We don't talk about it in school, parents don't talk about it, so who will? I find it so strange when the women in the family actually tell their daughters not to do this, not to do this. I don't understand even till today, even in educated class, women don't find it comfortable to talk to their fathers, their brothers about the period.\n\n(1:34 - 2:07)\nFrom centuries till today, when you go to buy a pad, the shopkeeper first wraps the pad in the newspaper, then puts it in black polythene, and then gives it to you. And since we do not talk about this, we also do not talk about our right to have the sex education, the right to have the basic sanitation during periods, the right to have the access to menstrual hygiene products. And we also lose our right to have the opportunities in life.\n\n(2:07 - 2:44)\nHow many opportunities will there be in life, which she may miss due to periods. So what is a period? Period happens because the inner lining of the uterus, which we call medically endometrium, every month, under the influence of hormones, which are estrogen and progesterone, it proliferates, and at the end of the month, it dies and it sheds off in form of bleeding. So this interplay of hormones happens because the body prepares the uterus every month for the pregnancy.\n\n(2:45 - 3:00)\nAnd when the pregnancy does not happen, all that preparation goes waste and the bleeding happens. So let's today and onwards, talk about the periods the way we should be talking about them. My name is Pooja Gupta, I am from Uttar Pradesh.\n\n(3:01 - 3:06)\nMy name is Shashi Yadav. My name is Hemanti. My name is Sejal Kumar and I am from Delhi.\n\n(3:06 - 3:13)\nMy name is Beena.",
"Your healthcare professional should discuss your individual risks based on the research evidence at your consultation.\nCan I still have HRT if I have had breast cancer or clots in my legs or lungs?\nHRT may still be an option for you and you should discuss this with your healthcare professional, who may seek advice or refer you to a menopause specialist.\nCan I take HRT if I have diabetes or high blood pressure?\nHRT should not affect your blood sugar control. If you are diabetic or have very high blood pressure, your healthcare professional may consult with a specialist before prescribing HRT.\nWould taking HRT prevent dementia?\nIt is not known whether HRT affects the development of dementia.\nDo I still need to use contraception when taking HRT?\nHRT does not provide contraception. You need to continue using contraception for 1 year after your last period if this happens after the age of 50 years. If your last period happens before you are 50 years of age then you need to continue using contraception for 2 years.\nWhen should I seek advice after starting HRT?\nYou should have a review appointment with your healthcare professional after 3 months of starting or changing HRT, and then yearly thereafter if all remains well.\nYou may notice some vaginal bleeding in the first 3 months of starting or changing HRT, but if you experience any bleeding after 3 months then you should see your healthcare professional straight away.\nHow long can I take HRT for?\nThere are no set time limits for how long you can be on HRT. The benefits and risks of taking HRT will depend on your individual situation, and your healthcare professional should discuss these with you.\nHow do I stop HRT?\nYou can stop your HRT suddenly or reduce gradually before stopping it. The chances of your symptoms coming back is the same either way.\nDo I need a referral to a menopause specialist?"
]
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 semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'max_seq_length': 1024, 'do_lower_case': False}) with Transformer model: ModernBertModel
(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})
(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("schaitanya/modernbert-embed-base-transcript-documents-v1")
# Run inference
sentences = [
'What is the recommendation for a water birth if a woman has COVID-19?',
'- Specific medications and antibody treatment.\nIf you are very unwell, your healthcare team may advise that your baby needs to be born early to help with your own treatment and recovery. How and when this may happen will depend on your individual situation.\nIf I have COVID-19, will this affect where I give birth and my choice of pain relief in labour?\nIf you have symptoms and have tested positive for COVID-19 at the time of birth:\nIt is recommended that you give birth in a consultant led maternity unit where you and your baby can be monitored more closely during labour.\nIt is safe for you to have a vaginal birth, and if you and your baby are both well you do not need to have a planned caesarean birth. Your birth choices should be respected and followed as closely as possible.\nA caesarean birth may be recommended if you or your baby are unwell or there are other complications. However, your chance of needing an emergency caesarean birth may be higher than usual.\nAll the usual options for pain relief for labour and birth are available to you, however a water birth is not recommended. This is because it is harder to monitor and give you any treatments needed.\nIf I have COVID-19, will this affect care of my baby after birth?\nIf your baby is well and does not require care in the neonatal unit, you will stay together after you have given birth. Skin-to-skin contact is encouraged.\nHow you feed your baby is dependent on your own circumstances and preferences, and your choices will be supported. Breastfeeding may help pass protection from infections (including COVID-19) to your baby. There is no strong evidence to show that COVID-19 can be passed on in breast milk.',
"(0:00 - 4:09)\nSo what is the color of the cake? Pink or blue? What is the color of the nursery? Pink or blue? And what about the baby's clothes? Are they frilly skirts or the soccer shirts? Have you ever wondered what is it which decides the sex of the baby inside? How that little pea-shaped embryo grows into that little baby girl or a baby boy? Since ages it was the mother who was held responsible for the sex of the baby. But now we know it is the father who decides whether it is going to be a pretty little daughter or a handsome baby boy. So hello everyone, this is Dr. Anjali Kumar once again bringing you greetings from Maitri.\n\nMaitri is a space where we talk anything and everything about women's health. So today we are starting our pregnancy series season 2 with this very question which every parent wants to know. So the baby inherits its genes from both the parents.\n\nThe genes are present in the DNA and the DNA is present in the chromosomes and the chromosomes are present in the nucleus of the cell. Every human cell has 23 pairs of chromosomes. So total 46 chromosomes.\n\nEach pair inherited from one parent. 22 of these pairs are called autosomes. They look the same in both males and females.\n\nThe 23rd pair, the sex chromosomes, that's the special one. It differs between males and females. Females have two copies of X chromosomes which makes it XX, while males have one X and one Y which makes it XY.\n\nSo at the time of fertilization, the father's sperm and the mother's egg each contributes one sex chromosomes to the baby. The mother can contribute only X since it has two copies of X chromosomes only, while the father can contribute either X or Y chromosomes. So the baby's biological or the genetic sex which is male or female is determined by the chromosome which the father contributes.\n\nSo if the father contributes his Y chromosome, it will be a male baby which is XY, while if he contributes the X chromosome, it will be a female baby XX. Baby's sex is determined at the time of fertilization or the conception when the sperm fertilizes the egg. Now this typically happens around day 14 to maybe day 17 in women who have regular cycles.\n\nNow this is the time when you don't even know that you are pregnant. You might not be even expecting a pregnancy. This is the time when the baby's sex is decided.\n\nAfter that, nobody and nothing can ever change the genetic sex of the baby. No medicine, no food, no kada, no jariputi, no exercise can change the sex of the baby afterwards.",
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
InformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.5191 |
| cosine_accuracy@3 | 0.7441 |
| cosine_accuracy@5 | 0.8 |
| cosine_accuracy@10 | 0.8912 |
| cosine_precision@1 | 0.5191 |
| cosine_precision@3 | 0.248 |
| cosine_precision@5 | 0.16 |
| cosine_precision@10 | 0.0891 |
| cosine_recall@1 | 0.5191 |
| cosine_recall@3 | 0.7441 |
| cosine_recall@5 | 0.8 |
| cosine_recall@10 | 0.8912 |
| cosine_ndcg@10 | 0.7051 |
| cosine_mrr@10 | 0.6457 |
| cosine_map@100 | 0.6503 |
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| details |
|
|
| anchor | positive |
|---|---|
What lifestyle changes are recommended before pregnancy? |
(0:02 - 0:50) |
Does the absence of symptoms indicate an absence of infection? |
(0:00 - 0:21) |
When does pre-eclampsia usually occur during pregnancy? |
What is pre-eclampsia? |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
eval_strategy: epochper_device_train_batch_size: 16gradient_accumulation_steps: 16learning_rate: 2e-05num_train_epochs: 4lr_scheduler_type: cosinewarmup_ratio: 0.1log_level: debugbf16: Truetf32: Trueload_best_model_at_end: Trueoptim: adamw_torch_fusedbatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: epochprediction_loss_only: Trueper_device_train_batch_size: 16per_device_eval_batch_size: 8per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 16eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 2e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 4max_steps: -1lr_scheduler_type: cosinelr_scheduler_kwargs: {}warmup_ratio: 0.1warmup_steps: 0log_level: debuglog_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: Falseuse_ipex: Falsebf16: Truefp16: Falsefp16_opt_level: O1half_precision_backend: autobf16_full_eval: Falsefp16_full_eval: Falsetf32: Truelocal_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: Trueignore_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}deepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthddp_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: Falsegradient_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: Nonedispatch_batches: Nonesplit_batches: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: Falseneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseeval_use_gather_object: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | cosine_ndcg@10 |
|---|---|---|---|
| 0.4178 | 10 | 5.9152 | - |
| 0.8355 | 20 | 2.7824 | - |
| 0.9608 | 23 | - | 0.6781 |
| 1.2924 | 30 | 1.9575 | - |
| 1.7102 | 40 | 1.5202 | - |
| 1.9608 | 46 | - | 0.6943 |
| 2.1671 | 50 | 1.4008 | - |
| 2.5849 | 60 | 1.1741 | - |
| 2.9608 | 69 | - | 0.7031 |
| 3.0418 | 70 | 1.0995 | - |
| 3.4595 | 80 | 1.0416 | - |
| 3.8773 | 90 | 1.1648 | - |
| 3.9608 | 92 | - | 0.7051 |
@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
answerdotai/ModernBERT-base
from sentence_transformers import SentenceTransformer model = SentenceTransformer("schaitanya/modernbert-embed-base-transcript-documents-v1") sentences = [ "What should you do if you experience any bleeding after 3 months of starting HRT?", "So it is best used actually not alone but with the help of hair reduction laser as an adjuvant therapy. Then talking about the cosmetic treatments. So shaving, threading, waxing.\n\nThese methods are pretty good but they are temporary because they do not cause a permanent damage to the hair follicle. Does shaving leads to increased hair growth? So medically it has been proven with experiments, control experiments that that is not the case. Medically we have done shaving then after that we have checked the hair caliber, hair length, rate of growth.\n\nIt is bound to be the same. Then we have hair removal creams. They basically work by dissolving the shaft of the hair and once again these creams may cause allergies in some people.\n\nSo make sure that you do a patch test before using them. Then we have the bleaches. So this basically works by lightening the hair color and making it less noticeable against the skin and most of these bleaching agents contain a chemical called hydrogen peroxide.\n\nSo once again make sure that you do a patch test on the skin before using them. Then talking about the permanent method of the hair removal. So few years back people used to do electrolysis.\n\nSo it is difficult to target larger areas of skin with electrolysis and it can be very time consuming also. But now we have lasers available which are very effective. They can be used to target bigger areas of the skin.\n\nSo we asked Dr. Sachin about what types of lasers, how to choose where to go for laser, how many sitting and a lot more. Laser hair reduction treatment essentially involves a single wavelength of light which gets absorbed inside your hair follicle, the color inside it and partially causes damage so that it doesn't either produce hair or produces hair which is very thin and almost baby like or it delays the growth a lot. So let's say if you shave and your hair comes back in five days or ten days, once you do laser and you reach a certain point where you've done a certain number of sessions, it may not come for three months or four months and you only have to do maintenance sessions then.\n\nBut you have to realize the right candidate for doing laser hair reduction is somebody who's got terminal hair, somebody who's got thick, coarse hair.", "(0:00 - 0:59)\nPeriods, Menses, Menstruation, Monthly, Maasik, Mahawari, so how can something which is so very essential for the survival of species be so dirty and impure? Something which is very normal, which happens to 50% of the population every month. Something which is the sign of womanhood, something which is the sign of motherhood. How can that be so impure? How can that be so dirty? So why don't people talk about it? As far as I know, even in schools, the sex education class or the e-production chapter is in 7th or 8th class.\n\n(0:59 - 1:33)\nBut these days, as a gynecologist, I see young girls as young as 8 or 9 years coming to me with the periods. We don't talk about it in school, parents don't talk about it, so who will? I find it so strange when the women in the family actually tell their daughters not to do this, not to do this. I don't understand even till today, even in educated class, women don't find it comfortable to talk to their fathers, their brothers about the period.\n\n(1:34 - 2:07)\nFrom centuries till today, when you go to buy a pad, the shopkeeper first wraps the pad in the newspaper, then puts it in black polythene, and then gives it to you. And since we do not talk about this, we also do not talk about our right to have the sex education, the right to have the basic sanitation during periods, the right to have the access to menstrual hygiene products. And we also lose our right to have the opportunities in life.\n\n(2:07 - 2:44)\nHow many opportunities will there be in life, which she may miss due to periods. So what is a period? Period happens because the inner lining of the uterus, which we call medically endometrium, every month, under the influence of hormones, which are estrogen and progesterone, it proliferates, and at the end of the month, it dies and it sheds off in form of bleeding. So this interplay of hormones happens because the body prepares the uterus every month for the pregnancy.\n\n(2:45 - 3:00)\nAnd when the pregnancy does not happen, all that preparation goes waste and the bleeding happens. So let's today and onwards, talk about the periods the way we should be talking about them. My name is Pooja Gupta, I am from Uttar Pradesh.\n\n(3:01 - 3:06)\nMy name is Shashi Yadav. My name is Hemanti. My name is Sejal Kumar and I am from Delhi.\n\n(3:06 - 3:13)\nMy name is Beena.", "Your healthcare professional should discuss your individual risks based on the research evidence at your consultation.\nCan I still have HRT if I have had breast cancer or clots in my legs or lungs?\nHRT may still be an option for you and you should discuss this with your healthcare professional, who may seek advice or refer you to a menopause specialist.\nCan I take HRT if I have diabetes or high blood pressure?\nHRT should not affect your blood sugar control. If you are diabetic or have very high blood pressure, your healthcare professional may consult with a specialist before prescribing HRT.\nWould taking HRT prevent dementia?\nIt is not known whether HRT affects the development of dementia.\nDo I still need to use contraception when taking HRT?\nHRT does not provide contraception. You need to continue using contraception for 1 year after your last period if this happens after the age of 50 years. If your last period happens before you are 50 years of age then you need to continue using contraception for 2 years.\nWhen should I seek advice after starting HRT?\nYou should have a review appointment with your healthcare professional after 3 months of starting or changing HRT, and then yearly thereafter if all remains well.\nYou may notice some vaginal bleeding in the first 3 months of starting or changing HRT, but if you experience any bleeding after 3 months then you should see your healthcare professional straight away.\nHow long can I take HRT for?\nThere are no set time limits for how long you can be on HRT. The benefits and risks of taking HRT will depend on your individual situation, and your healthcare professional should discuss these with you.\nHow do I stop HRT?\nYou can stop your HRT suddenly or reduce gradually before stopping it. The chances of your symptoms coming back is the same either way.\nDo I need a referral to a menopause specialist?" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4]