luismsgomes commited on
Commit
ddb5b3e
1 Parent(s): 472e467

fixed README

Browse files
Files changed (1) hide show
  1. README.md +135 -3
README.md CHANGED
@@ -1,3 +1,135 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language: pt
4
+ library_name: sentence-transformers
5
+ pipeline_tag: sentence-similarity
6
+ tags:
7
+ - sentence-transformers
8
+ - feature-extraction
9
+ - sentence-similarity
10
+ - transformers
11
+
12
+ ---
13
+
14
+ # Serafim 900m Portuguese (PT) Sentence Transformer tuned for Information Retrieval (IR)
15
+
16
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 1536 dimensional dense vector space and can be used for tasks like clustering or semantic search.
17
+
18
+ <!--- Describe your model here -->
19
+
20
+ ## Usage (Sentence-Transformers)
21
+
22
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
23
+
24
+ ```
25
+ pip install -U sentence-transformers
26
+ ```
27
+
28
+ Then you can use the model like this:
29
+
30
+ ```python
31
+ from sentence_transformers import SentenceTransformer
32
+ sentences = ["This is an example sentence", "Each sentence is converted"]
33
+
34
+ model = SentenceTransformer('PORTULAN/serafim-900m-portuguese-pt-sentence-encoder-ir')
35
+ embeddings = model.encode(sentences)
36
+ print(embeddings)
37
+ ```
38
+
39
+
40
+
41
+ ## Usage (HuggingFace Transformers)
42
+ 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.
43
+
44
+ ```python
45
+ from transformers import AutoTokenizer, AutoModel
46
+ import torch
47
+
48
+
49
+ #Mean Pooling - Take attention mask into account for correct averaging
50
+ def mean_pooling(model_output, attention_mask):
51
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
52
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
53
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
54
+
55
+
56
+ # Sentences we want sentence embeddings for
57
+ sentences = ['This is an example sentence', 'Each sentence is converted']
58
+
59
+ # Load model from HuggingFace Hub
60
+ tokenizer = AutoTokenizer.from_pretrained('PORTULAN/serafim-900m-portuguese-pt-sentence-encoder-ir')
61
+ model = AutoModel.from_pretrained('PORTULAN/serafim-900m-portuguese-pt-sentence-encoder-ir')
62
+
63
+ # Tokenize sentences
64
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
65
+
66
+ # Compute token embeddings
67
+ with torch.no_grad():
68
+ model_output = model(**encoded_input)
69
+
70
+ # Perform pooling. In this case, mean pooling.
71
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
72
+
73
+ print("Sentence embeddings:")
74
+ print(sentence_embeddings)
75
+ ```
76
+
77
+
78
+
79
+ ## Evaluation Results
80
+
81
+ <!--- Describe how your model was evaluated -->
82
+
83
+ For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name=PORTULAN/serafim-900m-portuguese-pt-sentence-encoder-ir)
84
+
85
+
86
+ ## Training
87
+ The model was trained with the parameters:
88
+
89
+ **DataLoader**:
90
+
91
+ `sentence_transformers.datasets.NoDuplicatesDataLoader.NoDuplicatesDataLoader` of length 1989040 with parameters:
92
+ ```
93
+ {'batch_size': 40}
94
+ ```
95
+
96
+ **Loss**:
97
+
98
+ `sentence_transformers.losses.GISTEmbedLoss.GISTEmbedLoss` with parameters:
99
+ ```
100
+ {'guide': SentenceTransformer(
101
+ (0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: BertModel
102
+ (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, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
103
+ ), 'temperature': 0.01}
104
+ ```
105
+
106
+ Parameters of the fit()-Method:
107
+ ```
108
+ {
109
+ "epochs": 1,
110
+ "evaluation_steps": 19891,
111
+ "evaluator": "sentence_transformers.evaluation.InformationRetrievalEvaluator.InformationRetrievalEvaluator",
112
+ "max_grad_norm": 1,
113
+ "optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
114
+ "optimizer_params": {
115
+ "lr": 1e-06
116
+ },
117
+ "scheduler": "WarmupLinear",
118
+ "steps_per_epoch": 1989040,
119
+ "warmup_steps": 198904,
120
+ "weight_decay": 0.01
121
+ }
122
+ ```
123
+
124
+
125
+ ## Full Model Architecture
126
+ ```
127
+ SentenceTransformer(
128
+ (0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: DebertaV2Model
129
+ (1): Pooling({'word_embedding_dimension': 1536, '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})
130
+ )
131
+ ```
132
+
133
+ ## Citing & Authors
134
+
135
+ <!--- Describe where people can find more information -->