dmedhi commited on
Commit
976aa92
·
verified ·
1 Parent(s): a78bbe5

Add sentence-transformers compatibility

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 768,
3
+ "pooling_mode_cls_token": true,
4
+ "pooling_mode_mean_tokens": false,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false,
7
+ "pooling_mode_weightedmean_tokens": false,
8
+ "pooling_mode_lasttoken": false
9
+ }
2_Normalize/config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {}
README.md CHANGED
@@ -21,7 +21,7 @@ A 68M parameter embedding model distilled from Granite-278M
21
 
22
  - **Model Type**: Sentence Embedding Model
23
  - **Architecture**: Transformer-based encoder with projection layer
24
- - **Parameters**: ~68 million
25
  - **Teacher Model**: IBM Granite-278M Multilingual Embedding
26
  - **Training Method**: Knowledge Distillation
27
  - **Output Dimensions**: 768
@@ -46,14 +46,14 @@ This model was trained using knowledge distillation from the [IBM Granite-278M](
46
 
47
  ### Using Transformers
48
 
49
- ```Python
50
  from transformers import AutoModel, AutoTokenizer
51
  import torch
52
  import torch.nn.functional as F
53
 
54
  # Load model and tokenizer
55
- model = AutoModel.from_pretrained("dmedhi/PawanEmbd-68M")
56
- tokenizer = AutoTokenizer.from_pretrained("dmedhi/PawanEmbd-68M")
57
 
58
  # Encode sentences
59
  sentences = ["This is an example sentence", "Each sentence is converted to a vector"]
@@ -72,11 +72,11 @@ print(f"Similarity: {similarity.item():.4f}")
72
 
73
  ### Using Sentence-Transformers
74
 
75
- ```Python
76
  from sentence_transformers import SentenceTransformer
77
  from sentence_transformers.util import cos_sim
78
 
79
- model = SentenceTransformer("dmedhi/PawanEmbd-68M")
80
 
81
  sentences = ["This is an example sentence", "Each sentence is converted to a vector"]
82
  embeddings = model.encode(sentences)
@@ -86,6 +86,23 @@ similarity = cos_sim(embeddings, embeddings)
86
  print(f"Similarity: {similarity.item():.4f}")
87
  ```
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
  ## Performance
91
 
 
21
 
22
  - **Model Type**: Sentence Embedding Model
23
  - **Architecture**: Transformer-based encoder with projection layer
24
+ - **Parameters**: ~5 million
25
  - **Teacher Model**: IBM Granite-278M Multilingual Embedding
26
  - **Training Method**: Knowledge Distillation
27
  - **Output Dimensions**: 768
 
46
 
47
  ### Using Transformers
48
 
49
+ ```
50
  from transformers import AutoModel, AutoTokenizer
51
  import torch
52
  import torch.nn.functional as F
53
 
54
  # Load model and tokenizer
55
+ model = AutoModel.from_pretrained("dmedhi/pawanembd-68m")
56
+ tokenizer = AutoTokenizer.from_pretrained("dmedhi/pawanembd-68m")
57
 
58
  # Encode sentences
59
  sentences = ["This is an example sentence", "Each sentence is converted to a vector"]
 
72
 
73
  ### Using Sentence-Transformers
74
 
75
+ ```
76
  from sentence_transformers import SentenceTransformer
77
  from sentence_transformers.util import cos_sim
78
 
79
+ model = SentenceTransformer("dmedhi/pawanembd-68m")
80
 
81
  sentences = ["This is an example sentence", "Each sentence is converted to a vector"]
82
  embeddings = model.encode(sentences)
 
86
  print(f"Similarity: {similarity.item():.4f}")
87
  ```
88
 
89
+ ======================================================================
90
+ COMPARING INFERENCE SPEED (Student vs Teacher)
91
+ ======================================================================
92
+ Average inference time over 100 runs with 10 sentences (max_length=128):
93
+ Teacher Model: 17.944 ms
94
+ Student Model: 2.759 ms
95
+ Student is 6.5x faster than Teacher.
96
+
97
+ CPU speed comparision
98
+
99
+ ======================================================================
100
+ COMPARING INFERENCE SPEED (Student vs Teacher)
101
+ ======================================================================
102
+ Average inference time over 100 runs with 10 sentences (max_length=128):
103
+ Teacher Model: 269.578 ms
104
+ Student Model: 11.577 ms
105
+ Student is 23.3x faster than Teacher.
106
 
107
  ## Performance
108
 
modules.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "transformers.models.auto.modeling_auto.AutoModel"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Pooling",
12
+ "type": "sentence_transformers.models.Pooling"
13
+ },
14
+ {
15
+ "idx": 2,
16
+ "name": "2",
17
+ "path": "2_Normalize",
18
+ "type": "sentence_transformers.models.Normalize"
19
+ }
20
+ ]
sentence_transformers_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_name_or_path": "dmedhi/PawanEmbd-68M",
3
+ "model_type": "pawan_embd",
4
+ "__version__": {
5
+ "sentence_transformers": "2.2.0",
6
+ "transformers": "4.35.0",
7
+ "pytorch": "2.0.0"
8
+ }
9
+ }