Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 13
How to use AShi846/all-MiniLM-L6-v2_rag_ft_e-7 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("AShi846/all-MiniLM-L6-v2_rag_ft_e-7")
sentences = [
"Suppose we use the Simplex method to solve the following linear program: \\begin{align*} \\textbf{maximize} \\hspace{0.8cm} & \\hspace{0.4cm}4x_1 - 6x_2 + 4x_3 \\\\ \\textbf{subject to}\\hspace{0.6cm} & x_1 - 3x_2 + x_3 + s_1 = 1 \\\\ \\hspace{0.8cm} & \\hspace{1.90cm}x_1 + s_2 = 8 \\\\ \\hspace{0.8cm} & \\hspace{0.65cm} 3x_2 + 2x_3 + s_3 = 6 \\\\ \\hspace{0.8cm} &\\hspace{-0.35cm} x_1,\\: x_2, \\: x_3, \\:s_1, \\:s_2, \\:s_3 \\geq 0 \\end{align*} At the current step, we have the following Simplex tableau: \\begin{align*} \\hspace{1cm} x_1 &= 1 + 3x_2 - x_3 - s_1 \\\\ s_2 &= 7 -3x_2 + x_3 + s_1 \\\\ s_3 &= 6 - 3x_2 - 2x_3 \\\\ \\cline{1-2} z &= 4 + 6 x_2 - 4s_1 \\end{align*} Write the tableau obtained by executing one iteration (pivot) of the Simplex method starting from the above tableau.",
"We want to assign each job to a machine. For any job $j$ which the LP assigns to a single machine $i$, i.e., $x^*_{ij} = 1$, it clearly makes sense to listen to the LP and assign $j$ to $i$. To assign the other jobs, we will use the graph $H$, which has the following properties: \\begin{itemize} \\item $H$ is acyclic, i.e., a forest. \\item Vertices corresponding to the already-assigned jobs are isolated. \\item Vertices corresponding to the yet-unassigned jobs have degree at least two. \\end{itemize} While $H$ contains an edge, we iteratively do the following: \\begin{itemize} \\item Choose a machine $i$ whose vertex $a_i$ has degree one in $H$, i.e., there is only a single edge $\\{a_i, b_j\\}$ incident to $a_i$. (Such a machine exists because $H$ is nonempty, and a nonempty forest contains a degree-one vertex; since job-vertices have degrees either zero or at least two, a degree-one vertex must be a machine-vertex.) \\item Assign job $j$ to machine $i$. \\item Remove all edges incident to $j$ from $H$. (Note that this preserves all the above properties of $H$.) \\end{itemize} Obviously, this procedure will terminate. Note that it will assign all jobs to machines, because as long as there is an unassigned job $j$, the vertex $b_j$ has at least two incident edges in $H$. It remains to reason that for every machine $i$, the sum of processing times of jobs assigned to $i$ (this is called the \\textit{makespan} of $i$) is at most $T + \\max_{j \\in J} p_j$. This is because there are two kinds of jobs assigned to $i$: \\begin{itemize} \\item Assigned in the beginning: the jobs $j$ which had $x^*_{ij} = 1$. The total processing time of these jobs is \\[ \\sum_{j\\in J: x^*_{ij} = 1} p_j = \\sum_{j\\in J: x^*_{ij} = 1} x^*_{ij} p_j \\le \\sum_{j\\in J: i \\in N(j)} x^*_{ij} p_j \\le T. \\] \\item Assigned later: at most one other job. For note that we only assign a job to $i$ when $a_i$ is of degree-one, and once we do, $a_i$ becomes isolated and no more jobs can be assigned to $i$. This job has processing time at most $\\max_{j \\in J} p_j$. \\end{itemize} Another perspective on the solution is the following. By looking at the makespan bound $T + \\max_j p_j$ that we should satisfy, we can notice that it will be fine if we assign the integral jobs to the machines that the LP has selected and the non-integral jobs in such a way that each machine gets at most one. In other words, we just need to prove that the graph $H$ has a matching which matches all non-integral jobs (any such matching will be fine). Our iterative procedure is one way to prove that such a matching exists.",
"1",
"It breaks backward compatibility, because the signature changes and \"Document\" is not a special kind of \"String\" thus callers will have to be updated"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from sentence-transformers/all-MiniLM-L6-v2. It maps sentences & paragraphs to a 384-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
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()
)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import SentenceTransformer
# Download from the 🤗 Hub
model = SentenceTransformer("AShi846/all-MiniLM-L6-v2_rag_ft_e-7")
# Run inference
sentences = [
'Show a code snippet which represents the kernel of a Spectre\n attack (use any convenient programming language or assembly).\n',
"No, this will force other members to sit through an explanation that's not relevant to them, the colleague was right.",
'Whatever your personal convictions, you have to adapt to the convention used by the project.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
Now let $\xv$ be a random vector distributed according to the uniform distribution over the finite centered dataset $\xv_1, . . . , \xv_N$ from above. % |
False. |
0.1 |
In the following problem Alice holds a string $x = \langle x_1, x_2, \ldots, x_n \rangle$ and Bob holds a string $y = \langle y_1, y_2, \ldots, y_n\rangle$. Both strings are of length $n$ and $x_i, y_i \in {1,2,\ldots, n}$ for $i=1,2, \ldots, n$. The goal is for Alice and Bob to use little communication to estimate the quantity \begin{align*} Q = \sum_{i=1}^n (x_i + y_i)^2,. \end{align*} A trivial solution is for Alice to transfer all of her string $x$ to Bob who then computes $Q$ exactly. However this requires Alice to send $\Theta(n \log n)$ bits of information to Bob. In the following, we use randomization and approximation to achieve a huge improvement on the number of bits transferred from Alice to Bob. Indeed, for a small parameter $\epsilon > 0$, your task is to devise and analyze a protocol of the following type: \begin{itemize} \item On input $x$, Alice uses a randomized algorithm to compute a message $m$ that consists of $O(\log (n)/\epsilon^2)$ bits. She then transmits ... |
The algorithm is as follows: \begin{itemize} \item If $x_1 \geq W$, then do the exchange on day $1$ and receive $x_1$ Swiss francs. \item Otherwise, do the exchange on day $2$ and receive $x_2$ Swiss francs. \end{itemize} We now analyze its competitiveness. If $x_1 \geq W$, then our algorithm gets at least $W$ Swiss francs. Optimum is at most $W^2$ and so we are $1/W$ competitive. Otherwise if $x_1 < W$ then we get $x_2 \geq 1$ Swiss francs which is $x_2/ \max(x_2, x_1) \geq 1/W$ competitive. |
0.1 |
What does it mean that a processor implements precise exceptions? |
When preparing benchmarks, your colleague should make sure that the inputs are representative of the real world, and complex enough to potentially detect performance bottlenecks. In this example, the inputs strings should be long enough. |
0.1 |
CosineSimilarityLoss with these parameters:{
"loss_fct": "torch.nn.modules.loss.MSELoss"
}
per_device_train_batch_size: 16per_device_eval_batch_size: 16num_train_epochs: 7multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_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: 7max_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: 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@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}
Base model
nreimers/MiniLM-L6-H384-uncased