Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper
•
1908.10084
•
Published
•
10
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("hyunjongkimmath/notation_linking_rag_sentence_transformers_all_MiniLM_L6_v2")
# Run inference
sentences = [
'latex_in_original_or_summarized: \\pi\n\n[SEP]\n\nsummarized: $\\pi$\n\n[SEP]\n\nmain_note_content: The Categories $D_{c}^{b}(X, E)$ and $D_{c}^{b}\\left(X, \\overline{\\mathbb{Q}}_{l}\\right)$\n\nFor the finite extension field $E \\subset \\overline{\\mathbb{Q}}_{l}$ of $\\mathbb{Q}_{l}$, let $\\mathfrak{o}$ be theU valuation ring of $E$ and $\\pi$ be a generating element of the maximal ideal of $o$.\n\nIn Chap. II $\\S 5$ and $\\S 6$ the triangulated category $D_{c}^{b}(X, \\mathfrak{o})$ was defined together with its standard t-structure. In the following we explain the "localized" categories $D_{c}^{b}(X, E)$ and $D_{c}^{b}\\left(X, \\overline{\\mathbb{Q}}_{l}\\right)$. Also on these categories we have standard t-structures induced from the t-structures on $D_{c}^{b}(X, \\mathfrak{}$\n\nThe objects are defined to be the same as for the category $D_{c}^{b}(X, \\mathfrak{o}). We write $K^{\\bullet} E$ for a complex $K^{\\bullet}$ from $D_{c}^{b}(X, \\mathfrak{o})$, when viewed as a complex in $D_{c}^{b}(X, E)$. Furthermore\n\n$$ \\operatorname{Hom}\\left(F^{\\bullet} \\otimes E, K^{\\bullet} E\\right)=\\operatorname{Hom}\\left(F^{\\bullet}, K^{\\bullet}) \\otimes_{\\mathfrak{o}} E $$ ^c425ae\n\nAdmissible triangles in $D_{c}^{b}(X, E)$ are triangles, which are isomorphic in $D_{c}^{b}(X, E)$ to admissible triangles in $D_{c}^{b}(X, \\mathfrak{o})$.\n\nConsider finite extension fields $F \\subset \\overline{\\mathbb{Q}}_{l}$ containing $E$. Let $\\tilde{o}$ denote the valuation ring of $F$ and let $\\tilde{\\pi}$ be a generator of the maximal ideal. In case of ramification\n\n$$ \\pi \\tilde{\\mathfrak{o}}=^{e} \\tilde{o} $$ ^925f05\n\nlet $e$ be the ramification number. We construct natural functors\n\n$$ D_{c}^{b}(X, E) \\rightarrow D_{c}^{b}(X, F) $$ ^429009\n\nA. $\\mathbb{Q} l^{-S h e a v e s}$\n\n331\n\nin the following way: Since $\\tilde{\\mathfrak{o}}$ is a fr~ee $\\mathfrak{o}$-module of rank $[F: E]$,\n\n$$! \\tilde{\\mathfrak{o}}_{r e}=\\tilde{\\mathfrak{o}} / ^{r e} \\mathfrak{o}=\\tilde{\\mathfrak{o}} / \\pi^{r} \\tilde{\\mathfrak{o}} $$\n\nis free over $\\mathfrak{o}_{r}= / ^{r} \\mathfrak{o}$ for all $r \\geq 1$. Consider first the functors\n\n$$ \\begin{gathered} D_{c t f}^{b}\\left(X, \\mathfrak{o}_{r}\\right) \\rightarrow D_{c t f}^{b}(X, \\tilde{o}_{r e}\\right) \\\\ K^{} \\mapsto K^{\\bullet} \\otimes_{o_{r}} \\tilde{\\mathfrak{o}}_{r e}=K^{} \\otimes_{\\mathfrak{o}_{r}}^{L} \\tilde{\\mathfrak{o}}_{r e} $$\n\n\n\nThe family of these functors for $r=1,2, \\ldots$ naturally defines a functor\n\n$$``\\varprojlim_r\'\' D_{ctf}^b(X, \\mathfrak{o}_r) \\to ``_r\'\' D_{ctf}^b(X, \\tilde{\\mathfrak{o}}_{re}) = ``\\varprojlim_r\'\' D_{ctf}^b(X, \\tilde{\\mathfrak{o}}_{r\'}),$$\n\n\n\nhence by definition a functor\n\n$$ D_{c}^{b}(X, \\mathfrak{o}) \\rightarrow D_{c}^{b}(X, \\tilde{\\mathfrak{o}}) $$ ^807c7e\n\nBy localization, as above, we get from this the desired functor\n\n$$ D_{c}^{b}(X, E) \\rightarrow D_{c}^{b}(X, F) $$\n\nFinally the category $D_{c}^{b}\\left(X, }_{l})$ is defined as the direct limit\n\n$$ D_{c}^{b}\\left(X, }_{l}\\right)= ``\\lim _{r} " D_{c t f}^{b}(X, E) $$ ^2e1ccf\n\n(in the obvious way) of the categories $D_{c}^{b}(X, E)$, where $E \\subset \\overline{\\mathbb{Q}}_{l}$ ranges over all finite extension fields of $\\mathbb{Q}_{l}$. For all such fields $E$$ one has natural functors\n\n$$ \\begin{gathered} D_{c}^{b}(X, E) \\rightarrow D_{c}^{b}\\left(X, \\overline{\\mathbb{Q}}_{l}\\right) \\\\ K^{\\bullet} \\mapsto K^{\\bullet} \\otimes_{E} \\overline{\\mathbb{Q}}_{l} \\end{gathered} $$\n\nand\n\n$$ \\operatorname{Hom}\\left(F^{\\bullet} \\otimes_{E} \\overline{\\mathbb{Q}}_{l}, K^{\\bullet} \\otimes_{E} \\overline{\\mathbb{Q}}_{l}\\right)=\\operatorname{Hom}\\left(F^{\\bullet}, K^{\\bullet}\\right) \\otimes_{E} \\overline{\\mathbb{Q}}_{l} $$\n\nWe skip the obvious definitions for the usual derived functors related to the derived category $D_{c}^{b}\\left(X, \\overline{\\mathbb{Q}}_{l}\\right)$. The results for $D_{c}^{b}(X, \\mathfrak{o})$ immediately carry over to the categories D_{c}^{b}(X, E)$ and $D_{c}^{b}\\left(X, \\overline{\\mathbb{Q}}_{l}\\right)$. From the standard t-structure on $D_{c}^{b}(X, \\mathfrak{o})$, defined in Chap. II $\\S$, we immediately get t-structures on the categories $D_{c}^{b}(X, E)$ and $D_{c}^{b}\\left(X, }_{l}\\right)$.\n\n\n[SEP]\n\nprocessed_content: ',
'latex_in_original_or_summarized: \\mathfrak{o}\n\n[SEP]\n\nsummarized: $\\mathfrak{o}$\n\n[SEP]\n\nmain_note_content: The Categories $D_{c}^{b}(X, E)$ and $D_{c}^{b}\\left(X, \\overline{\\mathbb{Q}}_{l}\\right)$\n\nFor the finite extension field $E \\subset \\overline{\\mathbb{Q}}_{l}$ of $\\mathbb{Q}_{l}$, let $\\mathfrak{o}$ be the valuation ring of $E$ and $\\pi$ be a generating elem(ent of the maximal ideal of $o$.\n\nIn Chap. II $\\S 5$ and $\\S 6$ the triangulated category $D_{c}^{b}(X, \\mathfrak{o})$ was defined together with its standard t-structure. In the following we explain the "localized" categories $D_{c}^{b}(X, E)$ and $D_{c}^{b}\\left(X, \\overline{\\mathbb{Q}}_{l}\\right)$. Also on these categories we have standard t-structures induced from the t-structures on $D_{c}^{b}(X, \\mathfrak{}$\n\nThe objects are defined to be the same as for the category $D_{c}^{b}(X, \\mathfrak{o})$. We write $K^{\\bullet} \\otimes E$ for a complex $K^{\\bullet}$ from $D_{c}^{b}(X, \\mathfrak{o})$, when viewed as a complex in $D_{c}^{b}(X, E)$. Furthermore\n\n$$ \\operatorname{Hom}\\left(F^{\\bullet} \\otimes E, K^{\\bullet} \\otimes E\\right)=\\operatorname{Hom}\\left(F^{\\bullet}, K^{\\bullet}\\right) \\otimes_{\\mathfrak{o}} E $$ ^c425ae\n\nAdmissible triangles in $D_{c}^{b}(X, E)$ are triangles, which are isomorphic in $D_{c}^{b}(X, E)$ to admissible triangles in $D_{c}^{b}(X, \\mathfrak{o})$.\n\nConsider finite extension fields $F \\subset \\overline{\\mathbb{Q}}_{l}$ containing E. Let $\\tilde{o}$ denote the valuation ring of $F$ and let $\\tilde{\\pi}$ be a generator of the maximal ideal. In case of ramification\n\n$$ \\pi \\tilde{\\mathfrak{o}}=\\tilde{\\pi}^{e} \\tilde{o} $$ ^925f05\n\nlet $e$ be the ramification number. We construct natural functors\n\n$$ D_{c}^{b}(X, E) \\rightarrow D_{c}^{b}(X, F) $$ ^429009\n\nA. $\\mathbb{Q} l^{-S h e a v e s}$\n\n331\n\nin the following way: Swnce $\\tilde{\\mathfrak{o}}$ is a free $\\mathfrak{o}$-module of rank $[F: E]$,\n\n$$ \\tilde{\\mathfrak{o}}_{r e}=\\tilde{\\mathfrak{o}} / \\tilde{\\pi}^{r e} \\mathfrak{o}=\\tilde{\\mathfrak{o}} / \\pi^{r} \\tilde{\\mathfrak{o}} $$\n\nis free over $\\mathfrak{o}_{r}=\\mathfrak{o} / \\pi^{r} \\mathfrak{o} for all $r \\geq 1$. Consider first the functors\n\n$$ \\begin{gathered} D_{c t f}^{b}\\left(X, \\mathfrak{o}_{r}\\right) \\rightarrow D_{c t f}^{b}\\left(X, \\tilde{o}_{r e}\\right) \\\\ K^{\\bullet} \\mapsto K^{} \\otimes_{o_{r}} \\tilde{\\mathfrak{o}}_{r e}=K^{\\bullet} _{\\mathfrak{o}_{r}}^{L} \\tilde{\\mathfrak{o}}_{r e} \\end{gathered} $$$\n\n\n\nThe family of these functors for $r=1,2, \\ldots$ naturally defines a functor\n\n$$``\\varprojlim_r\'\' D_{ctf}^b(X, \\mathfrak{o}_r) \\to ``\\varprojlim_r\'\' D_{ctf}^b(X, \\tilde{\\mathfrak{o}}_{re}) = ``\\varprojlim_r\'\' D_{ctf}^b(X, \\tilde{\\mathfrak{o}}_{r\'}),$$\n\n\n\nhence by definition a functor\n\n$$ D_{c}^{b}(X, \\mathfrak{o}) \\rightarrow D_{c}^{b}(X, \\tilde{\\mathfrak{o}}) $$$ ^807c7e\n\nBy localization, as above, we get from this the desired functor\n\n$$ D_{c}^{b}(X, E) \\rightarrow D_{c}^{b}(X, F) $$\n\nFinally the category $D_{c}^{b}\\left(X, \\overline{\\mathbb{Q}}_{l}\\right)$ is defined as the direct limit\n\n$$ D_{c}^{b}\\left(X, \\overline{\\mathbb{Q}}_{l}\\right)= ``\\lim _{r} " D_{c t f}^{b}(X, E) $$ ^2e1ccf\n\n(in the obvious way) of the categories $D_{c}^{b}(X, E)$, where $E \\subset \\overline{\\mathbb{Q}}_{l}$ ranges over all finite extension fields of $\\mathbb{Q}_{l}$. For all such fields $E$ one has natural functors\n\n$$ \\begin{gathered} D_{c}^{b}(X, E) \\rightarrow D_{c}^{b}\\left(X, \\overline{\\mathbb{Q}}_{l}\\right) \\\\ K^{} \\mapsto K^{\\bullet} \\otimes_{E} }_{l} \\end{gathered} $$\n\nand\n\n$$ \\operatorname{Hom}\\left(F^{\\bullet} \\otimes_{E} \\overline{\\mathbb{Q}}_{l}, K^{\\bullet} \\otimes_{E} }_{l}\\right)=\\operatorname{Hom}\\left(F^{\\bullet}, K^{\\bullet}\\right) \\otimes_{E} \\overline{\\mathbb{Q}}_{l} $$\n\nWe skip the obvious definitions for the usual derived functors related to the derived category $D_{c}^{b}(X, \\overline{\\mathbb{Q}}_{l}\\right)$. The results for $D_{c}^{b}(X, \\mathfrak{o})$ immediately carry over to the categories D_{c}^{b}(X, E)$ and $D_{c}^{b}\\left(X, \\overline{\\mathbb{Q}}_{l}). From the standard t-structure on $D_{c}^{b}(X, \\mathfrak{o})$, defined in Chap. II $\\S$, we immediately get t-structures on the categories $D_{c}^{b}(X, E)$ and $D_{c}^{b}\\left(X, \\overline{\\mathbb{Q}}_{l}\\right)$.\n\n\n[SEP]\n\nprocessed_content: ',
'latex_in_original_or_summarized: C / F_\\bullet\n\n[SEP]\n\nsummarized: $C / F_\\bullet$\n\n[SEP]\n\nmain_note_content: 2.4.5. This can be generalized as follows. For a simplicial object $F$. in $T$ we define a topos $T / F_{\\text {}}$ as follows. For each $[n] \\in $ we can consider the localized topos $T / F_{n}$. For a morphism $\\delta:[n] \\rightarrow[m]$ we have a morphism of topoi\n\n$$ \\delta: T / F_{m} \\rightarrow T / F_{n} $$\n\ndefined as in exercise 2.F. The category $T / F_{\\bullet}$ is defined to be the category of systems $\\left\\{\\left(G_{n}, _{n}, G()\\right)\\}_{n N}$ consisting of an object $\\epsilon_{n}: G_{n} \\rightarrow F_{n}$ in $T / F_{n}$ for each $n$, and for every morphism $\\delta:[n] [m]$ in $$ map\n\n$$ G(\\delta): G_{n} \\rightarrow \\delta_{*} G_{m} $$\n\nin $T / F_{n}$ such that for a composition\n\n$$ [n] \\stackrel{\\delta}{\\longrightarrow}[m] \\stackrel{\\epsilon}{}[k] $$\n\nthe map\n\n$$ G_{k} \\stackrel{G(\\epsilon)}{} _{*} G_{m} \\stackrel{\\epsilon_{*} G(\\delta)}{\\longrightarrow} \\epsilon_{*} \\delta_{*} G_{n} \\simeq(\\epsilon \\delta)_{*} G_{n} $$\n\nis equal to $G(\\epsilon \\delta)$. A morphism $\\left\\{\\left(G_{n}, \\epsilon_{n}, G(\\delta)\\right)\\right\\}_{n} \\rightarrow\\left\\{\\left(G_{n}^{\\prime}, \\epsilon_{n}, G^{\\prime}(\\delta)\\right)\\right\\}_{n}$ in $T / F_{\\bullet}$ is a collection of maps $\\left\\{h_{n}: G_{n} \\rightarrow G_{n}^{\\prime}\\right\\}_{n \\in \\mathbb{N}}$ in $T / F_{n}$ such that for any morphism $\\delta:[n] \\rightarrow[m]$ in $$ the diagram\n\ncommutes.\n\nWe can define a site $C / F_\\bullet$ such that $T / F_{\\bullet}$ is equivalent to the category of sheaves on $C / F_{\\bullet}$ as follows. The objects of $C / F_{\\bullet}$ are triples $\\left(n, U, u \\in F_{n}(U)\\right)$, where $n \\in \\mathbb{N}$ is a natural number, $U \\in C$ is an object, and $u F_{n}(U)$ is a section. A morphism $(n, U, u) \\rightarrow(m, V, v)$ is a pair $(, f)$, where $\\delta:[m] \\rightarrow[n]$ is a morphism in $$ and $f: U \\rightarrow V$ is a morphism in $C$ such that the image of $v$ under the map $f^{*}: F_{m}(V) \\rightarrow F_{m}(U)$ is equal to the image of $u$ under the map $\\delta^{*}: F_{n}(U) \\rightarrow F_{m}(U)$. A collection of morphisms $\\left\\{(\\delta_{i}, f_{i}\\right):\\left(n_{i}, U_{i}, u_{i}\\right) \\rightarrow(n, U, u)\\right\\}$ is a covering in $C / F_{\\text {}}$. if $n_{i}=n$ for all $i$, each $\\delta_{i}$ is the identity map, and the\n\n2.4. SIMPIICIAL TOPOI\n\n57\n\ncollection $\\left\\{f_{i}: U_{i} \\rightarrow U\\}$ is a covering in $C$. We leave it as exercise 2 .I that $C / F_{\\bullet}$ is a site with associated topos $T / F_{\\bullet}$.\n\n\n[SEP]\n\nprocessed_content: ',
]
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]
relevance-valBinaryClassificationEvaluator| Metric | Value |
|---|---|
| cosine_accuracy | 0.8457 |
| cosine_accuracy_threshold | 0.5248 |
| cosine_f1 | 0.669 |
| cosine_f1_threshold | 0.3437 |
| cosine_precision | 0.6567 |
| cosine_recall | 0.6819 |
| cosine_ap | 0.6486 |
| cosine_mcc | 0.5579 |
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
latex_in_original_or_summarized: {}^{\mathrm{P}} \mathrm{D}^{ 0}(\mathrm{X}, O) |
latex_in_original_or_summarized: f_*, f^*, f_{!}, f^{!} |
1.0 |
latex_in_original_or_summarized: \theta: A_{\mathrm{inf}}\to \mathcal{O} |
latex_in_original_or_summarized: |
0.0 |
latex_in_original_or_summarized: K(M, n) |
latex_in_original_or_summarized: \langle u\rangle G W(F) |
0.0 |
CosineSimilarityLoss with these parameters:{
"loss_fct": "torch.nn.modules.loss.MSELoss"
}
eval_strategy: stepsper_device_train_batch_size: 1per_device_eval_batch_size: 1num_train_epochs: 1multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 1per_device_eval_batch_size: 1per_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: 1max_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: 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 | Training Loss | relevance-val_cosine_ap |
|---|---|---|---|
| 0.0019 | 500 | 0.2362 | - |
| 0.0038 | 1000 | 0.235 | - |
| 0.0057 | 1500 | 0.2233 | - |
| 0.0076 | 2000 | 0.2104 | - |
| 0.0094 | 2500 | 0.1846 | - |
| 0.0113 | 3000 | 0.1677 | - |
| 0.0132 | 3500 | 0.1602 | - |
| 0.0151 | 4000 | 0.1519 | 0.6486 |
| 0.0170 | 4500 | 0.1323 | - |
| 0.0189 | 5000 | 0.141 | - |
| 0.0208 | 5500 | 0.1446 | - |
| 0.0227 | 6000 | 0.1395 | - |
| 0.0245 | 6500 | 0.1307 | - |
| 0.0264 | 7000 | 0.1511 | - |
| 0.0283 | 7500 | 0.1358 | - |
| 0.0302 | 8000 | 0.1362 | 0.6486 |
@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
sentence-transformers/all-MiniLM-L6-v2