Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 19
How to use htdht/e5_base_finetuned_mnrl_v2 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("htdht/e5_base_finetuned_mnrl_v2")
sentences = [
"query: bàn phím gaming switch yellow",
"passage: Thực phẩm bảo vệ sức khỏe BioIsland DHA For Pregnancy BioIsland DHA For Pregnancy là thực phẩm bảo vệ sức khỏe thiết yếu dành cho mẹ bầu, hỗ trợ cung cấp hàm lượng DHA tinh khiết, an toàn cho sự phát triển não bộ và thị giác của thai nhi. Sản phẩm được sản xuất với quy trình nghiêm ngặt, đảm bảo chất lượng và hiệu quả. Bổ sung DHA đầy đủ trong thai kỳ giúp bé yêu chào đời khỏe mạnh và thông minh hơn. Sản phẩm hiện có mặt tại hơn 1102 siêu thị và sẵn sàng giao nhanh tận nhà khi bạn đặt mua online, mang đến sự tiện lợi tối đa cho các mẹ.",
"passage: Bàn Phím Cơ Có Dây Gaming Razer BlackWidow V3 Tenkeyless Yellow Switch Nâng tầm trải nghiệm gaming của bạn với Bàn Phím Cơ Có Dây Gaming Razer BlackWidow V3 Tenkeyless Yellow Switch. Thiết kế Tenkeyless nhỏ gọn, tối ưu không gian làm việc, cùng bộ switch Yellow cho tốc độ phản hồi siêu nhanh và hành trình phím êm ái, lý tưởng cho các trận chiến game kịch tính. Bàn phím mang đến cảm giác gõ thoải mái, độ bền cao, là lựa chọn hoàn hảo cho các game thủ chuyên nghiệp. Sản phẩm chính hãng Razer, đảm bảo chất lượng và hiệu suất vượt trội. Tận hưởng ưu đãi giao hàng miễn phí toàn quốc và chính sách 1 đổi 1 trong tháng đầu tiên nếu có lỗi.",
"passage: Sữa Tươi Tiệt Trùng TH True Milk Nguyên Chất Bịch 220Ml Thưởng thức hương vị sữa tươi nguyên chất, tinh túy từ thiên nhiên với Sữa Tươi Tiệt Trùng TH True Milk Nguyên Chất Bịch 220Ml. Sản phẩm được làm hoàn toàn từ sữa tươi sạch của trang trại TH, không bổ sung sữa bột hay chất béo sữa, giữ trọn vẹn vị ngon tự nhiên và giàu dinh dưỡng. Mỗi bịch sữa 220ml cung cấp năng lượng, protein, canxi, cùng các vitamin thiết yếu như A, D, B1, B2, hỗ trợ phát triển thể chất và trí tuệ. Sản phẩm đã qua tiệt trùng, đảm bảo an toàn vệ sinh thực phẩm, rất tiện lợi để sử dụng hàng ngày hoặc mang theo khi di chuyển. Ngon hơn khi ướp lạnh, sữa TH True Milk Nguyên Chất là thức uống bổ dưỡng cho cả gia đình."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from intfloat/multilingual-e5-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': 'XLMRobertaModel'})
(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("sentence_transformers_model_id")
# Run inference
sentences = [
'query: bàn phím bluetooth màu đen',
'passage: Bàn Phím Bluetooth Keychron B1P-K9 Pro Trải nghiệm sự kết hợp hoàn hảo giữa công nghệ và thiết kế với Bàn Phím Bluetooth Keychron B1P-K9 Pro chính hãng. Phiên bản màu đen mạnh mẽ, sang trọng, dễ dàng hòa hợp với mọi không gian làm việc, từ văn phòng đến gaming setup. Khả năng kết nối Bluetooth ổn định mang đến sự tiện lợi tối đa, giúp bạn làm việc linh hoạt trên nhiều thiết bị mà không bị giới hạn bởi dây cáp. Keychron B1P-K9 Pro được chế tác từ vật liệu cao cấp, đảm bảo độ bền bỉ và mang lại cảm giác gõ phím êm ái, chính xác, đáp ứng mọi nhu cầu sử dụng. Cam kết giao hàng miễn phí toàn quốc trong 1 giờ và 1 đổi 1 trong tháng đầu tiên nếu sản phẩm lỗi.',
'passage: Áo Bra Nữ 2XU Ribbed Longline - Xanh Dương Áo Bra Nữ 2XU Ribbed Longline màu xanh dương mang đến sự kết hợp hoàn hảo giữa phong cách và hiệu suất cho phái đẹp. Với thiết kế gân sọc và dáng longline, áo không chỉ thời trang mà còn cung cấp độ che phủ và hỗ trợ tốt trong quá trình tập luyện. Sản phẩm có sẵn đa dạng kích cỡ từ XS đến XL, đảm bảo vừa vặn với nhiều vóc dáng. Đây là sản phẩm chính hãng từ 2XU, cam kết chất lượng cao, giúp bạn tự tin và thoải mái chinh phục mọi thử thách thể thao.',
]
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.7873, 0.0174],
# [0.7873, 1.0000, 0.0220],
# [0.0174, 0.0220, 1.0000]])
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| modality | text | text | |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
query: bánh dẻo |
passage: Bánh Mochi Sachi Vị Cam Gói 200G Thưởng thức hương vị tươi mát của Bánh Mochi Sachi Vị Cam 200G, món quà ngọt ngào từ Nhật Bản. Bánh mochi dẻo thơm, dai dai, quyện cùng nhân cam chua ngọt dịu dàng, mang đến trải nghiệm ẩm thực độc đáo. Sản phẩm được làm từ maltose, đường, gạo nếp, dầu cọ và hương cam tự nhiên, an toàn cho sức khỏe. Ngon hơn khi thưởng thức lạnh, bánh mochi Sachi là lựa chọn hoàn hảo cho bữa tráng miệng hoặc món ăn vặt. Bảo quản nơi khô ráo, tránh ánh nắng và nhiệt độ cao. |
1.0 |
query: ốp lưng pc tpu cho iphone 14 pro max |
passage: Ốp lưng iPhone 14 Pro Max PC TPU DEKEY Crystal case Mang đến sự bảo vệ toàn diện và vẻ ngoài tinh tế cho iPhone 14 Pro Max với ốp lưng DEKEY Crystal case. Chất liệu PC và TPU cao cấp được sử dụng để tạo nên một sản phẩm vừa cứng cáp, vừa có khả năng đàn hồi, giúp chống lại các tác động mạnh từ bên ngoài. Thiết kế Crystal case trong suốt cho phép bạn khoe trọn vẻ đẹp của chiếc điện thoại, đồng thời công nghệ chống ố vàng tiên tiến giúp duy trì sự sáng bóng theo thời gian. Màu trắng trang nhã, ốp lưng ôm vừa vặn, không làm tăng thêm độ dày cho máy, mang lại cảm giác cầm nắm thoải mái. DEKEY Crystal case là sự đầu tư xứng đáng cho dế yêu của bạn. |
1.0 |
query: tay cầm chơi game machenike trắng |
passage: Tay cầm chơi game Machenike Trắng G3s Nâng tầm trải nghiệm chơi game của bạn với Tay cầm chơi game Machenike Trắng G3s chính hãng. Thiết kế tinh tế màu trắng, mang đến cảm giác cầm nắm thoải mái và thao tác chính xác. Sản phẩm là lựa chọn lý tưởng cho các game thủ yêu thích sự gọn nhẹ và hiệu năng ổn định. Tận hưởng những giờ phút giải trí đỉnh cao với tay cầm Machenike G3s, được bảo hành trên toàn quốc. Mua ngay để nhận ưu đãi hấp dẫn, giao hàng nhanh chóng và thanh toán tiện lợi tại nhà. |
1.0 |
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
}
per_device_train_batch_size: 16num_train_epochs: 2per_device_eval_batch_size: 16multi_dataset_batch_sampler: round_robinper_device_train_batch_size: 16num_train_epochs: 2max_steps: -1learning_rate: 5e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0optim: 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: 1label_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: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 16prediction_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: round_robinrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.2198 | 500 | 0.1259 |
| 0.4396 | 1000 | 0.0963 |
| 0.6593 | 1500 | 0.0894 |
| 0.8791 | 2000 | 0.0811 |
| 1.0989 | 2500 | 0.0787 |
| 1.3187 | 3000 | 0.0606 |
| 1.5385 | 3500 | 0.0663 |
| 1.7582 | 4000 | 0.0657 |
| 1.9780 | 4500 | 0.0640 |
@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},
}
Base model
intfloat/multilingual-e5-base