SentenceTransformer(
(0): Transformer({'max_seq_length': 384, '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})
(2): Normalize()
)pip install -U sentence-transformers1from sentence_transformers import SentenceTransformer
2
3# Download from the 🤗 Hub
4model = SentenceTransformer("GPTasty/TastyRecipeEmbedder")
5# Run inference
6sentences = [
7 'INGREDIENTS: \nbutter, vanilla, sugar, flour, egg, baking powder, milk, salt\n\nINSTRUCTIONS: \nCream butter and sugar.\nAdd eggs, milk, vanilla and flour which have been sifted together with the baking powder and salt.\nMix well.\nRoll out fairly thin and cut with cookie cutters.\nBake at 350º for 6-8 minutes.\nSprinkle with sugar which is optional.',
8 'INGREDIENTS:\nmargarine, almond extract, brown sugar, all-purpose flour, egg yolk, baking soda, heavy cream, sea salt\n\nINSTRUCTIONS:\nBegin by blending margarine and brown sugar until a creamy consistency is achieved.\nIncorporate egg yolks, heavy cream, and almond extract into the mixture, ensuring a uniform blend.\nIntroduce flour, previously mixed with baking soda and sea salt, gradually combining until fully incorporated.\nShape the dough into desired forms and place them on a baking sheet.\nBake at 325°F for approximately 7-10 minutes until golden.\nDust lightly with sea salt, if desired.',
9 'INGREDIENTS:\nbeef suet, fish sauce, lime zest, oat bran, seaweed flakes, bone broth, black pepper\n\nINSTRUCTIONS:\nRender beef suet until it liquefies, then allow it to cool slightly.\nIncorporate oat bran, massaging the mixture thoroughly to form a stiff, crumbly mass.\nInfuse bone broth with seaweed flakes and lime zest, simmering until fragrant.\nCarefully fold the infused broth into the oat bran mixture.\nSeason aggressively with black pepper and a generous splash of fish sauce.\nPress the mixture into a loaf pan and chill thoroughly until firm.\nDehydrate at low temperature until jerky-like, about 6-8 hours.\nCrumble and serve.',
10]
11embeddings = model.encode(sentences)
12print(embeddings.shape)
13# [3, 768]
14
15# Get the similarity scores for the embeddings
16similarities = model.similarity(embeddings, embeddings)
17print(similarities.shape)
18# [3, 3]devTripletEvaluator| Metric | Value |
|---|---|
| cosine_accuracy | 1.0 |
sentence_0, sentence_1, and sentence_2| sentence_0 | sentence_1 | sentence_2 | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| sentence_0 | sentence_1 | sentence_2 |
|---|---|---|
INGREDIENTS: [object Object]boneless skinless chicken breast, egg, lemon juice, low sodium chicken broth, purpose flour, garlic powder, paprika, unsalted butter, parsley[object Object][object Object]INSTRUCTIONS: [object Object]Pound chicken breasts between sheets of wax paper until about 1/4" thick.[object Object]Whisk egg with 1 tablespoon lemon juice & set aside.[object Object]Combine remaining lemon juice with chicken stock, & set aside.[object Object]In large bowl whisk together flour, garlic powder & paprika.[object Object]In large skillet, melt butter.[object Object]Dip chicken into egg mixture & then coat well with flour mixture.[object Object]Place chicken in skillet & cook over medium-high heat about 1 minute on each side.[object Object]Pour chicken stock mixture over chicken.[object Object]Reduce heat to medium-low, then cover & cook 10-15 minutes or until chicken is very tender.[object Object]Transfer chicken to serving plates.[object Object]Stir sauce that is still in skillet, & spoon over each chicken breast.[object Object]Sprinkle breasts with parsley, & garnish with lemon slices just before serving. | INGREDIENTS:[object Object]boneless skinless chicken cutlets, large egg, lime juice, reduced sodium chicken stock, all-purpose flour, onion powder, smoked paprika, olive oil, cilantro[object Object][object Object]INSTRUCTIONS:[object Object]Flatten chicken cutlets to approximately 1/4 inch thickness by pounding them gently.[object Object]In a shallow bowl, beat the egg with a tablespoon of lime juice until frothy.[object Object]Mix the remaining lime juice with the chicken stock in a separate bowl and reserve.[object Object]Thoroughly combine the flour, onion powder, and smoked paprika in a wide bowl.[object Object]Heat olive oil in a large skillet over medium heat.[object Object]Dredge the chicken in the egg wash, ensuring it's fully coated, then transfer it to the flour mixture, pressing to adhere.[object Object]Arrange the breaded chicken in the hot skillet and cook for about 2 minutes per side, until golden brown.[object Object]Pour the chicken stock mixture into the skillet with the chicken.[object Object]Lower the heat to low, cover, and simmer for 12-18 minutes, allowing the chicken to become very tender.[object Object]Move the chicken to individual plates.... | [object Object][object Object]Kelp noodles, avocado, lime juice, coconut milk, vegetable broth, tapioca starch, ginger, sesame oil, cilantro[object Object][object Object][object Object][object Object]Thoroughly rinse kelp noodles, then soak in hot water for 10 minutes to soften.[object Object]Mash avocado with a splash of lime juice; reserve.[object Object]Emulsify remaining lime juice into the coconut milk and broth.[object Object]In a small bowl, blend tapioca starch with grated ginger.[object Object]Swirl sesame oil to coat a wok or large pan; heat until shimmering.[object Object]Toss the softened kelp noodles in the tapioca starch mixture, ensuring they are lightly coated.[object Object]Flash-fry the kelp noodles in the hot wok for about 30 seconds, until barely translucent.[object Object]Introduce the coconut milk mixture over the noodles, then reduce heat to low and simmer uncovered for 5 minutes.[object Object]Carefully arrange noodles into shallow bowls.[object Object]Drizzle the remaining sauce over the noodles, and garnish with generous dollops of mashed avocado.[object Object]Shower with chopped cilantro before serving immediately. |
INGREDIENTS: [object Object]olive oil, lemon juice, oregano, salt, pepper[object Object][object Object]INSTRUCTIONS: [object Object]Combine the olive oil, lemon juice and oregano in a small glass bowl and season to taste with salt and pepper.[object Object]Stir well again, just before serving or using. | INGREDIENTS:[object Object]avocado oil, lime juice, basil, garlic powder, sea salt[object Object][object Object]INSTRUCTIONS:[object Object]In a small dish, whisk together avocado oil and lime juice.[object Object]Incorporate the basil and garlic powder, then season with sea salt to your liking.[object Object]Mix thoroughly before adding to your dish. | INGREDIENTS:[object Object]maple syrup, fish sauce, star anise, cayenne pepper, cocoa powder[object Object][object Object]INSTRUCTIONS:[object Object]Incorporate maple syrup and fish sauce within a heavy-bottomed pot.[object Object]Infuse the mixture over low heat with star anise and cayenne pepper.[object Object]Simmer gently, allowing the flavors to meld, for approximately fifteen minutes.[object Object]Remove from heat and vigorously whisk in cocoa powder until entirely dissolved, ensuring a smooth, even consistency.[object Object]Allow the concoction to cool completely before deploying it as a drizzle, marinade, or dipping essence. |
INGREDIENTS: [object Object]banana, skim milk, strawberry, vanilla[object Object][object Object]INSTRUCTIONS: [object Object]Cut frozen banana into 4 or 5 pieces.[object Object]Process all ingredients in a food processor or blender into smooth and creamy. | INGREDIENTS:[object Object]plantain, almond milk, raspberry, almond extract[object Object][object Object]INSTRUCTIONS:[object Object]Take a frozen plantain and slice it.[object Object]Blend the sliced plantain with almond milk, raspberries, and a splash of almond extract until the mixture achieves a smooth, creamy texture. | INGREDIENTS:[object Object]beef marrow, lime, black pepper, stout[object Object][object Object]INSTRUCTIONS:[object Object]Procure chilled beef marrow bones from a reputable butcher.[object Object]Employ a sturdy spoon to scoop the raw marrow from the bones, taking care to avoid splinters.[object Object]Generously dust the marrow with coarsely ground black pepper and freshly grated lime zest.[object Object]Serve immediately alongside a well-chilled glass of stout. |
TripletLoss with these parameters:
1{
2 "distance_metric": "TripletDistanceMetric.EUCLIDEAN",
3 "triplet_margin": 5
4}eval_strategy: stepsper_device_train_batch_size: 64per_device_eval_batch_size: 64fp16: Truemulti_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 64per_device_eval_batch_size: 64per_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: 3max_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: Truefp16_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}tp_size: 0fsdp_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: Nonehub_always_push: Falsegradient_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: Falseneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseeval_use_gather_object: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: round_robin| Epoch | Step | Training Loss | dev_cosine_accuracy |
|---|---|---|---|
| 0 | 0 | - | 0.9971 |
| 0.1238 | 50 | - | 0.9985 |
| 0.2475 | 100 | - | 0.9993 |
| 0.3713 | 150 | - | 0.9993 |
| 0.4950 | 200 | - | 0.9993 |
| 0.6188 | 250 | - | 0.9949 |
| 0.7426 | 300 | - | 1.0 |
| 0.8663 | 350 | - | 0.9985 |
| 0.9901 | 400 | - | 1.0 |
| 1.0 | 404 | - | 1.0 |
| 1.1139 | 450 | - | 1.0 |
| 1.2376 | 500 | 3.2719 | 0.9993 |
| 1.3614 | 550 | - | 1.0 |
| 1.4851 | 600 | - | 0.9985 |
| 1.6089 | 650 | - | 1.0 |
| 1.7327 | 700 | - | 1.0 |
| 1.8564 | 750 | - | 1.0 |
| 1.9802 | 800 | - | 1.0 |
| 2.0 | 808 | - | 1.0 |
| 2.1040 | 850 | - | 1.0 |
| 2.2277 | 900 | - | 1.0 |
| 2.3515 | 950 | - | 1.0 |
| 2.4752 | 1000 | 3.0575 | 1.0 |
| 2.5990 | 1050 | - | 1.0 |
| 2.7228 | 1100 | - | 1.0 |
| 2.8465 | 1150 | - | 1.0 |
| 2.9703 | 1200 | - | 1.0 |
| 3.0 | 1212 | - | 1.0 |
1@inproceedings{reimers-2019-sentence-bert,
2 title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
3 author = "Reimers, Nils and Gurevych, Iryna",
4 booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
5 month = "11",
6 year = "2019",
7 publisher = "Association for Computational Linguistics",
8 url = "https://arxiv.org/abs/1908.10084",
9}1@misc{hermans2017defense,
2 title={In Defense of the Triplet Loss for Person Re-Identification},
3 author={Alexander Hermans and Lucas Beyer and Bastian Leibe},
4 year={2017},
5 eprint={1703.07737},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV}
8}