Sentence Similarity
sentence-transformers
Safetensors
Transformers
bert
feature-extraction
text-embeddings-inference
Instructions to use finvector/Test_sbert_lora_finsent-finmodern_2chunks_pair_merged with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use finvector/Test_sbert_lora_finsent-finmodern_2chunks_pair_merged with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("finvector/Test_sbert_lora_finsent-finmodern_2chunks_pair_merged") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Transformers
How to use finvector/Test_sbert_lora_finsent-finmodern_2chunks_pair_merged with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("finvector/Test_sbert_lora_finsent-finmodern_2chunks_pair_merged") model = AutoModel.from_pretrained("finvector/Test_sbert_lora_finsent-finmodern_2chunks_pair_merged", device_map="auto") - Notebooks
- Google Colab
- Kaggle
2026_1123_2040_11
Browse files- 1_Pooling/config.json +5 -0
- README.md +101 -0
- config.json +30 -0
- config_sentence_transformers.json +15 -0
- model.safetensors +3 -0
- modules.json +14 -0
- sentence_bert_config.json +10 -0
- tokenizer.json +0 -0
- tokenizer_config.json +17 -0
1_Pooling/config.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"embedding_dimension": 768,
|
| 3 |
+
"pooling_mode": "mean",
|
| 4 |
+
"include_prompt": true
|
| 5 |
+
}
|
README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
library_name: sentence-transformers
|
| 4 |
+
tags:
|
| 5 |
+
- sentence-transformers
|
| 6 |
+
- feature-extraction
|
| 7 |
+
- sentence-similarity
|
| 8 |
+
- transformers
|
| 9 |
+
pipeline_tag: sentence-similarity
|
| 10 |
+
---
|
| 11 |
+
**⚠️ This model is deprecated. Please don't use it as it produces sentence embeddings of low quality. You can find recommended sentence embedding models here: [SBERT.net - Pretrained Models](https://www.sbert.net/docs/pretrained_models.html)**
|
| 12 |
+
|
| 13 |
+
# sentence-transformers/bert-base-nli-mean-tokens
|
| 14 |
+
|
| 15 |
+
This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
## Usage (Sentence-Transformers)
|
| 20 |
+
|
| 21 |
+
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
| 22 |
+
|
| 23 |
+
```
|
| 24 |
+
pip install -U sentence-transformers
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
Then you can use the model like this:
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
from sentence_transformers import SentenceTransformer
|
| 31 |
+
sentences = ["This is an example sentence", "Each sentence is converted"]
|
| 32 |
+
|
| 33 |
+
model = SentenceTransformer('sentence-transformers/bert-base-nli-mean-tokens')
|
| 34 |
+
embeddings = model.encode(sentences)
|
| 35 |
+
print(embeddings)
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
## Usage (HuggingFace Transformers)
|
| 41 |
+
Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
from transformers import AutoTokenizer, AutoModel
|
| 45 |
+
import torch
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
| 49 |
+
def mean_pooling(model_output, attention_mask):
|
| 50 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
| 51 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
| 52 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
# Sentences we want sentence embeddings for
|
| 56 |
+
sentences = ['This is an example sentence', 'Each sentence is converted']
|
| 57 |
+
|
| 58 |
+
# Load model from HuggingFace Hub
|
| 59 |
+
tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/bert-base-nli-mean-tokens')
|
| 60 |
+
model = AutoModel.from_pretrained('sentence-transformers/bert-base-nli-mean-tokens')
|
| 61 |
+
|
| 62 |
+
# Tokenize sentences
|
| 63 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
| 64 |
+
|
| 65 |
+
# Compute token embeddings
|
| 66 |
+
with torch.no_grad():
|
| 67 |
+
model_output = model(**encoded_input)
|
| 68 |
+
|
| 69 |
+
# Perform pooling. In this case, max pooling.
|
| 70 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
| 71 |
+
|
| 72 |
+
print("Sentence embeddings:")
|
| 73 |
+
print(sentence_embeddings)
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
## Full Model Architecture
|
| 79 |
+
```
|
| 80 |
+
SentenceTransformer(
|
| 81 |
+
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: BertModel
|
| 82 |
+
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
|
| 83 |
+
)
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
## Citing & Authors
|
| 87 |
+
|
| 88 |
+
This model was trained by [sentence-transformers](https://www.sbert.net/).
|
| 89 |
+
|
| 90 |
+
If you find this model helpful, feel free to cite our publication [Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks](https://arxiv.org/abs/1908.10084):
|
| 91 |
+
```bibtex
|
| 92 |
+
@inproceedings{reimers-2019-sentence-bert,
|
| 93 |
+
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
|
| 94 |
+
author = "Reimers, Nils and Gurevych, Iryna",
|
| 95 |
+
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
|
| 96 |
+
month = "11",
|
| 97 |
+
year = "2019",
|
| 98 |
+
publisher = "Association for Computational Linguistics",
|
| 99 |
+
url = "http://arxiv.org/abs/1908.10084",
|
| 100 |
+
}
|
| 101 |
+
```
|
config.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_cross_attention": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"BertModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"bos_token_id": null,
|
| 8 |
+
"classifier_dropout": null,
|
| 9 |
+
"dtype": "bfloat16",
|
| 10 |
+
"eos_token_id": null,
|
| 11 |
+
"gradient_checkpointing": false,
|
| 12 |
+
"hidden_act": "gelu",
|
| 13 |
+
"hidden_dropout_prob": 0.1,
|
| 14 |
+
"hidden_size": 768,
|
| 15 |
+
"initializer_range": 0.02,
|
| 16 |
+
"intermediate_size": 3072,
|
| 17 |
+
"is_decoder": false,
|
| 18 |
+
"layer_norm_eps": 1e-12,
|
| 19 |
+
"max_position_embeddings": 512,
|
| 20 |
+
"model_type": "bert",
|
| 21 |
+
"num_attention_heads": 12,
|
| 22 |
+
"num_hidden_layers": 12,
|
| 23 |
+
"pad_token_id": 0,
|
| 24 |
+
"position_embedding_type": "absolute",
|
| 25 |
+
"tie_word_embeddings": true,
|
| 26 |
+
"transformers_version": "5.22.1",
|
| 27 |
+
"type_vocab_size": 2,
|
| 28 |
+
"use_cache": true,
|
| 29 |
+
"vocab_size": 30522
|
| 30 |
+
}
|
config_sentence_transformers.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"__version__": {
|
| 3 |
+
"pytorch": "2.14.1+cu130",
|
| 4 |
+
"sentence_transformers": "5.6.0",
|
| 5 |
+
"transformers": "5.22.1"
|
| 6 |
+
},
|
| 7 |
+
"default_prompt_name": null,
|
| 8 |
+
"model_type": "SentenceTransformer",
|
| 9 |
+
"prompts": {
|
| 10 |
+
"document": "",
|
| 11 |
+
"passage": "",
|
| 12 |
+
"query": ""
|
| 13 |
+
},
|
| 14 |
+
"similarity_fn_name": "cosine"
|
| 15 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:74d473b5271799bb0cb8b73ee8ba97a2c429f2ba852b353f9245e9c294b3f9a9
|
| 3 |
+
size 218986928
|
modules.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"idx": 0,
|
| 4 |
+
"name": "0",
|
| 5 |
+
"path": "",
|
| 6 |
+
"type": "sentence_transformers.base.modules.transformer.Transformer"
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"idx": 1,
|
| 10 |
+
"name": "1",
|
| 11 |
+
"path": "1_Pooling",
|
| 12 |
+
"type": "sentence_transformers.sentence_transformer.modules.pooling.Pooling"
|
| 13 |
+
}
|
| 14 |
+
]
|
sentence_bert_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"transformer_task": "feature-extraction",
|
| 3 |
+
"modality_config": {
|
| 4 |
+
"text": {
|
| 5 |
+
"method": "forward",
|
| 6 |
+
"method_output_name": "last_hidden_state"
|
| 7 |
+
}
|
| 8 |
+
},
|
| 9 |
+
"module_output_name": "token_embeddings"
|
| 10 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"do_basic_tokenize": true,
|
| 5 |
+
"do_lower_case": true,
|
| 6 |
+
"is_local": false,
|
| 7 |
+
"local_files_only": false,
|
| 8 |
+
"mask_token": "[MASK]",
|
| 9 |
+
"model_max_length": 512,
|
| 10 |
+
"never_split": null,
|
| 11 |
+
"pad_token": "[PAD]",
|
| 12 |
+
"sep_token": "[SEP]",
|
| 13 |
+
"strip_accents": null,
|
| 14 |
+
"tokenize_chinese_chars": true,
|
| 15 |
+
"tokenizer_class": "BertTokenizer",
|
| 16 |
+
"unk_token": "[UNK]"
|
| 17 |
+
}
|