Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 15
How to use knguyennguyen/mpnet_jacket4k with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("knguyennguyen/mpnet_jacket4k")
sentences = [
"men's jacket featuring a waterproof outer layer, an insulated inner layer, and multiple secure pockets for storage.",
"Title: Pure Leather Biker Short Jacket Black Men’s Bike Jackets - Cowhide Top Grain Classic Belted Strap Descripion: ['We Believe in Beauty of Simplicity' 'PURE LEATHER'\n 'jackets are negligible and made for regular wear. Our plans are ageless any style without overwhelming it, in light of the fact that there is'\n 'Beauty in Simplicity' '.' 'Product Detail:'\n 'This black leather jacket for men is traditional yet contemporary and useful ranging from your weekend sport coat. With great style, this cowhide leather cool leather jackets for men will keep you warm and comfortable in all types of weather. The style is similar to our PR-40 in Natural Sheep Leather but this one comes in a different leather altogether Cow Natural. Molds need to be removed because they are prone to breeding when three Parts of it are in excess. Parts are dirt, its multiplicity, and temperature. Firstly, you have to hang it on a hanger in a nicely-ventilated place.'\n 'Note:'\n 'The color will become slightly darker due to its transparent appearance. Do not stretch it for extended time as it will fall prey to different proportions. Jackets from Pure Leather are made by caring people who love their jobs, so you won’t get annoyed or disappointed when wearing them!! (Do Not Wash. Do Not Bleach. Do Not Tumble. Do Not Iron, Dry Clean only- Satisfaction guaranteed'\n 'A Great Gift:'\n 'These beautiful Jackets Would be a perfect gift for that special someone in your life. Buy these jackets for your Husband, Son, Brother, or best friend, and without a doubt you have purchased the perfect present for the any occasion, whether it is for Father’s Day, Valentine-day, Christmas, Graduation or their Birthday.'\n 'Material:' 'Cowhide Leather' 'Colors:' 'Black' 'Click' 'ADD TO CART'\n 'to order your Ancient Jacket' 'TODAY!']",
"Title: Pendleton Men's Jacquard Sherpa-Lined Shirt Jacket Descripion: ['New style for Pendleton but using our iconic Harding print. Taking our classic shirt jacket and lining it with soft sherpa for warmth.']",
"Title: THE NORTH FACE Men's Clement Triclimate Jacket Descripion: ['The North Face Size Chart' 'The North Face Size Chart'\n 'Please note, the logo and hardware color may vary in styles marked as Prior Season.'\n 'Please note, the logo and hardware color may vary in styles marked as Prior Season.'\n 'Your go-to jacket all season long, this versatile The North Face® Clement Triclimate Jacket system pairs a breathable, waterproof shell with a warm, insulated liner jacket'\n 'Your go-to jacket all season long, this versatile The North Face® Clement Triclimate Jacket system pairs a breathable, waterproof shell with a warm, insulated liner jacket'\n 'Waterproof, insulated three-in-one ski jacket.'\n 'Waterproof, insulated three-in-one ski jacket.'\n 'Removable, helmet-compatible hood.' 'Removable, helmet-compatible hood.'\n 'Secure-zip chest and hand pockets.' 'Secure-zip chest and hand pockets.'\n 'Internal goggle pocket.' 'Internal goggle pocket.'\n 'Underarm vents for added breathability.'\n 'Underarm vents for added breathability.'\n 'Secure-zip wrist pocket with goggle wipe.'\n 'Secure-zip wrist pocket with goggle wipe.' 'Zip-in integration.'\n 'Zip-in integration.' 'Secure-zip hand pockets.'\n 'Secure-zip hand pockets.' '100% polyester.' '100% polyester.'\n '50D 73 G/M² 100% Recycled Polyester With Non-PFC DWR Finish.'\n '50D 73 G/M² 100% Recycled Polyester With Non-PFC DWR Finish.'\n 'Machine wash cold, hang dry.' 'Machine wash cold, hang dry.' 'Imported.'\n 'Imported.']"
]
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': 128, '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")
# Run inference
sentences = [
'a pair of statement stud earrings for brightening up outfits',
"Title: Kendra Scott Sienna Ear Jacket Earrings Descripion: ['The Kendra Scott Sienna Ear Jacket Earrings are the best bright-colored statement stud. Straight post backing. Removeable jackets. Gold plated brass. Shell detailing. Remove jewelry when swimming, bathing, or exercising. Imported.']",
"Title: TrailCrest Infant-Toddler Boys & Girls Fleece Full Zip Mock Neck Soft Jacket Descripion: ['Feel the chill! On chilly summer nights out in the wilderness or crisp spring and autumn days, these semi-fitted fleece zips are the perfect cover to keep you warm. These fleece zips are great for camping, hiking and just about any sport related activities. Featuring bright accent colors with realistic camo print to make the experience all the more exciting. Fully equipped with a mock neck collar for extra warmth, two hand pockets with hidden zippers, an adjustable drawstring at the bottom, and elastic cuffs. All set for the outdoors!']",
]
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 |
|---|---|
men's parka jacket with a concealed front closure, multiple storage pockets, and a detachable hood. |
Title: DKNY Men's Welded Short Parka Jacket Descripion: ["FUNCTIONALITY: Center front placket with hidden zipper closure, two lower flap pockets with side entry, removable hood. STYLISH FEATURES: DKNY logo on wearer's left sleeve, DKNY small logo metal zipper puller. Water resistant outer shell with faux down fill insulation."] |
a track jacket and pant set for active girls |
Title: PUMA girls Track Jacket & Pant Set Descripion: ['PUMA, a Global athletic brand, provides consumers with innovative products that successfully fuses the creative influences from the world of sport, lifestyle, and fashion.'] |
kids' hoodies made from soft fleece material, featuring a zip closure and pockets for convenience. suitable for both boys and girls, these garments are designed for warmth and comfort during colder seasons. |
Title: Eddie Bauer Kids’ Jacket - 2 Pack Ultra Soft Sherpa Fleece Hoodie Sweatshirt for Boys and Girls (5-20) Descripion: ["Eddie Bauer Kids' Plush Sherpa Fleece Zip Hoodie Sweatshirt for Boys and Girls is a great choice for the chilly fall and winter weather. This fun sweatshirt is high quality, and long lasting. This everyday clothing is a great gift for birthdays and holidays. We have several designs available, perfect for cold weather. High Quality fabric and durable, high stitch density give your boy or girl a long lasting hoodie that they'll be able to wear for years. Fashionable sherpa fleece sweatshirt for a soft feel and comfort. Full Zip jacket and quarter zip pullover allows her to have the ability to layer other tops underneath for a casual look. Comfort Fit jacket has split kangaroo pockets and cuffed sleeves to keep it from bunching and riding up. Simply machine wash and tumble dry; Please Reference the Variations for All Available Sizes & Colors! Eddie Bauer Offers Premium Clothing at Affordable Prices because we value every customer that visits our listings! Stop by Our Storefront to See the Rest of Our Great Deals; we're confident you're going to find items that anyone who needs a gift will absolutely love and adore!"] |
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