Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 15
How to use swardiantara/bert-tiny-amazon_reviews-k10-fixed-cosine with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("swardiantara/bert-tiny-amazon_reviews-k10-fixed-cosine")
sentences = [
"The product was faulty and seller offered refund and asked that I take down my previous bad review. It's been 2 weeks and I still haven't seen a refund. The diffuser worked fine for about a month (long enough to be out of the return policy) then stopped. Not worth the $40",
"I love that this holds a lot of water. The color is nice and the handle is convenient. However, it seems to be pretty poor quality. A piece of mine broke off before I even got to use it once",
"I love that this holds a lot of water. The color is nice and the handle is convenient. However, it seems to be pretty poor quality. A piece of mine broke off before I even got to use it once",
"I have alopecia and I’m constantly buying wigs, this wig feels so soft and the color is great. Only thing I would say could be better is the quality but other than that it’s good for the price."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from google/bert_uncased_L-2_H-128_A-2. It maps sentences & paragraphs to a 128-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': 'BertModel'})
(1): Pooling({'embedding_dimension': 128, 'pooling_mode': 'mean', '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("swardiantara/bert-tiny-amazon_reviews-k10-fixed-cosine")
# Run inference
sentences = [
"Arrived broken. Manufacturer defect. Two of the legs of the base were not completely formed, so there was no way to insert the casters. I unpackaged the entire chair and hardware before noticing this. So, I'll spend twice the amount of time boxing up the whole useless thing and send it back with a 1-star review of part of a chair I never got to sit in. I will go so far as to include a picture of what their injection molding and quality assurance process missed though. I will be hesitant to buy again. It makes me wonder if there aren't missing structures and supports that don't impede the assembly process.",
'I like the design of the bag, though it came a little crumpled up. Hoping everything smoothes out with use. Also very upset that I paid more for this bag and my key chain was never sent.',
'I bought these plates because I liked the way they looked. They are good enough for a single use but do not hold up too well with multiple uses. Once they are put in the microwave they start to crack quite easily.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 128]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.2434, 0.1683],
# [0.2434, 1.0000, 0.4315],
# [0.1683, 0.4315, 1.0000]])
text_a, text_b, and label| text_a | text_b | label | |
|---|---|---|---|
| type | string | string | list |
| modality | text | text | |
| details |
|
|
|
| text_a | text_b | label |
|---|---|---|
Arrived broken. Manufacturer defect. Two of the legs of the base were not completely formed, so there was no way to insert the casters. I unpackaged the entire chair and hardware before noticing this. So, I'll spend twice the amount of time boxing up the whole useless thing and send it back with a 1-star review of part of a chair I never got to sit in. I will go so far as to include a picture of what their injection molding and quality assurance process missed though. I will be hesitant to buy again. It makes me wonder if there aren't missing structures and supports that don't impede the assembly process. |
I ordered this a while ago, even using prime it took over a month to get here, now that I finally got it, I only receved 6 of the 12! Im a little upset. It's still funny, but would not recomend for someone who needs foam quick and in bulk like i do. |
[1.0, 0.0] |
Arrived broken. Manufacturer defect. Two of the legs of the base were not completely formed, so there was no way to insert the casters. I unpackaged the entire chair and hardware before noticing this. So, I'll spend twice the amount of time boxing up the whole useless thing and send it back with a 1-star review of part of a chair I never got to sit in. I will go so far as to include a picture of what their injection molding and quality assurance process missed though. I will be hesitant to buy again. It makes me wonder if there aren't missing structures and supports that don't impede the assembly process. |
I was happy to find this piece to replace on my broken Shark. Price was good and had it in a few days. When I installed it however, I was no longer satisfied. It wouldn't stay attached and kept popping of with any pull on the handle. Returned the same day it areived. |
[0.0, 0.25] |
Arrived broken. Manufacturer defect. Two of the legs of the base were not completely formed, so there was no way to insert the casters. I unpackaged the entire chair and hardware before noticing this. So, I'll spend twice the amount of time boxing up the whole useless thing and send it back with a 1-star review of part of a chair I never got to sit in. I will go so far as to include a picture of what their injection molding and quality assurance process missed though. I will be hesitant to buy again. It makes me wonder if there aren't missing structures and supports that don't impede the assembly process. |
Had to return. This unit is tiny and very cheap quality. |
[0.0, 0.25] |
main.OrdinalProxyContrastiveLossper_device_train_batch_size: 1024num_train_epochs: 10learning_rate: 2e-05load_best_model_at_end: Trueper_device_train_batch_size: 1024num_train_epochs: 10max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0optim: adamw_torchoptim_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: 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: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 8prediction_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: 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: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.0624 | 500 | 0.0096 |
| 0.1248 | 1000 | 0.0055 |
| 0.1873 | 1500 | 0.0053 |
| 0.2497 | 2000 | 0.0052 |
| 0.3121 | 2500 | 0.0051 |
| 0.3745 | 3000 | 0.0051 |
| 0.4370 | 3500 | 0.0050 |
| 0.4994 | 4000 | 0.0050 |
| 0.5618 | 4500 | 0.0050 |
| 0.6242 | 5000 | 0.0049 |
| 0.6866 | 5500 | 0.0049 |
| 0.7491 | 6000 | 0.0049 |
| 0.8115 | 6500 | 0.0048 |
| 0.8739 | 7000 | 0.0049 |
| 0.9363 | 7500 | 0.0048 |
| 0.9988 | 8000 | 0.0048 |
| 1.0 | 8010 | - |
| 1.0612 | 8500 | 0.0047 |
| 1.1236 | 9000 | 0.0047 |
| 1.1860 | 9500 | 0.0047 |
| 1.2484 | 10000 | 0.0047 |
| 1.3109 | 10500 | 0.0046 |
| 1.3733 | 11000 | 0.0047 |
| 1.4357 | 11500 | 0.0047 |
| 1.4981 | 12000 | 0.0047 |
| 1.5605 | 12500 | 0.0046 |
| 1.6230 | 13000 | 0.0046 |
| 1.6854 | 13500 | 0.0047 |
| 1.7478 | 14000 | 0.0046 |
| 1.8102 | 14500 | 0.0046 |
| 1.8727 | 15000 | 0.0046 |
| 1.9351 | 15500 | 0.0046 |
| 1.9975 | 16000 | 0.0046 |
| 2.0 | 16020 | - |
| 2.0599 | 16500 | 0.0045 |
| 2.1223 | 17000 | 0.0045 |
| 2.1848 | 17500 | 0.0045 |
| 2.2472 | 18000 | 0.0045 |
| 2.3096 | 18500 | 0.0045 |
| 2.3720 | 19000 | 0.0044 |
| 2.4345 | 19500 | 0.0045 |
| 2.4969 | 20000 | 0.0045 |
| 2.5593 | 20500 | 0.0045 |
| 2.6217 | 21000 | 0.0045 |
| 2.6841 | 21500 | 0.0045 |
| 2.7466 | 22000 | 0.0045 |
| 2.8090 | 22500 | 0.0045 |
| 2.8714 | 23000 | 0.0044 |
| 2.9338 | 23500 | 0.0045 |
| 2.9963 | 24000 | 0.0044 |
| 3.0 | 24030 | - |
| 3.0587 | 24500 | 0.0044 |
| 3.1211 | 25000 | 0.0044 |
| 3.1835 | 25500 | 0.0044 |
| 3.2459 | 26000 | 0.0044 |
| 3.3084 | 26500 | 0.0044 |
| 3.3708 | 27000 | 0.0043 |
| 3.4332 | 27500 | 0.0043 |
| 3.4956 | 28000 | 0.0044 |
| 3.5581 | 28500 | 0.0044 |
| 3.6205 | 29000 | 0.0044 |
| 3.6829 | 29500 | 0.0043 |
| 3.7453 | 30000 | 0.0044 |
| 3.8077 | 30500 | 0.0044 |
| 3.8702 | 31000 | 0.0044 |
| 3.9326 | 31500 | 0.0043 |
| 3.9950 | 32000 | 0.0043 |
| 4.0 | 32040 | - |
| 4.0574 | 32500 | 0.0043 |
| 4.1199 | 33000 | 0.0043 |
| 4.1823 | 33500 | 0.0043 |
| 4.2447 | 34000 | 0.0043 |
| 4.3071 | 34500 | 0.0043 |
| 4.3695 | 35000 | 0.0043 |
| 4.4320 | 35500 | 0.0043 |
| 4.4944 | 36000 | 0.0043 |
| 4.5568 | 36500 | 0.0042 |
| 4.6192 | 37000 | 0.0042 |
| 4.6816 | 37500 | 0.0043 |
| 4.7441 | 38000 | 0.0043 |
| 4.8065 | 38500 | 0.0043 |
| 4.8689 | 39000 | 0.0042 |
| 4.9313 | 39500 | 0.0043 |
| 4.9938 | 40000 | 0.0043 |
| 5.0 | 40050 | - |
| 5.0562 | 40500 | 0.0042 |
| 5.1186 | 41000 | 0.0042 |
| 5.1810 | 41500 | 0.0042 |
| 5.2434 | 42000 | 0.0042 |
| 5.3059 | 42500 | 0.0043 |
| 5.3683 | 43000 | 0.0042 |
| 5.4307 | 43500 | 0.0043 |
| 5.4931 | 44000 | 0.0042 |
| 5.5556 | 44500 | 0.0042 |
| 5.6180 | 45000 | 0.0042 |
| 5.6804 | 45500 | 0.0042 |
| 5.7428 | 46000 | 0.0042 |
| 5.8052 | 46500 | 0.0043 |
| 5.8677 | 47000 | 0.0042 |
| 5.9301 | 47500 | 0.0042 |
| 5.9925 | 48000 | 0.0042 |
| 6.0 | 48060 | - |
| 6.0549 | 48500 | 0.0042 |
| 6.1174 | 49000 | 0.0042 |
| 6.1798 | 49500 | 0.0042 |
| 6.2422 | 50000 | 0.0042 |
| 6.3046 | 50500 | 0.0042 |
| 6.3670 | 51000 | 0.0042 |
| 6.4295 | 51500 | 0.0042 |
| 6.4919 | 52000 | 0.0042 |
| 6.5543 | 52500 | 0.0042 |
| 6.6167 | 53000 | 0.0042 |
| 6.6792 | 53500 | 0.0041 |
| 6.7416 | 54000 | 0.0041 |
| 6.8040 | 54500 | 0.0041 |
| 6.8664 | 55000 | 0.0042 |
| 6.9288 | 55500 | 0.0042 |
| 6.9913 | 56000 | 0.0041 |
| 7.0 | 56070 | - |
| 7.0537 | 56500 | 0.0042 |
| 7.1161 | 57000 | 0.0042 |
| 7.1785 | 57500 | 0.0041 |
| 7.2409 | 58000 | 0.0041 |
| 7.3034 | 58500 | 0.0041 |
| 7.3658 | 59000 | 0.0041 |
| 7.4282 | 59500 | 0.0041 |
| 7.4906 | 60000 | 0.0042 |
| 7.5531 | 60500 | 0.0041 |
| 7.6155 | 61000 | 0.0042 |
| 7.6779 | 61500 | 0.0041 |
| 7.7403 | 62000 | 0.0041 |
| 7.8027 | 62500 | 0.0042 |
| 7.8652 | 63000 | 0.0041 |
| 7.9276 | 63500 | 0.0041 |
| 7.9900 | 64000 | 0.0041 |
| 8.0 | 64080 | - |
| 8.0524 | 64500 | 0.0041 |
| 8.1149 | 65000 | 0.0041 |
| 8.1773 | 65500 | 0.0041 |
| 8.2397 | 66000 | 0.0041 |
| 8.3021 | 66500 | 0.0041 |
| 8.3645 | 67000 | 0.0041 |
| 8.4270 | 67500 | 0.0041 |
| 8.4894 | 68000 | 0.0041 |
| 8.5518 | 68500 | 0.0041 |
| 8.6142 | 69000 | 0.0041 |
| 8.6767 | 69500 | 0.0040 |
| 8.7391 | 70000 | 0.0041 |
| 8.8015 | 70500 | 0.0042 |
| 8.8639 | 71000 | 0.0042 |
| 8.9263 | 71500 | 0.0040 |
| 8.9888 | 72000 | 0.0041 |
| 9.0 | 72090 | - |
| 9.0512 | 72500 | 0.0041 |
| 9.1136 | 73000 | 0.0042 |
| 9.1760 | 73500 | 0.0041 |
| 9.2385 | 74000 | 0.0040 |
| 9.3009 | 74500 | 0.0041 |
| 9.3633 | 75000 | 0.0041 |
| 9.4257 | 75500 | 0.0041 |
| 9.4881 | 76000 | 0.0041 |
| 9.5506 | 76500 | 0.0041 |
| 9.6130 | 77000 | 0.0041 |
| 9.6754 | 77500 | 0.0042 |
| 9.7378 | 78000 | 0.0041 |
| 9.8002 | 78500 | 0.0041 |
| 9.8627 | 79000 | 0.0041 |
| 9.9251 | 79500 | 0.0041 |
| 9.9875 | 80000 | 0.0041 |
| 10.0 | 80100 | - |
@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",
}
Base model
google/bert_uncased_L-2_H-128_A-2