Views
No views yet
pip install -U sentence-transformers1from sentence_transformers import CrossEncoder
2
3# Download from the 🤗 Hub
4model = CrossEncoder("cross_encoder_model_id")
5# Get scores for pairs of texts
6pairs = [
7 ['president takes aim at cybersecurity through executive order just a few hours before the state of the union address president obama signed an executive order authorizing new policies to protect u s critical infrastructure cybersecurity the call for additional legislation in this area acknowledges the need for continued vigilance', 'take your child to work day the funniest someecards take your child to work day an excellent idea in all of its incarnations but sometimes goes awry in practice your kids'],
8 ['healthy breakfast ideas what health editors eat in the morning when it comes to eating breakfast most experts agree you should do it because health editors spend their days learning', 'eat healthier now simple swaps to make in your next meal there are plenty of ways you may be looking to improve your health and for every goal there are countless diet changes'],
9 ['how to kick the feeling that you re not good enough facing impostor feelings can be challenging but speaking with mentors recognizing your personal expertise using strategies to replace current negative habits with more positive beneficial patterns will bring you to a more optimistic experience so you can enjoy your well earned successes', 'how to stick to your resolutions by hacking your brain whether you keep a win journal or just a photo album your story will serve as a constant reminder of what you re capable of and inspire you to shoot even higher in the future the more you reshape your expectations of yourself the more you ll find yourself sticking to your goals'],
10 ['voter fraud the gop boogyman we ve put far too much energy into combatting a non existent problem and too little in resolving real issues of enfranchisement remember this when you vote in this general election', 'american dream fraud confession of a stupid idealist while i ve been a true believer and i ve perpetuated the belief in hard work as the great poverty buster now when i talk to some of them i feel that i ve perpetuated a great fraud upon them'],
11 ['what soda commercials would look like if they told the truth wet sugar with bubbles yep', 'these photos show how the world might look to a person with autism they don t look at most things in a typical way'],
12]
13scores = model.predict(pairs)
14print(scores.shape)
15# (5,)
16
17# Or rank different texts based on similarity to a single text
18ranks = model.rank(
19 'president takes aim at cybersecurity through executive order just a few hours before the state of the union address president obama signed an executive order authorizing new policies to protect u s critical infrastructure cybersecurity the call for additional legislation in this area acknowledges the need for continued vigilance',
20 [
21 'take your child to work day the funniest someecards take your child to work day an excellent idea in all of its incarnations but sometimes goes awry in practice your kids',
22 'eat healthier now simple swaps to make in your next meal there are plenty of ways you may be looking to improve your health and for every goal there are countless diet changes',
23 'how to stick to your resolutions by hacking your brain whether you keep a win journal or just a photo album your story will serve as a constant reminder of what you re capable of and inspire you to shoot even higher in the future the more you reshape your expectations of yourself the more you ll find yourself sticking to your goals',
24 'american dream fraud confession of a stupid idealist while i ve been a true believer and i ve perpetuated the belief in hard work as the great poverty buster now when i talk to some of them i feel that i ve perpetuated a great fraud upon them',
25 'these photos show how the world might look to a person with autism they don t look at most things in a typical way',
26 ]
27)
28# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
president takes aim at cybersecurity through executive order just a few hours before the state of the union address president obama signed an executive order authorizing new policies to protect u s critical infrastructure cybersecurity the call for additional legislation in this area acknowledges the need for continued vigilance | take your child to work day the funniest someecards take your child to work day an excellent idea in all of its incarnations but sometimes goes awry in practice your kids | 0.0 |
healthy breakfast ideas what health editors eat in the morning when it comes to eating breakfast most experts agree you should do it because health editors spend their days learning | eat healthier now simple swaps to make in your next meal there are plenty of ways you may be looking to improve your health and for every goal there are countless diet changes | 1.0 |
how to kick the feeling that you re not good enough facing impostor feelings can be challenging but speaking with mentors recognizing your personal expertise using strategies to replace current negative habits with more positive beneficial patterns will bring you to a more optimistic experience so you can enjoy your well earned successes | how to stick to your resolutions by hacking your brain whether you keep a win journal or just a photo album your story will serve as a constant reminder of what you re capable of and inspire you to shoot even higher in the future the more you reshape your expectations of yourself the more you ll find yourself sticking to your goals | 0.0 |
BinaryCrossEntropyLoss with these parameters:
1{
2 "activation_fn": "torch.nn.modules.linear.Identity",
3 "pos_weight": null
4}per_device_train_batch_size: 32per_device_eval_batch_size: 32num_train_epochs: 2overwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 32per_device_eval_batch_size: 32per_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: 2max_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}fsdp_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: Falsehub_always_push: Falsegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseeval_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: Falseeval_use_gather_object: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.6394 | 500 | 2.8338 |
| 1.2788 | 1000 | 0.7721 |
| 1.9182 | 1500 | 0.6555 |
| 0.6394 | 500 | 0.4732 |
| 1.2788 | 1000 | 0.4281 |
| 1.9182 | 1500 | 0.4102 |
| 0.6394 | 500 | 0.4003 |
| 1.2788 | 1000 | 0.3924 |
| 1.9182 | 1500 | 0.3882 |
| 0.6394 | 500 | 0.3756 |
| 1.2788 | 1000 | 0.3735 |
| 1.9182 | 1500 | 0.3651 |
| 0.6394 | 500 | 0.3533 |
| 1.2788 | 1000 | 0.3488 |
| 1.9182 | 1500 | 0.3489 |
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}