aari1995 commited on
Commit
659b07f
1 Parent(s): b03ef06

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +142 -0
README.md ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: sentence-similarity
3
+ language:
4
+ - de
5
+ datasets:
6
+ - stsb_multi_mt
7
+ tags:
8
+ - gBERT-large
9
+ - sentence-transformers
10
+ - feature-extraction
11
+ - sentence-similarity
12
+ - transformers
13
+
14
+ ---
15
+
16
+ # gBERT-large-STS_v2
17
+
18
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 1024 dimensional dense vector space and can be used for tasks like clustering or semantic search.
19
+
20
+ Special thanks to [deepset](https://huggingface.co/deepset/) for providing the model gBERT-large and also to [Philip May](https://huggingface.co/philipMay) for the Translation of the dataset and chats about the topic.
21
+
22
+ Model score after fine-tuning according to CSV:
23
+
24
+ **STS-B Test: 0.8626 (Spearman)**
25
+
26
+ This is the best result achieved that I know of.
27
+
28
+ <!--- Describe your model here -->
29
+
30
+ ## Usage (Sentence-Transformers)
31
+
32
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
33
+
34
+ ```
35
+ pip install -U sentence-transformers
36
+ ```
37
+
38
+ Then you can use the model like this:
39
+
40
+ ```python
41
+ from sentence_transformers import SentenceTransformer
42
+ sentences = ["This is an example sentence", "Each sentence is converted"]
43
+
44
+ model = SentenceTransformer('aari1995/gBERT-large-STS_v2')
45
+ embeddings = model.encode(sentences)
46
+ print(embeddings)
47
+ ```
48
+
49
+
50
+
51
+ ## Usage (HuggingFace Transformers)
52
+ 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.
53
+
54
+ ```python
55
+ from transformers import AutoTokenizer, AutoModel
56
+ import torch
57
+
58
+
59
+ #Mean Pooling - Take attention mask into account for correct averaging
60
+ def mean_pooling(model_output, attention_mask):
61
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
62
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
63
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
64
+
65
+
66
+ # Sentences we want sentence embeddings for
67
+ sentences = ['This is an example sentence', 'Each sentence is converted']
68
+
69
+ # Load model from HuggingFace Hub
70
+ tokenizer = AutoTokenizer.from_pretrained('aari1995/gBERT-large-STS_v2')
71
+ model = AutoModel.from_pretrained('aari1995/gBERT-large-STS_v2')
72
+
73
+ # Tokenize sentences
74
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
75
+
76
+ # Compute token embeddings
77
+ with torch.no_grad():
78
+ model_output = model(**encoded_input)
79
+
80
+ # Perform pooling. In this case, mean pooling.
81
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
82
+
83
+ print("Sentence embeddings:")
84
+ print(sentence_embeddings)
85
+ ```
86
+
87
+
88
+
89
+ ## Evaluation Results
90
+
91
+ <!--- Describe how your model was evaluated -->
92
+
93
+ For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name={MODEL_NAME})
94
+
95
+
96
+ ## Training
97
+ The model was trained with the parameters:
98
+
99
+ **DataLoader**:
100
+
101
+ `torch.utils.data.dataloader.DataLoader` of length 1438 with parameters:
102
+ ```
103
+ {'batch_size': 4, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
104
+ ```
105
+
106
+ **Loss**:
107
+
108
+ `sentence_transformers.losses.ContrastiveLoss.ContrastiveLoss` with parameters:
109
+ ```
110
+ {'distance_metric': 'SiameseDistanceMetric.COSINE_DISTANCE', 'margin': 0.5, 'size_average': True}
111
+ ```
112
+
113
+ Parameters of the fit()-Method:
114
+ ```
115
+ {
116
+ "epochs": 4,
117
+ "evaluation_steps": 500,
118
+ "evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
119
+ "max_grad_norm": 1,
120
+ "optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
121
+ "optimizer_params": {
122
+ "lr": 5e-06
123
+ },
124
+ "scheduler": "WarmupLinear",
125
+ "steps_per_epoch": null,
126
+ "warmup_steps": 576,
127
+ "weight_decay": 0.01
128
+ }
129
+ ```
130
+
131
+
132
+ ## Full Model Architecture
133
+ ```
134
+ SentenceTransformer(
135
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
136
+ (1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
137
+ )
138
+ ```
139
+
140
+ ## Citing & Authors
141
+
142
+ <!--- Describe where people can find more information -->