LNTTushar commited on
Commit
32aa11b
·
verified ·
1 Parent(s): b91f8d3

Improve model card: problem/why/speed/RAM/benchmarks/install/example

Browse files
Files changed (1) hide show
  1. README.md +38 -152
README.md CHANGED
@@ -1,171 +1,57 @@
1
  ---
2
- language: en
3
  license: apache-2.0
4
- library_name: sentence-transformers
5
  pipeline_tag: sentence-similarity
6
  tags:
7
- - sentence-transformers
8
- - feature-extraction
9
  - sentence-similarity
10
- - transformers
11
- - pytorch
12
- - semantic-search
13
- - custom-architecture
14
- - automated-tokenizer
15
- datasets:
16
- - mteb/stsbenchmark-sts
17
- - synthetic-similarity-data
18
- metrics:
19
- - spearman_correlation
20
- - pearson_correlation
21
- model-index:
22
- - name: Sentence Embedding Model
23
- results:
24
- - task:
25
- type: STS
26
- dataset:
27
- type: mteb/stsbenchmark-sts
28
- name: MTEB STSBenchmark
29
- config: default
30
- split: test
31
- metrics:
32
- - type: cos_sim_spearman
33
- value: 67.74
34
- - type: cos_sim_pearson
35
- value: 67.21
36
  ---
37
 
38
- # Sentence Embedding Model - Production Release
39
 
40
- ## 📊 Model Performance
41
- - **Semantic Understanding**: Strong correlation with human judgments
42
- - **Model Parameters**: 3,299,584
43
- - **Model Size**: 12.6MB
44
- - **Vocabulary Size**: 164 tokens (automatically built from stopwords + domain words)
45
- - **Max Sequence Length**: 128 tokens
46
- - **Embedding Dimensions**: Model-specific
47
 
48
- ## 🚀 Quick Start
 
 
 
 
 
 
49
 
50
- ### Installation
51
- ```bash
52
- pip install -r api/requirements.txt
53
- ```
54
 
55
- ### Basic Usage
56
- ```python
57
- from api.inference_api import SentenceEmbeddingInference
 
 
58
 
59
- # Initialize model
60
- model = SentenceEmbeddingInference("./")
61
 
62
- # Generate embeddings
63
- texts = ["Your text here", "Another text"]
64
- embeddings = model.get_embeddings(texts)
65
 
66
- # Compute similarity
67
- similarity = model.compute_similarity("Text 1", "Text 2")
 
 
68
 
69
- # Find similar texts
70
- query = "Search query"
71
- candidates = ["Text A", "Text B", "Text C"]
72
- results = model.find_similar_texts(query, candidates, top_k=3)
73
- ```
74
 
75
- ### Alternative Usage with Sentence Transformers
76
- ```python
77
- from sentence_transformers import SentenceTransformer
78
 
79
- # Load the model
80
- model = SentenceTransformer('LNTTushar/sentence-embedding-model-production-release')
 
 
81
 
82
- # Generate embeddings
83
- sentences = ["Machine learning is transforming AI", "AI includes machine learning"]
84
- embeddings = model.encode(sentences)
85
 
86
- # Compute similarity
87
- similarity = model.similarity(sentences[0], sentences[1])
88
- print(f"Similarity: {similarity:.4f}")
89
- ```
90
-
91
- ## 🔧 Automatic Tokenizer Features
92
- - **Stopwords Integration**: Uses comprehensive English stopwords
93
- - **Technical Vocabulary**: Includes ML/AI domain-specific terms
94
- - **Character Fallback**: Handles unknown words with character-level encoding
95
- - **Dynamic Building**: Automatically extracts vocabulary from training data
96
- - **No Manual Lists**: Eliminates need for manual word curation
97
-
98
- ## 📁 Package Structure
99
- ```
100
- ├── models/ # Model weights and configuration
101
- ├── tokenizer/ # Auto-generated vocabulary and mappings
102
- ├── exports/ # Optimized model exports (TorchScript)
103
- ├── api/ # Python inference API
104
- │ ├── inference_api.py
105
- │ └── requirements.txt
106
- └── README.md # This file
107
- ```
108
-
109
- ## ⚡ Performance Benchmarks
110
- - **Inference Speed**: ~500-1000 sentences/second (CPU)
111
- - **Memory Usage**: ~13MB base model
112
- - **Vocabulary**: Auto-built with 164 tokens
113
- - **Export Formats**: PyTorch, TorchScript (optimized)
114
-
115
- ## 🎯 Development Highlights
116
- This model represents a complete from-scratch development:
117
- 1. ✅ Automated tokenizer with stopwords + technical terms
118
- 2. ✅ No manual vocabulary curation required
119
- 3. ✅ Dynamic vocabulary building from training data
120
- 4. ✅ Comprehensive fallback mechanisms
121
- 5. ✅ Production-ready deployment package
122
-
123
- ## 📞 API Reference
124
-
125
- ### SentenceEmbeddingInference Class
126
-
127
- #### Methods:
128
- - `get_embeddings(texts, batch_size=8)`: Generate sentence embeddings
129
- - `compute_similarity(text1, text2)`: Calculate cosine similarity
130
- - `find_similar_texts(query, candidates, top_k=5)`: Find most similar texts
131
- - `benchmark_performance(num_texts=100)`: Run performance benchmarks
132
-
133
- ## 📋 System Requirements
134
- - **Python**: 3.7+
135
- - **PyTorch**: 1.9.0+
136
- - **NumPy**: 1.20.0+
137
- - **Memory**: ~512MB RAM recommended
138
- - **Storage**: ~50MB for model files
139
-
140
- ## 🏷️ Version Information
141
- - **Model Version**: 1.0
142
- - **Export Date**: 2025-07-22
143
- - **Tokenizer**: Auto-generated with stopwords
144
- - **Status**: Production-ready
145
-
146
- ## 🔬 Technical Details
147
-
148
- ### Architecture
149
- - **Custom Transformer**: Built from scratch with 3.3M parameters
150
- - **Embedding Dimension**: 384
151
- - **Attention Heads**: 6 per layer
152
- - **Transformer Layers**: 4 layers optimized for sentence embeddings
153
- - **Pooling Strategy**: Mean pooling for sentence-level representations
154
-
155
- ### Training
156
- - **Dataset**: STS Benchmark + synthetic similarity pairs
157
- - **Loss Function**: Multi-objective (MSE + ranking + contrastive)
158
- - **Optimization**: Custom training pipeline with advanced techniques
159
- - **Vocabulary Building**: Automated from training corpus + stopwords
160
-
161
- ### Performance Metrics
162
- - **Spearman Correlation**: Strong semantic similarity understanding
163
- - **Processing Speed**: 500-1000 sentences/second on CPU
164
- - **Memory Efficiency**: 13MB model size vs 90MB+ for comparable models
165
- - **Deployment Ready**: Optimized for production environments
166
-
167
- ---
168
-
169
- **Built with automated tokenizer using comprehensive stopwords and domain vocabulary**
170
-
171
- 🎉 **No more manual word lists - fully automated vocabulary building!**
 
1
  ---
 
2
  license: apache-2.0
 
3
  pipeline_tag: sentence-similarity
4
  tags:
5
+ - sentence-embeddings
 
6
  - sentence-similarity
7
+ - transformer
8
+ - from-scratch
9
+ - educational
10
+ language:
11
+ - en
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
+ # TrynMini v1 — a sentence transformer built from scratch (research prototype)
15
 
16
+ A compact **transformer sentence encoder implemented from scratch** — embeddings, sinusoidal
17
+ positional encoding, multi-head self-attention, feed-forward blocks, and masked mean pooling,
18
+ all hand-written (no `transformers` library) and trained on STS-B plus synthetic similarity data.
 
 
 
 
19
 
20
+ > ### This is an early research prototype, not a production encoder.
21
+ > v1 shipped with a **tiny auto-generated vocabulary (~164 tokens)** learned from limited,
22
+ > templated training text. As a result it handles the phrases it saw in training but **does not
23
+ > generalize to arbitrary English** — most real-world words fall back to `[UNK]`. It's published
24
+ > as a learning milestone and for provenance.
25
+ >
26
+ > **For a model you can actually use, see [LNTTushar/trynmini-v2-static-7m-v2](https://huggingface.co/LNTTushar/trynmini-v2-static-7m-v2)** — a properly trained static embedder (30k vocab, 0.715 STSB-dev, 7.8 MB, CPU-only, 5-line quickstart). A re-trained *transformer* v2 with a real 30k vocabulary is also in progress.
27
 
28
+ ## Architecture
 
 
 
29
 
30
+ - Custom Transformer encoder: **4 layers · 6 attention heads · 384-dim · mean pooling**
31
+ - **Parameters:** 3,299,584 (~3.3M)
32
+ - **Model size:** ~12.6 MB
33
+ - **Vocabulary:** ~164 tokens (auto-generated — the main limitation; fixed in v2's 30k vocab)
34
+ - **Max sequence length:** 128 tokens
35
 
36
+ ## Results
 
37
 
38
+ On its own STS-B evaluation (within the limits of the 164-token vocab):
 
 
39
 
40
+ | Metric | Score |
41
+ |--------|-------|
42
+ | Spearman | 0.677 |
43
+ | Pearson | 0.672 |
44
 
45
+ These numbers reflect the small-vocab setup and should not be compared directly to encoders
46
+ trained on a full vocabulary.
 
 
 
47
 
48
+ ## What this project is
 
 
49
 
50
+ TrynMini is a from-scratch study of how sentence embedding models work, built day by day:
51
+ tokenizer → transformer → distillation → static compression → calibration. v1 (this repo) is the
52
+ first working transformer stage. The line continues in the **static v2** models linked above,
53
+ which are the ones intended for real use.
54
 
55
+ ## License
 
 
56
 
57
+ Apache-2.0.