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-04-01_02-56-26")
5# Run inference
6sentences = [
7 'What is the name of the charm that creates a shield?',
8 'Book: 7, Chapter: 36\nPassage: 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 Invisibility Cloak at last. The yell of shock, the cheers, the screams on every side of "Harry!" "HE\'S ALIVE!" were stifled at once. The crowd was afraid, and silence fell abruptly and completely as Voldemort and Harry looked at each other, and began, at the same moment, to circle each other. "I don\'t want anyone else to try to help," Harry said loudly, and in the total silence his voice carried like a trumpet call.',
9 'Book: 3, Chapter: 12\nPassage: It\'s the nearest we\'ll get to a real dementor. The boggart will turn into a dementor when he sees you, so we\'ll be able to practice on him. I can store him in my office when we\'re not using him; there\'s a cupboard under my desk he\'ll like." "Okay," said Harry, trying to sound as though he wasn\'t apprehensive at all and merely glad that Lupin had found such a good substitute for a real dementor. "So ..." Professor Lupin had taken out his own wand, and indicated that Harry should do the same. "The spell I am going to try and teach you is highly advanced magic, Harry - well beyond Ordinary Wizarding Level. It is called the Patronus Charm." "How does it work?" said Harry nervously. "Well, when it works correctly, it conjures up a Patronus," said Lupin, "which is a kind of anti-dementor - a guardian that acts as a shield between you and the dementor." Harry had a sudden vision of himself crouching behind a Hagrid-sized figure holding a large club. Professor Lupin continued, "The Patronus is a kind of positive force, a projection of the very things that the dementor feeds upon - hope, happiness, the desire to survive - but it cannot feel despair, as real humans can, so the dementors can\'t hurt it. But I must warn you, Harry, that the charm might be too advanced for you. Many qualified wizards have difficulty with it." "What does a Patronus look like?" said Harry curiously.',
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]InformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.0247 |
| cosine_accuracy@3 | 0.037 |
| cosine_accuracy@5 | 0.0494 |
| cosine_accuracy@10 | 0.0617 |
| cosine_precision@1 | 0.0247 |
| cosine_precision@3 | 0.0123 |
| cosine_precision@5 | 0.0099 |
| cosine_precision@10 | 0.0062 |
| cosine_recall@1 | 0.0247 |
| cosine_recall@3 | 0.0288 |
| cosine_recall@5 | 0.0412 |
| cosine_recall@10 | 0.0535 |
| cosine_ndcg@10 | 0.0376 |
| cosine_mrr@10 | 0.0355 |
| cosine_map@100 | 0.0347 |
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 first person to be sorted into a house in Harry's year? | Book: 1, Chapter: 7[object Object]Passage: Professor McGonagall now stepped forward holding a long roll of parchment. "When I call your name, you will put on the hat and sit on the stool to be sorted," she said. "Abbott, Hannah!" A pink-faced girl with blonde pigtails stumbled out of line, put on the hat, which fell right down over her eyes, and sat down. A moment's pause -[object Object]"HUFFLEPUFF!" shouted the hat. The table on the right cheered and clapped as Hannah went to sit down at the Hufflepuff table. Harry saw the ghost of the Fat Friar waving merrily at her. "Bones, Susan!" "HUFFLEPUFF!" shouted the hat again, and Susan scuttled off to sit next to Hannah. "Boot, Terry!" "RAVENCLAW!" The table second from the left clapped this time; several Ravenclaws stood up to shake hands with Terry as he joined them. "Brocklehurst, Mandy" went to Ravenclaw too, but "Brown, Lavender" became the first new Gryffindor, and the table on the far left exploded with cheers; Harry could see Ron's twin brothers catcalling. | Book: 5, Chapter: 14[object Object]Passage: Harry was the first to awake in his dormitory next morning. He lay for a moment watching dust swirl in the chink of sunlight falling through the gap in his four-poster's hangings and savored the thought that it was Saturday. The first week of term seemed to have dragged on forever, like one gigantic History of Magic lesson. Judging by the sleepy silence and the freshly minted look of that beam of sunlight, it was just after daybreak. He pulled open the curtains around his bed, got up, and started to dress. The only sound apart from the distant twittering of birds was the slow, deep breathing of his fellow Gryffindors. He opened his schoolbag carefully, pulled out parchment and quill, and headed out of the dormitory for the common room. |
Which teacher accidentally removes all the bones from Harry's arm while trying to fix it? | Book: 2, Chapter: 10[object Object]Passage: So, Harry, just toddle up to the hospital wing - ah, Mr. Weasley, Miss Granger, would you escort him? - and Madam Pomfrey will be able to - er - tidy you up a bit." As Harry got to his feet, he felt strangely lopsided. Taking a deep breath he looked down at his right side. What he saw nearly made him pass out again. Poking out of the end of his robes was what looked like a thick, flesh-colored rubber glove. He tried to move his fingers. Nothing happened. Lockhart hadn't mended Harry's bones. He had removed them. Madam Pomfrey wasn't at all pleased. | Book: 3, Chapter: 7[object Object]Passage: "I'm afraid he won't be a teacher much longer," said Malfoy in a tone of mock sorrow. "Father's not very happy about my injury -"[object Object]"Keep talking, Malfoy, and I'll give you a real injury," snarled Ron. "- he's complained to the school governors. And to the Ministry of Magic. Father's got a lot of influence, you know. And a lasting injury like this" - he gave a huge, fake sigh - "who knows if my arm'll ever be the same again?" "So that's why you're putting it on," said Harry, accidentally beheading a dead caterpillar because his hand was shaking in anger. |
Who is the Slytherin prefect in Harry's fifth year? | Book: 5, Chapter: 10[object Object]Passage: The Stinksap vanished. "Sorry," said Neville again, in a small voice. Ron and Hermione did not turn up for nearly an hour, by which time the food trolley had already gone by. Harry, Ginny, and Neville had finished their Pumpkin Pasties and were busy swapping Chocolate Frog cards when the compartment door slid open and they walked in, accompanied by Crookshanks and a shrilly hooting Pigwidgeon in his cage. "I'm starving," said Ron, stowing Pigwidgeon next to Hedwig, grabbing a Chocolate Frog from Harry and throwing himself into the seat next to him. He ripped open the wrapper, bit off the Frog's head, and leaned back with his eyes closed as though he had had a very exhausting morning. "Well, there are two fifth-year prefects from each House," said Hermione, looking thoroughly disgruntled as she took her seat. "Boy and girl from each." "And guess who's a Slytherin prefect?" said Ron, still with his eyes closed. "Malfoy," replied Harry at once, his worst fear... | Book: 6, Chapter: 7[object Object]Passage: "Malfoy's not doing prefect duty. He's just sitting in his compartment with the other Slytherins, we saw him when we passed." Harry sat up straight, interested. It was not like Malfoy to pass up the chance to demonstrate his power as prefect, which he had happily abused all the previous year. "What did he do when he saw you?" "The usual," said Ron indifferently, demonstrating a rude hand gesture. "Not like him, though, is it? Well - that is" - he did the hand gesture again - "but why isn't he out there bullying first years? |
TripletLoss with these parameters:
1{
2 "distance_metric": "TripletDistanceMetric.COSINE",
3 "triplet_margin": 0.3
4}eval_strategy: stepsper_device_train_batch_size: 16per_device_eval_batch_size: 16num_train_epochs: 5multi_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: 5max_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 | cosine_ndcg@10 |
|---|---|---|
| 0.25 | 5 | 0.1607 |
| 0.5 | 10 | 0.1481 |
| 0.75 | 15 | 0.1110 |
| 1.0 | 20 | 0.1018 |
| 1.25 | 25 | 0.0897 |
| 1.5 | 30 | 0.0818 |
| 1.75 | 35 | 0.0691 |
| 2.0 | 40 | 0.0567 |
| 2.25 | 45 | 0.0565 |
| 2.5 | 50 | 0.0322 |
| 2.75 | 55 | 0.0283 |
| 3.0 | 60 | 0.0378 |
| 3.25 | 65 | 0.0585 |
| 3.5 | 70 | 0.0596 |
| 3.75 | 75 | 0.0506 |
| 4.0 | 80 | 0.0428 |
| 4.25 | 85 | 0.0376 |
| 4.5 | 90 | 0.0376 |
| 4.75 | 95 | 0.0376 |
| 5.0 | 100 | 0.0376 |
| -1 | -1 | 0.0376 |
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}