Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 16
How to use knguyennguyen/mpnet_jacket4k_adjusted with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("knguyennguyen/mpnet_jacket4k_adjusted")
sentences = [
"a leather jacket for casual occasions and weekend trips for men",
"Title: Blazer Jackets for Women Business Casual Suit Coat Zipper Crop Cardigan Work Outfits Office Long Sleeve Boyfriend Blazers Descripion: [\"Blazer Jackets for Women Business Casual Suit Coat Zipper Crop Cardigan Work Outfits Office Long Sleeve Boyfriend Blazers/Women's Casual Blazers Open Front Long Sleeve Button Work Office Blazer Jacket\"\n '【 Feature:】'\n \"✨ Women blazer casual, open front cardigan jacket comes with long sleeve and label collar. ✨ Occasion: Women's lapel pocket blazer suit perfect for casual, daily life, work office, going out, night out, travel, vacation, holiday, spring, fall, winter, etc. ✨ Women's Casual Lightweight Open Front Cardigan is extremely comfortable! It can be dressed up for business or work, or dressed down for a casual look! Good quality and versatile!\"\n '【 Size Chart】'\n \"Size:S US:6 EU:36 Bust:98cm/38.58'' Sleeve:60cm/23.62'' Front Length:60cm/23.62'' Size:M US:8 EU:38 Bust:102cm/40.16'' Sleeve:61cm/24.02'' Front Length:61cm/24.02'' Size:L US:10 EU:40 Bust:106cm/41.73'' Sleeve:62cm/24.41'' Front Length:62cm/24.41'' Size:XL US:12 EU:42 Bust:110cm/43.31'' Sleeve:63cm/24.80'' Front Length:63cm/24.80''\"\n '❤️ Please Refer to Our Size Chart for Choosing Your Most Suitable Open Front Lapel Blazer Suit/Long Sleeves Buttons Work Suit/Flap Pockets Suit Outerwear Coat, Work Blazer Suit for Women/Basic Lapel Collar Blazer Jacket for Women.'\n \"❤️BDFCY'S SERVICE:\"\n '💕About Shipping: ✨ Standard Shipping: 8-15 Biz Days to Arrive ✨ Expedited Shipping: 3-5 Biz Days to Arrive 💕Guarantee: * We endeavors 100% customer satisfaction service and experience. * If you receive damaged or wrong items,please contact us, we will provide you a satisfactory solution asap, please rest assured to purchase.* If you are satisfied with our product or service,hope you can leave your positive message,thanks for your encouragement.']",
"Title: LZJDS Mens Wool Coats Casual Regular Fit Trenchcoats Double Collar Thick Winter Peacoats Mid-Length Jacket Overcoat Descripion: [\"★Mens trench coat autumn winter long jacket overcoat business woolen coat with double collar (removable) to resist the cold and keep warm. The fashion trend of woolen coat is becoming more and more fierce. The design of this coat provides a new standardMaterial: wool blend + polyester (30% wool 70% polyester fiber)Color: black, gray, camelSize: M-170, L-175, XL-180, XXL-185, XXXL-190, XXXXL-195Style: business gentlemanFeatures: thick, single-breasted, double-layer collar, side slit pockets★Packing list: 1*Men's thick windbreaker coat★Notes:1. Please carefully refer to our size suggestion pictures (not the Amazon size chart). The jacket is a slim fit, slightly smaller than expected2. We are trying to take a photo to show the color of the item, but it may be different depending on the settings of the monitor3. Due to long-distance transportation. The coat may be a little crumpled when delivered, we are glad that you can iron it before wearing it, it will look much better.\"]",
"Title: Men Brown Air Force A-2 Leather Flight Bomber Jacket - ww2 flight jacket - Men Navy G-1 Jacket - Brown Bomber leather Jacket Descripion: [\"The G1 Men leather jacket is a premium quality, vintage jacket designed to provide a rugged and stylish look for men. The G1Leather jacket is made of high-quality distressed leather that gives it a unique, worn-in appearance. The Distressed Brown leather jacket features a stylish collar with a button closure and a front zipper closure. The G1 Men jacket also comes with two spacious pockets on the front for storing your essentials. The Leather jacket Men' cuffs and hemline are made of rib-knit fabric, which provides a comfortable fit and protects against cold winds. The Brown Bomber jacket is a timeless classic that never goes out of style. It is perfect for casual occasions, such as a night out with friends or a weekend trip. This jacket will keep you looking stylish while also providing the warmth and comfort you need.\"]"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from sentence-transformers/all-mpnet-base-v2. 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}) with Transformer model: MPNetModel
(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("knguyennguyen/mpnet_jacket4k_adjusted")
# Run inference
sentences = [
"men's winter jacket with a water-resistant exterior, thermal insulation, and multiple pockets for storage.",
"Title: Columbia Men's Grand Wall Jacket Descripion: ['Perfect for Fall and Winter, the Columbia Men’s Grand Wall Jacket combines a classic outdoor look with advanced technology to keep you warm and dry. Crafted from water resistant fabric, packed with our down-like Thermarator insulation, and lined with our signature Omni-HEAT reflective dots – this is your new go-to cold weather coat. Complete with zippered hand pockets, a chest pocket for important essentials, and binding at the cuffs — perfect to help block the cold, and lock your comfy body heat in. This men’s winter jacket is offered in multiple sizes and colors. Extended sizing available. Regular Fit. To ensure the size you choose is right, utilize our sizing chart and the following measurement instructions: For the sleeves, start at the center back of your neck and measure across the shoulder and down to the sleeve. If you come up with a partial number, round up to the next even number. For the chest, measure at the fullest part of the chest, under the armpits and over the shoulder blades, keeping the tape measure firm and level.']",
"Title: Yansguard Men's Cycling Jerseys Tops Biking Shirts Short Sleeve Bike Clothing Full Zipper Bicycle Jacket Gray, M (jersey008),J-G-M Descripion: ['100% Polyester.Ultra-soft and UV protection.Full zipper in front, easy to wear and take offHigh quality Moisture Wicking Fabric, quick-dry feature makes you feel more comfortableWith 5 Pockets for safe storage, one of which has a zipper and is waterproof!.There are reflective signs on the back of cycling jersey to enhance the safety of cycling at night']",
]
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]
sentence_0 and sentence_1| sentence_0 | sentence_1 | |
|---|---|---|
| type | string | string |
| details |
|
|
| sentence_0 | sentence_1 |
|---|---|
a heated vest for staying warm in winter |
Title: Yi-Create Heated Vest with Battery Pack Included,Unisex Heated Jacket for Men & Women,7.4v 7000mAh Quick Heated Closing Descripion: ['Yi-create Heated Vest with Battery Pack Included,Unisex Heated Jacket for Men & Women,7.4v 7000mAh Quick Heated Clothing with 3 Heating Levels,Lightweight USB Electric Heated Vest with 8 Heating Zone'] |
a mid-layer jacket for cold-weather sports and casual wear for men. men's mid-layer jacket with a combination of moisture-wicking panels and a warm, textured fabric. |
Title: Spyder Active Sports Men's Bandit Half Zip Mid-Layer Jacket Descripion: ['An excellent first layer for its combo of wicking side panels and warm sweater knit bonded to fleece everywhere else, the half zip bandit is made for cold-weather sports, but is stylish enough for just sauntering around town.'] |
a down jacket for camping and hiking adventures |
Title: Helly-Hansen Mens Verglas Icefall Down Jacket Descripion: ["An essential piece in anyone's pack; a lightweight down insulator, ready for your next adventure."] |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
per_device_train_batch_size: 128per_device_eval_batch_size: 128num_train_epochs: 5multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 128per_device_eval_batch_size: 128per_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: 5max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_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: Falseuse_ipex: 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}deepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torchoptim_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: Falsehub_always_push: Falsegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseeval_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: Falsebatch_sampler: batch_samplermulti_dataset_batch_sampler: round_robin@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
sentence-transformers/all-mpnet-base-v2