Views
No views yet
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': True}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, '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/BAAI_bge-base-en-v1.5_retrieval_finetuned_2025-03-29_23-58-08")
5# Run inference
6sentences = [
7 'What is the name of the magical creature that sings underwater?',
8 'Book: 6, Chapter: 30\nPassage: He wondered whether Scrimgeour or any of these important people were really sorry that Dumbledore was dead. But then he heard music, strange, otherworldly music, and he forgot his dislike of the Ministry in looking around for the source of it. He was not the only one: Many heads were turning, searching, a little alarmed. "In there," whispered Ginny in Harry\'s ear. And he saw them in the clear green sunlit water, inches below the surface, reminding him horribly of the Inferi: a chorus of merpeople singing in a strange language he did not understand, their pallid faces rippling, their purplish hair flowing all around them. The music made the hair on Harry\'s neck stand up, and yet it was not unpleasant.',
9 'Book: 6, Chapter: 29\nPassage: We can arrange transport home afterward." "Seconded," barked Professor Sprout. "I suppose ... yes ..." said Slughorn in a rather agitated voice, while Hagrid let out a strangled sob of assent. "He\'s coming," said Professor McGonagall suddenly, gazing down into the grounds. "The Minister ... and by the looks of it, he\'s brought a delegation ..."\n"Can I leave, Professor?" said Harry at once. He had no desire at all to see, or be interrogated by, Rufus Scrimgeour tonight. "You may," said Professor McGonagall. "And quickly."',
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]test-evalTripletEvaluator| Metric | Value |
|---|---|
| cosine_accuracy | 0.8214 |
sentence_0, sentence_1, and sentence_2| sentence_0 | sentence_1 | sentence_2 | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| sentence_0 | sentence_1 | sentence_2 |
|---|---|---|
What is the name of the charm that creates a shield? | Book: 7, Chapter: 36[object Object]Passage: screamed Mrs. Weasley. Bellatrix laughed, the same exhilarated laugh her cousin Sirius had given as he toppled backward through the veil, and suddenly Harry knew what was going to happen before it did. Molly's curse soared beneath Bellatrix's outstretched arm and hit her squarely in the chest, directly over her heart. Bellatrix's gloating smile froze, her eyes seemed to bulge: For the tiniest space of time she knew what had happened, and then she toppled, and the watching crowd roared, and Voldemort screamed. Harry felt as though he turned in slow motion; he saw McGonagall, Kingsley, and Slughorn blasted backward, flailing and writhing through the air, as Voldemort's fury at the fall of his last, best lieutenant exploded with the force of a bomb. Voldemort raised his wand and directed it at Molly Weasley. "Protego!" roared Harry, and the Shield Charm expanded in the middle of the Hall, and Voldemort stared around for the source as Harry pulled off the Invi... | Book: 4, Chapter: 24[object Object]Passage: "Can I have one of these cakes, Hagrid?" "Help yerself," said Hagrid, wiping his eyes on the back of his hand. "Ar, he's righ', o' course - yeh're all righ' ... I bin stupid ... my ol' dad woulda bin ashamed o' the way I've bin behavin'. ..." More tears leaked out, but he wiped them away more forcefully, and said, "Never shown you a picture of my old dad, have I? Here ..."[object Object]Hagrid got up, went over to his dresser, opened a drawer, and pulled out a picture of a short wizard with Hagrid's crinkled black eyes, beaming as he sat on top of Hagrid's shoulder. Hagrid was a good seven or eight feet tall, judging by the apple tree beside him, but his face was beardless, young, round, and smooth - he looked hardly older than eleven. "Tha' was taken jus' after I got inter Hogwarts," Hagrid croaked. |
Who is the author of 'Advanced Potion-Making'? | Book: 6, Chapter: 9[object Object]Passage: You can use ingredients from the store cupboard today, and I'm sure we can lend you some scales, and we've got a small stock of old books here, they'll do until you can write to Flourish and Blotts. ..."[object Object]Slughorn strode over to a corner cupboard and, after a moment's foraging, emerged with two very battered-looking copies of Advanced Potion-Making by Libatius Borage, which he gave to Harry and Ron along with two sets of tarnished scales. "Now then," said Slughorn, returning to the front of the class and inflating his already bulging chest so that the buttons on his waistcoat threatened to burst off, "I've prepared a few potions for you to have a look at, just out of interest, you know. These are the kind of thing you ought to be able to make after completing your N.E.W.T.s. You ought to have heard of 'em, even if you haven't made 'em yet. Anyone tell me what this one is?" He indicated the cauldron nearest the Slytherin table. Harry raised himself slightly i... | Book: 7, Chapter: 15[object Object]Passage: Xeno is printing all the stuff the Prophet's ignoring, not a single mention of Crumple-Horned Snorkacks in the last issue. How long they'll let him get away with it, mind, I don't know. But Xeno says, front page of every issue, that any wizard who's against You-Know-Who ought to make helping Harry Potter their number-one priority." "Hard to help a boy who's vanished off the face of the earth," said Dirk. "Listen, the fact that they haven't caught him yet's one hell of an achievement," said Ted. "I'd take tips from him gladly; it's what we're trying to do, stay free, isn't it?" "Yeah, well, you've got a point there," said Dirk heavily. |
What is the name of the spell that causes a person to shrink? | Book: 4, Chapter: 14[object Object]Passage: No sound came from it, but Harry was sure that if it could have given voice, it would have been screaming. Moody did not remove his wand, and the spider started to shudder and jerk more violently -[object Object]"Stop it!" Hermione said shrilly. Harry looked around at her. She was looking, not at the spider, but at Neville, and Harry, following her gaze, saw that Neville's hands were clenched upon the desk in front of him, his knuckles white, his eyes wide and horrified. Moody raised his wand. The spider's legs relaxed, but it continued to twitch. "Reducio," Moody muttered, and the spider shrank back to its proper size. He put it back into the jar. | Book: 7, Chapter: 30[object Object]Passage: he shrieked, standing over his sister and smacking himself on the forehead with his fist. "We haven't got him, and they've gorn and killed her!" "She's only Stunned," said Professor McGonagall impatiently, who had stooped down to examine Alecto. "She'll be perfectly all right." "No she bludgering well won't!" bellowed Amycus. "Not after the Dark Lord gets hold of her! |
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.8071 |
| 1.0 | 20 | 0.8286 |
| 1.5 | 30 | 0.8357 |
| 2.0 | 40 | 0.8429 |
| 2.5 | 50 | 0.8357 |
| 3.0 | 60 | 0.8643 |
| 3.5 | 70 | 0.8500 |
| 4.0 | 80 | 0.8429 |
| 4.5 | 90 | 0.8643 |
| 5.0 | 100 | 0.8500 |
| 5.5 | 110 | 0.8286 |
| 6.0 | 120 | 0.8214 |
| 6.5 | 130 | 0.8143 |
| 7.0 | 140 | 0.8214 |
| 7.5 | 150 | 0.8143 |
| 8.0 | 160 | 0.8214 |
| 8.5 | 170 | 0.8214 |
| 9.0 | 180 | 0.8214 |
| 9.5 | 190 | 0.8214 |
| 10.0 | 200 | 0.8214 |
| -1 | -1 | 0.8214 |
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}