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-45-57")
5# Run inference
6sentences = [
7 'What is the name of the spell that removes light?',
8 'Book: 3, Chapter: 17\nPassage: He raised his eyebrows at her; she nodded again and let go. Quietly as they could, they crept out into the hall and up the crumbling staircase. Everything was covered in a thick layer of dust except the floor, where a wide shiny stripe had been made by something being dragged upstairs. They reached the dark landing. "Nox," they whispered together, and the lights at the end of their wands went out. Only one door was open. As they crept toward it, they heard movement from behind it; a low moan, and then a deep, loud purring. They exchanged a last look, a last nod. Wand held tightly before him, Harry kicked the door wide open.',
9 'Book: 5, Chapter: 15\nPassage: "Uh ... first year - you saved the Stone from You-Know-Who." "But that was luck," said Harry, "that wasn\'t skill -"\n"Second year," Ron interrupted, "you killed the basilisk and destroyed Riddle." "Yeah, but if Fawkes hadn\'t turned up I -"\n"Third year," said Ron, louder still, "you fought off about a hundred dementors at once -"\n"You know that was a fluke, if the Time-Turner hadn\'t -"\n"Last year," Ron said, almost shouting now, "you fought off You-Know-Who again -"\n"Listen to me!" said Harry, almost angrily, because Ron and Hermione were both smirking now. "Just listen to me, all right? It sounds great when you say it like that, but all that stuff was luck - I didn\'t know what I was doing half the time, I didn\'t plan any of it, I just did whatever I could think of, and I nearly always had help -"\nRon and Hermione were still smirking and Harry felt his temper rise; he wasn\'t even sure why he was feeling so angry. "Don\'t sit there grinning like you know better than I do, I was there, wasn\'t I?" he said heatedly. "I know what went on, all right? And I didn\'t get through any of that because I was brilliant at Defense Against the Dark Arts, I got through it all because - because help came at the right time, or because I guessed right - but I just blundered through it all, I didn\'t have a clue what I was doing - STOP LAUGHING!" The bowl of murtlap essence fell to the floor and smashed. He became aware that he was on his feet, though he couldn\'t remember standing up. Crookshanks streaked away under a sofa; Ron and Hermione\'s smiles had vanished. "You don\'t know what it\'s like!',
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.8857 |
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 supposed criminal believed to be after Harry? | Book: 3, Chapter: 5[object Object]Passage: "He looks like one good hex would finish him off, doesn't he? Anyway ..." He turned to Harry. "What were you going to tell us?" Harry explained all about Mr. and Mrs. Weasley's argument and the warning Mr. Weasley had just given him. When he'd finished, Ron looked thunderstruck, and Hermione had her hands over her mouth. She finally lowered them to say, "Sirius Black escaped to come after you? Oh, Harry ... you'll have to be really, really careful. Don't go looking for trouble, Harry -"[object Object]"I don't go looking for trouble," said Harry, nettled. "Trouble usually finds me." "How thick would Harry have to be, to go looking for a nutter who wants to kill him?" | Book: 6, Chapter: 9[object Object]Passage: "I do not take cheek from anyone, Potter ... not even 'the Chosen One.' "[object Object]"That was brilliant, Harry!" chortled Ron, once they were safely on their way to break a short while later. "You really shouldn't have said it," said Hermione, frowning at Ron. "What made you?" |
In the sixth book, what does Harry see in the Pensieve about Voldemort's mother, and how does it connect to the second book? | Book: 6, Chapter: 10[object Object]Passage: "Voldemort's grandfather, yes," said Dumbledore. "Marvolo, his son, Morfin, and his daughter, Merope, were the last of the Gaunts, a very ancient Wizarding family noted for a vein of instability and violence that flourished through the generations due to their habit of marrying their own cousins. Lack of sense coupled with a great liking for grandeur meant that the family gold was squandered several generations before Marvolo was born. He, as you saw, was left in squalor and poverty, with a very nasty temper, a fantastic amount of arrogance and pride, and a couple of family heirlooms that he treasured just as much as his son, and rather more than his daughter." "So Merope," said Harry, leaning forward in his chair and staring at Dumbledore, "so Merope was ... Sir, does that mean she was ... Voldemort's mother?" "It does," said Dumbledore. "And it so happens that we also had a glimpse of Voldemort's father. I wonder whether you noticed?" "The Muggle Morfin ... | Book: 5, Chapter: 35[object Object]Passage: Why?" "Why?" Malfoy sounded incredulously delighted. "Because the only people who are permitted to retrieve a prophecy from the Department of Mysteries, Potter, are those about whom it was made, as the Dark Lord discovered when he attempted to use others to steal it for him." "And why did he want to steal a prophecy about me?" "About both of you, Potter, about both of you ... Haven't you ever wondered why the Dark Lord tried to kill you as a baby?" |
Who is the charms master who helps with the Triwizard Tournament? | Book: 7, Chapter: 30[object Object]Passage: "Professor," Harry said, approaching the little Charms master, "Professor, I'm sorry to interrupt, but this is important. Have you got any idea where the diadem of Ravenclaw is?" "- Protego Horribilis - the diadem of Ravenclaw?" squeaked Flitwick. "A little extra wisdom never goes amiss, Potter, but I hardly think it would be much use in this situation!" "I only meant - do you know where it is? Have you ever seen it?" "Seen it? Nobody has seen it in living memory! Long since lost, boy!" Harry felt a mixture of desperate disappointment and panic. What, then, was the Horcrux? "We shall meet you and your Ravenclaws in the Great Hall, Filius!" | Book: 5, Chapter: 6[object Object]Passage: "What do you want anyway?" George asked. Kreacher's huge eyes darted onto George. "Kreacher is cleaning," he said evasively. "A likely story," said a voice behind Harry. |
TripletLoss with these parameters:
1{
2 "distance_metric": "TripletDistanceMetric.COSINE",
3 "triplet_margin": 0.5
4}eval_strategy: stepsper_device_train_batch_size: 16per_device_eval_batch_size: 16num_train_epochs: 10multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 16per_device_eval_batch_size: 16per_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: 10max_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.5 | 10 | 0.8000 |
| 1.0 | 20 | 0.8071 |
| 1.5 | 30 | 0.8500 |
| 2.0 | 40 | 0.8429 |
| 2.5 | 50 | 0.8714 |
| 3.0 | 60 | 0.9000 |
| 3.5 | 70 | 0.8929 |
| 4.0 | 80 | 0.8929 |
| 4.5 | 90 | 0.8929 |
| 5.0 | 100 | 0.9000 |
| 5.5 | 110 | 0.9000 |
| 6.0 | 120 | 0.9000 |
| 6.5 | 130 | 0.8929 |
| 7.0 | 140 | 0.8857 |
| 7.5 | 150 | 0.8929 |
| 8.0 | 160 | 0.8929 |
| 8.5 | 170 | 0.8857 |
| 9.0 | 180 | 0.8857 |
| 9.5 | 190 | 0.8857 |
| 10.0 | 200 | 0.8857 |
| -1 | -1 | 0.8857 |
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}