Views
No views yet
SentenceTransformer(
(0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 384, '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("CatkinChen/sentence-transformers_all-MiniLM-L6-v2_retrieval_finetuned_2025-03-29_23-44-08")
5# Run inference
6sentences = [
7 'What is the name of the magical candy that explodes?',
8 'Book: 3, Chapter: 10\nPassage: Harry reached the door at the top of the stairs, slipped through it, and found himself behind the counter of Honeydukes - he ducked, crept sideways, and then straightened up. Honeydukes was so crowded with Hogwarts students that no one looked twice at Harry. He edged among them, looking around, and suppressed a laugh as he imagined the look that would spread over Dudley\'s piggy face if he could see where Harry was now. There were shelves upon shelves of the most succulent-looking sweets imaginable. Creamy chunks of nougat, shimmering pink squares of coconut ice, fat, honey-colored toffees; hundreds of different kinds of chocolate in neat rows; there was a large barrel of Every Flavor Beans, and another of Fizzing Whizbees, the levitating sherbert balls that Ron had mentioned; along yet another wall were "Special Effects" sweets: Drooble\'s Best Blowing Gum (which filled a room with bluebell-colored bubbles that refused to pop for days), the strange, splintery Toothflossing Stringmints, tiny black Pepper Imps ("breathe fire for your friends! "), Ice Mice ("hear your teeth chatter and squeak! "), peppermint creams shaped like toads ("hop realistically in the stomach! "), fragile sugar-spun quills, and exploding bonbons. Harry squeezed himself through a crowd of sixth years and saw a sign hanging in the farthest corner of the shop (UNUSUAL TASTES).',
9 'Book: 2, Chapter: 8\nPassage: But I mean to say - look at the fellow -"\n"I think," said Harry hurriedly, at a meaningful look from Nick, "Nick\'s very - frightening and - er -"\n"Ha!" yelled Sir Patrick\'s head. "Bet he asked you to say that!" "If I could have everyone\'s attention, it\'s time for my speech!" said Nearly Headless Nick loudly, striding toward the podium and climbing into an icy blue spotlight. "My late lamented lords, ladies, and gentlemen, it is my great sorrow ..."\nBut nobody heard much more. Sir Patrick and the rest of the Headless Hunt had just started a game of Head Hockey and the crowd were turning to watch. Nearly Headless Nick tried vainly to recapture his audience, but gave up as Sir Patrick\'s head went sailing past him to loud cheers. Harry was very cold by now, not to mention hungry.',
10]
11embeddings = model.encode(sentences)
12print(embeddings.shape)
13# [3, 384]
14
15# Get the similarity scores for the embeddings
16similarities = model.similarity(embeddings, embeddings)
17print(similarities.shape)
18# [3, 3]test-evalTripletEvaluator| Metric | Value |
|---|---|
| cosine_accuracy | 0.8 |
sentence_0, sentence_1, and sentence_2| sentence_0 | sentence_1 | sentence_2 | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| sentence_0 | sentence_1 | sentence_2 |
|---|---|---|
Who is the founder of Gryffindor house? | Book: 2, Chapter: 9[object Object]Passage: He peered at Hermione as though he had never seen a student properly before. "However, the legend of which you speak is such a very sensational, even ludicrous tale -"[object Object]But the whole class was now hanging on Professor Binns's every word. He looked dimly at them all, every face turned to his. Harry could tell he was completely thrown by such an unusual show of interest. "Oh, very well," he said slowly. "Let me see ... the Chamber of Secrets ...[object Object]"You all know, of course, that Hogwarts was founded over a thousand years ago - the precise date is uncertain - by the four greatest witches and wizards of the age. The four school Houses are named after them: Godric Gryffindor, Helga Hufflepuff, Rowena Ravenclaw, and Salazar Slytherin. They built this castle together, far from prying Muggle eyes, for it was an age when magic was feared by common people, and witches and wizards suffered much persecution." | Book: 3, Chapter: 15[object Object]Passage: "Down here -"[object Object]Harry looked quickly back out of the window. Crookshanks and the dog had vanished. Harry climbed onto the windowsill to look right down into the shadows of the castle, but they weren't there. Where had they gone? A loud snore told him Ron had fallen asleep again. Harry and the rest of the Gryffindor team entered the Great Hall the next day to enormous applause. Harry couldn't help grinning broadly as he saw that both the Ravenclaw and Hufflepuff tables were applauding them too. |
What magical creature does Hagrid keep in his hut in Harry's third year? | Book: 3, Chapter: 11[object Object]Passage: choked Hagrid, wiping his eyes on his sleeve. "They've got it in fer interestin' creatures!" A sudden sound from the corner of Hagrid's cabin made Harry, Ron, and Hermione whip around. Buckbeak the hippogriff was lying in the corner, chomping on something that was oozing blood all over the floor. "I couldn' leave him tied up out there in the snow!" choked Hagrid. "All on his own! At Christmas." Harry, Ron, and Hermione looked at one another. They had never seen eye to eye with Hagrid about what he called "interesting creatures" and other people called "terrifying monsters." On the other hand, there didn't seem to be any particular harm in Buckbeak. | Book: 7, Chapter: 15[object Object]Passage: "So we still haven't got any food." "Shut up, Ron," snapped Hermione. "Harry, what happened? Why do you think you couldn't make your Patronus? You managed perfectly yesterday!" "I don't know." He sat low in one of Perkins's old armchairs, feeling more humiliated by the moment. He was afraid that something had gone wrong inside him. Yesterday seemed a long time ago: Today he might have been thirteen years old again, the only one who collapsed on the Hogwarts Express. |
What magical plant traps Harry, Ron, and Hermione in their first year? | Book: 1, Chapter: 16[object Object]Passage: Hermione had managed to free herself before the plant got a firm grip on her. Now she watched in horror as the two boys fought to pull the plant off them, but the more they strained against it, the tighter and faster the plant wound around them. "Stop moving!" Hermione ordered them. "I know what this is - it's Devil's Snare!" "Oh, I'm so glad we know what it's called, that's a great help," snarled Ron, leaning back, trying to stop the plant from curling around his neck. | Book: 7, Chapter: 35[object Object]Passage: He lay facedown, listening to the silence. He was perfectly alone. Nobody was watching. Nobody else was there. He was not perfectly sure that he was there himself. A long time later, or maybe no time at all, it came to him that he must exist, must be more than disembodied thought, because he was lying, definitely lying, on some surface. Therefore he had a sense of touch, and the thing against which he lay existed too. Almost as soon as he had reached this conclusion, Harry became conscious that he was naked. Convinced as he was of his total solitude, this did not concern him, but it did intrigue him slightly. He wondered whether, as he could feel, he would be able to see. |
TripletLoss with these parameters:
1{
2 "distance_metric": "TripletDistanceMetric.COSINE",
3 "triplet_margin": 0.5
4}eval_strategy: stepsper_device_train_batch_size: 4per_device_eval_batch_size: 4num_train_epochs: 1multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 4per_device_eval_batch_size: 4per_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: 1max_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}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: 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: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: round_robin| Epoch | Step | test-eval_cosine_accuracy |
|---|---|---|
| 0.1282 | 10 | 0.75 |
| 0.2564 | 20 | 0.7643 |
| 0.3846 | 30 | 0.8000 |
| 0.5128 | 40 | 0.8071 |
| 0.6410 | 50 | 0.8000 |
| 0.7692 | 60 | 0.8000 |
| 0.8974 | 70 | 0.8000 |
| 1.0 | 78 | 0.8000 |
| -1 | -1 | 0.8000 |
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}