jaimevera1107 commited on
Commit
49f82d5
1 Parent(s): fc85089

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +57 -16
README.md CHANGED
@@ -4,12 +4,18 @@ tags:
4
  - sentence-transformers
5
  - feature-extraction
6
  - sentence-similarity
7
-
 
 
 
 
 
 
8
  ---
9
 
10
- # {MODEL_NAME}
11
 
12
- This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search.
13
 
14
  <!--- Describe your model here -->
15
 
@@ -25,20 +31,58 @@ Then you can use the model like this:
25
 
26
  ```python
27
  from sentence_transformers import SentenceTransformer
28
- sentences = ["This is an example sentence", "Each sentence is converted"]
29
 
30
- model = SentenceTransformer('{MODEL_NAME}')
31
  embeddings = model.encode(sentences)
32
  print(embeddings)
33
  ```
34
 
35
 
36
 
37
- ## Evaluation Results
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
- <!--- Describe how your model was evaluated -->
40
 
41
- For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name={MODEL_NAME})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
 
44
  ## Training
@@ -51,6 +95,8 @@ The model was trained with the parameters:
51
  {'batch_size': 16, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
52
  ```
53
 
 
 
54
  **Loss**:
55
 
56
  `sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss`
@@ -77,12 +123,7 @@ Parameters of the fit()-Method:
77
  ## Full Model Architecture
78
  ```
79
  SentenceTransformer(
80
- (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel
81
- (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})
82
- (2): Normalize()
83
  )
84
- ```
85
-
86
- ## Citing & Authors
87
-
88
- <!--- Describe where people can find more information -->
 
4
  - sentence-transformers
5
  - feature-extraction
6
  - sentence-similarity
7
+ - transformers
8
+ license: mit
9
+ datasets:
10
+ - jaimevera1107/similarity-sentences-spanish
11
+ language:
12
+ - es
13
+ library_name: sentence-transformers
14
  ---
15
 
16
+ # All-MiniLM-L6-v2 Fine Tuned - Sentence Transformers - Embedding Model (Spanish-Español)
17
 
18
+ 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.
19
 
20
  <!--- Describe your model here -->
21
 
 
31
 
32
  ```python
33
  from sentence_transformers import SentenceTransformer
34
+ sentences = ["Esta es una frase para ser comparada", "Esta es otra oración"]
35
 
36
+ model = SentenceTransformer('jaimevera1107/roberta-similarity-es')
37
  embeddings = model.encode(sentences)
38
  print(embeddings)
39
  ```
40
 
41
 
42
 
43
+ ## Usage (HuggingFace Transformers)
44
+ 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.
45
+
46
+ ```python
47
+ from transformers import AutoTokenizer, AutoModel
48
+ import torch
49
+
50
+
51
+ #Mean Pooling - Take attention mask into account for correct averaging
52
+ def mean_pooling(model_output, attention_mask):
53
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
54
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
55
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
56
 
 
57
 
58
+ # Sentences we want sentence embeddings for
59
+ sentences = ["Esta es una frase para ser comparada", "Esta es otra oración"]
60
+
61
+ # Load model from HuggingFace Hub
62
+ tokenizer = AutoTokenizer.from_pretrained('jaimevera1107/roberta-similarity-es')
63
+ model = AutoModel.from_pretrained('jaimevera1107/roberta-similarity-es')
64
+
65
+ # Tokenize sentences
66
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
67
+
68
+ # Compute token embeddings
69
+ with torch.no_grad():
70
+ model_output = model(**encoded_input)
71
+
72
+ # Perform pooling. In this case, mean pooling.
73
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
74
+
75
+ print("Sentence embeddings:")
76
+ print(sentence_embeddings)
77
+ ```
78
+
79
+
80
+
81
+ ## Evaluation Results
82
+
83
+ | Model | R squared | Spearman Correlation |
84
+ |----------------------------|--------------|-------------------------|
85
+ | Roberta Fine tuned | 70.67 % | 83.41 % |
86
 
87
 
88
  ## Training
 
95
  {'batch_size': 16, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
96
  ```
97
 
98
+ The data used was the one in the [Similarity Sentences Spanish Dataset](https://huggingface.co/datasets/jaimevera1107/similarity-sentences-spanish)
99
+
100
  **Loss**:
101
 
102
  `sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss`
 
123
  ## Full Model Architecture
124
  ```
125
  SentenceTransformer(
126
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: RobertaModel
127
+ (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})
 
128
  )
129
+ ```