Ponimash commited on
Commit
58b42ae
·
verified ·
1 Parent(s): 522f492

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +89 -11
README.md CHANGED
@@ -1,10 +1,18 @@
1
  ---
2
- pipeline_tag: sentence-similarity
3
  tags:
4
  - sentence-transformers
5
  - feature-extraction
6
  - sentence-similarity
7
-
 
 
 
 
 
 
 
 
 
8
  ---
9
 
10
  # FractalGPT/SbertSVDDistil
@@ -17,35 +25,105 @@ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentence
17
 
18
  Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
19
 
 
 
 
 
20
  ```
21
- pip install -U sentence-transformers
22
  ```
23
 
24
  Then you can use the model like this:
25
 
26
  ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  ```
29
 
30
 
 
 
 
 
 
 
 
 
31
 
32
- ## Evaluation Results
33
 
34
- <!--- Describe how your model was evaluated -->
35
 
36
- For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name=FractalGPT/SberDistil)
37
 
 
38
 
 
 
39
 
40
  ## Full Model Architecture
41
  ```
42
  SentenceTransformer(
43
- (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
44
  (1): Pooling({'word_embedding_dimension': 312, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
45
  (2): Dense({'in_features': 312, 'out_features': 384, 'bias': True, 'activation_function': 'torch.nn.modules.linear.Identity'})
46
  )
47
  ```
48
-
49
- ## Citing & Authors
50
-
51
- <!--- Describe where people can find more information -->
 
1
  ---
 
2
  tags:
3
  - sentence-transformers
4
  - feature-extraction
5
  - sentence-similarity
6
+ license: apache-2.0
7
+ datasets:
8
+ - wikimedia/wikipedia
9
+ - SiberiaSoft/SiberianPersonaChat-2
10
+ language:
11
+ - ru
12
+ - en
13
+ metrics:
14
+ - mse
15
+ library_name: transformers
16
  ---
17
 
18
  # FractalGPT/SbertSVDDistil
 
25
 
26
  Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
27
 
28
+ * [Run example in Collab](https://colab.research.google.com/drive/1m3fyh632htPs9UiEu4_AkQfrUtjDqIQq)
29
+
30
+
31
+
32
  ```
33
+ pip install -U sentence-transformers -q
34
  ```
35
 
36
  Then you can use the model like this:
37
 
38
  ```python
39
+ from transformers import BertModel
40
+ import numpy as np
41
+ import torch
42
+ from torch import nn
43
+ from sentence_transformers import SentenceTransformer, util
44
+ ```
45
+
46
+ ```python
47
+ class SVDLinearLayer(nn.Module):
48
+ def __init__(self, in_features, out_features, h_dim):
49
+ super(SVDLinearLayer, self).__init__()
50
+ self.encoder = nn.Linear(in_features, h_dim, bias=False)
51
+ self.decoder = nn.Linear(h_dim, out_features, bias=True)
52
+
53
+
54
+ def forward(self, x):
55
+ x = self.encoder(x)
56
+ x = self.decoder(x)
57
+ return x
58
+
59
+
60
+ class SVDBertModel(BertModel):
61
+ def __init__(self, config):
62
+ super(SVDBertModel, self).__init__(config)
63
+
64
+ for i, layer in enumerate(self.encoder.layer):
65
+ intermediate_size = layer.intermediate.dense.out_features
66
+ output_size = layer.output.dense.out_features
67
+
68
+ if i > 0:
69
+ layer.intermediate.dense = SVDLinearLayer(layer.intermediate.dense.in_features, intermediate_size, 5)
70
+ layer.output.dense = SVDLinearLayer(layer.output.dense.in_features, output_size, 5)
71
+ else:
72
+ layer.intermediate.dense = nn.Linear(layer.intermediate.dense.in_features, intermediate_size, True)
73
+ layer.output.dense = nn.Linear(layer.output.dense.in_features, output_size, True)
74
+
75
+
76
+ def sim(texts_1, texts_2):
77
+ embedding_1 = model.encode(texts_1)
78
+ embedding_2 = model.encode(texts_2)
79
+ s = util.pytorch_cos_sim(embedding_1, embedding_2)
80
+ return s.detach().numpy()
81
+ ```
82
+
83
+ ```python
84
+ path = 'FractalGPT/SbertSVDDistil'
85
+ model = SentenceTransformer(path)
86
+ model[0].auto_model = SVDBertModel.from_pretrained(path) # Правильная загрузка слоев с SVD
87
+ ```
88
 
89
+ ```python
90
+ sim(["I'm happy",
91
+ "Transistor (English transistor, an acronym invented in 1947 - from the English transfer + English resistor [1] - for a device for passing current through a resistance), semiconductor triode - an electronic component made of semiconductor material, capable of controlling a significant current into the output with a small input signal circuits, which allows it to be used to amplify, generate, switch and convert electrical signals. Currently, the transistor is the basis of the circuit design of the vast majority of electronic devices and integrated circuits.",
92
+ "That is a happy dog",
93
+ "Today is a sunny day",
94
+ "An electric vacuum triode, or simply triode, is an electronic tube that allows an input signal to control the current in an electrical circuit. It has three electrodes: a thermionic cathode (direct or indirectly heated), an anode and one control grid."],
95
+
96
+ ["Я счастлив",
97
+ "Транзи́стор (англ. transistor, придуманный в 1947 году акроним — от англ. transfer + англ. resistor[1] — для устройства пропуска тока через сопротивление), полупроводнико́вый трио́д — электронный компонент из полупроводникового материала, способный небольшим входным сигналом управлять значительным током в выходной цепи, что позволяет использовать его для усиления, генерирования, коммутации и преобразования электрических сигналов. В настоящее время транзистор является основой схемотехники подавляющего большинства электронных устройств и интегральных микросхем.",
98
+ "Это счастливая собака",
99
+ "Сегодня солнечный день",
100
+ "Эле́ктрова́куумный трио́д, или просто трио́д, — электронная лампа, позволяющая входным сигналом управлять током в электрической цепи. Имеет три электрода: термоэлектронный катод (прямого или косвенного накала), анод и одну управляющую сетку."])
101
  ```
102
 
103
 
104
+ ```
105
+ array([[ 0.92624545, -0.1081745 , 0.5569258 , 0.4006917 , 0.0524814 ],
106
+ [-0.10137352, 0.9214004 , -0.0590867 , -0.05579955, 0.6043041 ],
107
+ [ 0.56128216, -0.08206842, 0.9496383 , 0.23291808, 0.03726077],
108
+ [ 0.34002465, -0.05840789, 0.240945 , 0.9276679 , 0.09676868],
109
+ [-0.01571994, 0.60077745, -0.00638374, -0.02819303, 0.8434113 ]],
110
+ dtype=float32)
111
+ ```
112
 
 
113
 
 
114
 
115
+ ## Training
116
 
117
+ * Base model [FractalGPT/SbertDistil](https://huggingface.co/FractalGPT/SbertDistil).
118
 
119
+ * Log of additional training after decomposition.
120
+ <img src="https://github.com/FractalGPT/ModelEmbedderDistilation/blob/main/SbertSVDDistil/Train/en.JPG?raw=true" width=700 />
121
 
122
  ## Full Model Architecture
123
  ```
124
  SentenceTransformer(
125
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: SVDBertModel
126
  (1): Pooling({'word_embedding_dimension': 312, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
127
  (2): Dense({'in_features': 312, 'out_features': 384, 'bias': True, 'activation_function': 'torch.nn.modules.linear.Identity'})
128
  )
129
  ```