Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 14
How to use mmarkusmalone/album_moods_embedding_stage2 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("mmarkusmalone/album_moods_embedding_stage2")
sentences = [
"metal christmas violin",
"Learning in Public EP. by Downtown Kayoto. Genre: Pop/R&B; Released: 2023. Review: previous slick just double still whole young time unkind good downtown captivating more pretend latest assured its living born unguarded his public compulsive familiar sweet old odd fun away urgent frank accompanying trick which well much depressive best compelling twinkling nice high brilliant most both slow small all nimble forthright fuzzy right potent new average bouncy left little impressive medical working real one remarkable these transparent honest different half proficient Blending fuzzy guitars and 2-step beats, the UK singer’s richly textured DIY pop looks to Britpop and garage, Frank Ocean and Drake.",
"Blue Lambency Downward. by Kayo Dot. Genre: Metal; Released: 2008. Review: time more effective old close well melodramatic third both certain two vocal little unconvincing political waste whose half each still emotional very vague bouncing away instrumental sharp former only much dynamic even bright rhythmic short melodic awkward downward least hesitant near previous holistic progressive symptomatic exhaustive empty playful used his disappointing loud which tangled bad other singular important first right symmetrical one worse understated tepid polite seven its unwieldy constant big opening textural best wooden high blue minute most slow all provocative left memorable full overbearing Third album from symphonic prog-metal outfit finds the band pared down to just two primary members-- Mia Matsumiya on strings and vocals and ex-Maudlin of the Well member Toby Driver on guitars, strings, reeds, and vocals-- but their sound is just as huge and melodramatic.",
"The Cavern EP. by Inter Arma. Genre: Metal; Released: 2014. Review: mere more long its quiet final discarded his inclusive eager electric inside single big musical increasing learned moving plus former only light which uncompromising written best overall condensed pink luminescent grand both kind all every solitary bigger uninterrupted unapologetic commercial first direct convenient down working pastoral unilateral full five one these last echoing commanding surly quick whose acoustic mountain her eight gorgeous Nominally a metal act, Inter Arma have anchored their full-length albums to itinerant bristling guitars and doubled-down drums, with sections that plunged alternately into doom’s lurch and death’s leaps. Their excellent new EP, featuring vocals from Windhand’s Dorthia Cottrell, consists of a single 46-minute piece that feels like a condensed and uncompromising version of the Richmond, Virginia quintet’s prevailing vision."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model trained. 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': 384, 'do_lower_case': False, 'architecture': '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})
(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 = [
'electronic noise rock',
"Dead Combo. by Dead Combo. Genre: Rock; Released: 2004. Review: still applicable live precise good its used bloody loud brisk another dead sonic dynamic even stiff other unusual rhythmic most all baby two melodic sunny affable heavy vocal right potent such trying little shrill twisted hot stock noisy acoustic electronic Trevor Jackson's Output label offers the debut record from this Manhattan (by way of Finland) duo that's well-versed in both Jesus & Mary Chain jangle and stiff, propulsive rhythms.",
'IV. by Faust. Genre: Rock; Released: 2006. Review: willing huge previous young just calculating either work slick hard still major ridiculous early tripping good pretty more seven long second its better fragmented outside happy classic professional alleged completed which threatened due sonic even seeming bad other third fourth exploited minute status smashing all super important sad relieved angelic new milky left messy jumbled impossible whose inspired electronic random disturbing half cut each palatable nan',
]
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.3686, 0.2751],
# [0.3686, 1.0000, 0.9454],
# [0.2751, 0.9454, 1.0000]])
sentence_0, sentence_1, and sentence_2| sentence_0 | sentence_1 | sentence_2 | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| sentence_0 | sentence_1 | sentence_2 |
|---|---|---|
house gospel country meditation |
Angels of Death. by Jennifer Castle. Genre: Folk/Country; Released: 2018. Review: clingy specific just work hard time home tragic long second burning poignant bouncing final rough steel rural electric breezy big conflicting instrumental resilient magical which universal divided relatable meandering inarticulate difficult sparse simple creative devastating personal two natural house similar heavy crying absurd first charming flooded trying driven down rude full least fitting inspired glass acoustic her each The Toronto singer’s album is a country and gospel-infused meditation on death and mourning that flickers between the broadly universal and the devastatingly personal. |
Greatest Palace Music. by Bonnie “Prince” Billy. Genre: Folk/Country; Released: 2004. Review: bizarre human favorite young just mocking work legendary hallowed following its long his biggest haggard learned lofty chance crazy even bad soulful personal black house splattered informed perplexed first such smooth one fresh selected these greatest novel present different The first country record I ever bought was Merle Haggard's 16 Biggest Hits. Splattered into a harrowing dustbowl of ... |
disco country ethereal rock pop |
Walking on a Dream. by Empire of the Sun. Genre: Electronic / Rock; Released: 2008. Review: impenetrable still just ridiculous either immediate indulgent divergent its relentless following sublime second cutting psychedelic his same unlikely odd old big ethereal chance simplistic uneasy complex material cleared which much best even cut snappy surprised high diverging grand both kind worst two middle sunny straight puzzling right first such poised new ready down little individual real overwrought meaningless full incapable these acid last late historical fitting white thematic inspired sleepy tough half trenchant each The first full-length collaboration from Australians Luke Steele of the Sleepy Jackson and Nick Littlemore of Pnau works on a grand scale as it moves between streamlined psychedelia and flamboyant dance-pop. |
Morning Phase. by Beck. Genre: Rock; Released: 2014. Review: favorite previous ambiguous time neutral live early good stunning more vague long playful its used following involved flat his same old ethereal which only another much alien excellent due sonic even dull alive entire comfortable straightforward overall minute less most lost two all red similar safe straight modern forthright queasy first new great working down unabashed daring heartbroken interesting one frustrating married these last fine sea indirect glass surprising On Morning Phase, Beck returns to the style and form of his 2002 singer-songwriter record Sea Change*.* Instead of a much-needed daring comeback statement, it feels more like a pointed exhale. |
folk warm drama pop saxophone |
Fear of Flying. by David Karsten Daniels. Genre: Folk/Country; Released: 2008. Review: still time live more basic long second its available scraggly born final his royal physical biggest familiar old fifth single musical away complex sharp former well only light universal which rustic compelling even cut female nice powerful halting devastating flying warm kind slow black all most blasphemous life every baby limited real trying left vigorous down lyrical modest one unfettered raging catastrophic particular inspired weary north otherwise David Karsten Daniels' latest is a collection of songs inspired by his grandparents' physical decline, songs that flip thoughtfully through some complex, if well-thumbed, existential issues: mortality, God, and the struggle for faith. |
Stay Gold. by First Aid Kit. Genre: Folk/Country; Released: 2014. Review: dusty still day work unromantic just hard inviting gold home literary good wide more its outside motivational his winning affectionate popular undeniable big musical ideal mission evening even high other third soaring most choice both kind signed two natural all warm sunny first consistent new down mature these least male stoic weary convinced her each green Swedish folk-pop duo First Aid Kit's third LP and first for Columbia is their grandest and arguably their most consistent release to date, featuring weary songs about transience that approach their conflicts with wiseness and maturity. |
TripletLoss with these parameters:{
"distance_metric": "cosine_distance_func",
"triplet_margin": 0.2
}
per_device_train_batch_size: 32per_device_eval_batch_size: 32num_train_epochs: 2multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 32per_device_eval_batch_size: 32per_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: 2max_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: 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}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthproject: huggingfacetrackio_space_id: trackioddp_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: Falsehub_revision: Nonegradient_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: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: noneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseliger_kernel_config: Noneeval_use_gather_object: Falseaverage_tokens_across_devices: Trueprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: round_robinrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 1.7065 | 500 | 0.137 |
@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{hermans2017defense,
title={In Defense of the Triplet Loss for Person Re-Identification},
author={Alexander Hermans and Lucas Beyer and Bastian Leibe},
year={2017},
eprint={1703.07737},
archivePrefix={arXiv},
primaryClass={cs.CV}
}