Upload PawanEmbd model
Browse files- .gitattributes +1 -0
- README.md +161 -0
- config.json +19 -0
- model.safetensors +3 -0
- requirements.txt +3 -0
- sentencepiece.bpe.model +3 -0
- special_tokens_map.json +51 -0
- tokenizer.json +3 -0
- tokenizer_config.json +55 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
tags:
|
| 5 |
+
- sentence-transformers
|
| 6 |
+
- sentence-similarity
|
| 7 |
+
- embedding
|
| 8 |
+
- knowledge-distillation
|
| 9 |
+
datasets:
|
| 10 |
+
- sentence-transformers/all-nli
|
| 11 |
+
metrics:
|
| 12 |
+
- cosine_similarity
|
| 13 |
+
pipeline_tag: sentence-similarity
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# PawanEmbd-68M
|
| 17 |
+
|
| 18 |
+
A 68M parameter embedding model distilled from Granite-278M
|
| 19 |
+
|
| 20 |
+
## Model Details
|
| 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
|
| 28 |
+
- **Max Sequence Length**: 512 tokens
|
| 29 |
+
|
| 30 |
+
## Training Details
|
| 31 |
+
|
| 32 |
+
This model was trained using knowledge distillation from the [IBM Granite-278M](https://huggingface.co/ibm-granite/granite-embedding-278m-multilingual) teacher model on the All-NLI dataset (SNLI + MultiNLI).
|
| 33 |
+
|
| 34 |
+
### Training Hyperparameters
|
| 35 |
+
|
| 36 |
+
- **Dataset**: sentence-transformers/all-nli (100K samples)
|
| 37 |
+
- **Epochs**: 20
|
| 38 |
+
- **Batch Size**: 32
|
| 39 |
+
- **Learning Rate**: 5e-4 with OneCycleLR scheduler
|
| 40 |
+
- **Loss Function**: Combined MSE + Cosine Similarity (α=0.5, β=0.5)
|
| 41 |
+
- **Mixed Precision**: FP16 (AMP)
|
| 42 |
+
- **Hardware**: NVIDIA T4 GPU
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
## Usage
|
| 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"]
|
| 60 |
+
encoded = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
| 61 |
+
|
| 62 |
+
# Get embeddings
|
| 63 |
+
with torch.no_grad():
|
| 64 |
+
outputs = model(**encoded)
|
| 65 |
+
embeddings = outputs.pooler_output # Already normalized
|
| 66 |
+
|
| 67 |
+
# Compute similarity
|
| 68 |
+
similarity = F.cosine_similarity(embeddings[0:1], embeddings[1:2])
|
| 69 |
+
print(f"Similarity: {similarity.item():.4f}")
|
| 70 |
+
```
|
| 71 |
+
|
| 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)
|
| 83 |
+
|
| 84 |
+
# Compute similarity
|
| 85 |
+
similarity = cos_sim(embeddings, embeddings)
|
| 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 |
+
|
| 109 |
+
### Comparison with Teacher Model
|
| 110 |
+
|
| 111 |
+
| Metric | Teacher (Granite-278M) | Student (PawanEmbd-68M) |
|
| 112 |
+
|--------|----------------------|----------------------|
|
| 113 |
+
| Parameters | 278M | 68M (4.1x smaller) |
|
| 114 |
+
| Model Size | ~1.1 GB | ~258.7 MB |
|
| 115 |
+
| Inference Speed (CPU) | 269.57 ms | 11.57 (23.3x faster) |
|
| 116 |
+
| Inference Speed (GPU) | 17.94.57 ms | 2.75 (6.5x faster) |
|
| 117 |
+
| Cosine Similarity | 1.000 | 0.943 |
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
## Intended Uses
|
| 121 |
+
|
| 122 |
+
This model is suitable for:
|
| 123 |
+
|
| 124 |
+
✅ **Semantic Search**: Find similar documents or passages
|
| 125 |
+
✅ **Clustering**: Group similar texts together
|
| 126 |
+
✅ **Duplicate Detection**: Identify near-duplicate content
|
| 127 |
+
✅ **Recommendation Systems**: Find similar items
|
| 128 |
+
✅ **Question Answering**: Retrieve relevant passages
|
| 129 |
+
✅ **Sentence Similarity**: Measure semantic similarity between texts
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
## Training Code
|
| 133 |
+
|
| 134 |
+
The model was trained using PyTorch with knowledge distillation. Training code available at: TODO
|
| 135 |
+
|
| 136 |
+
## Citation
|
| 137 |
+
|
| 138 |
+
```
|
| 139 |
+
@misc{pawanembdmodel2025,
|
| 140 |
+
author = {Dipankar Medhi},
|
| 141 |
+
title = {PawanEmbd: A Lightweight Embedding Model via Knowledge Distillation},
|
| 142 |
+
year = {2025},
|
| 143 |
+
publisher = {Hugging Face},
|
| 144 |
+
howpublished = { \url{https://huggingface.co/dmedhi/pawanembd-68m} }
|
| 145 |
+
}
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
## Acknowledgments
|
| 150 |
+
|
| 151 |
+
- Teacher model: [IBM Granite-278M](https://huggingface.co/ibm-granite/granite-embedding-278m-multilingual)
|
| 152 |
+
- Training data: [Sentence-Transformers All-NLI](https://huggingface.co/datasets/sentence-transformers/all-nli)
|
| 153 |
+
- Framework: Hugging Face Transformers & PyTorch
|
| 154 |
+
|
| 155 |
+
## License
|
| 156 |
+
|
| 157 |
+
Apache 2.0
|
| 158 |
+
|
| 159 |
+
## Contact
|
| 160 |
+
|
| 161 |
+
For questions or feedback, please open an issue on Github.
|
config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"PawanEmbdModel"
|
| 4 |
+
],
|
| 5 |
+
"bos_token_id": 0,
|
| 6 |
+
"dropout": 0.1,
|
| 7 |
+
"dtype": "float32",
|
| 8 |
+
"eos_token_id": 2,
|
| 9 |
+
"hidden_size": 256,
|
| 10 |
+
"intermediate_size": 1024,
|
| 11 |
+
"max_position_embeddings": 512,
|
| 12 |
+
"model_type": "pawan_embd",
|
| 13 |
+
"num_heads": 4,
|
| 14 |
+
"num_layers": 4,
|
| 15 |
+
"output_size": 768,
|
| 16 |
+
"pad_token_id": 1,
|
| 17 |
+
"transformers_version": "4.57.2",
|
| 18 |
+
"vocab_size": 250002
|
| 19 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fdc44ef043e813a4d5cadf7fe1b5d6f43a9f45d7d25ee4d8a632a3560a977daf
|
| 3 |
+
size 271272400
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers>=4.35.0
|
| 2 |
+
torch>=2.0.0
|
| 3 |
+
sentence-transformers>=2.2.0
|
sentencepiece.bpe.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cfc8146abe2a0488e9e2a0c56de7952f7c11ab059eca145a0a727afce0db2865
|
| 3 |
+
size 5069051
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<s>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": false,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"cls_token": {
|
| 10 |
+
"content": "<s>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": false,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"eos_token": {
|
| 17 |
+
"content": "</s>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": false,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"mask_token": {
|
| 24 |
+
"content": "<mask>",
|
| 25 |
+
"lstrip": true,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
},
|
| 30 |
+
"pad_token": {
|
| 31 |
+
"content": "<pad>",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": false,
|
| 34 |
+
"rstrip": false,
|
| 35 |
+
"single_word": false
|
| 36 |
+
},
|
| 37 |
+
"sep_token": {
|
| 38 |
+
"content": "</s>",
|
| 39 |
+
"lstrip": false,
|
| 40 |
+
"normalized": false,
|
| 41 |
+
"rstrip": false,
|
| 42 |
+
"single_word": false
|
| 43 |
+
},
|
| 44 |
+
"unk_token": {
|
| 45 |
+
"content": "<unk>",
|
| 46 |
+
"lstrip": false,
|
| 47 |
+
"normalized": false,
|
| 48 |
+
"rstrip": false,
|
| 49 |
+
"single_word": false
|
| 50 |
+
}
|
| 51 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3a56def25aa40facc030ea8b0b87f3688e4b3c39eb8b45d5702b3a1300fe2a20
|
| 3 |
+
size 17082734
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "<s>",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"1": {
|
| 12 |
+
"content": "<pad>",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"2": {
|
| 20 |
+
"content": "</s>",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"3": {
|
| 28 |
+
"content": "<unk>",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"250001": {
|
| 36 |
+
"content": "<mask>",
|
| 37 |
+
"lstrip": true,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"bos_token": "<s>",
|
| 45 |
+
"clean_up_tokenization_spaces": false,
|
| 46 |
+
"cls_token": "<s>",
|
| 47 |
+
"eos_token": "</s>",
|
| 48 |
+
"extra_special_tokens": {},
|
| 49 |
+
"mask_token": "<mask>",
|
| 50 |
+
"model_max_length": 512,
|
| 51 |
+
"pad_token": "<pad>",
|
| 52 |
+
"sep_token": "</s>",
|
| 53 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
| 54 |
+
"unk_token": "<unk>"
|
| 55 |
+
}
|