Update README with Enhanced RAG system instructions
Browse files
README.md
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: hi
|
3 |
+
license: mit
|
4 |
+
tags:
|
5 |
+
- hindi
|
6 |
+
- embeddings
|
7 |
+
- sentence-embeddings
|
8 |
+
- semantic-search
|
9 |
+
- text-similarity
|
10 |
+
datasets:
|
11 |
+
- custom
|
12 |
+
pipeline_tag: sentence-similarity
|
13 |
+
library_name: transformers
|
14 |
+
---
|
15 |
+
|
16 |
+
# Hindi Sentence Embeddings Model
|
17 |
+
|
18 |
+
This is a custom state-of-the-art sentence embedding model trained specifically for Hindi text. It leverages an advanced transformer architecture with specialized pooling strategies to create high-quality semantic representations of Hindi sentences.
|
19 |
+
|
20 |
+
## Features
|
21 |
+
|
22 |
+
- Specialized for Hindi language text
|
23 |
+
- Advanced transformer architecture with optimized attention mechanism
|
24 |
+
- Multiple pooling strategies for enhanced semantic representations
|
25 |
+
- Creates normalized vector representations for semantic similarity
|
26 |
+
- Supports semantic search and text similarity applications
|
27 |
+
|
28 |
+
## Usage
|
29 |
+
|
30 |
+
### Installation
|
31 |
+
|
32 |
+
```bash
|
33 |
+
pip install torch sentencepiece scikit-learn matplotlib
|
34 |
+
git lfs install
|
35 |
+
git clone https://huggingface.co/DeepMostInnovations/hindi-embedding-foundational-model
|
36 |
+
cd hindi-embedding-foundational-model
|
37 |
+
```
|
38 |
+
|
39 |
+
### Enhanced RAG System
|
40 |
+
|
41 |
+
This model now includes an enhanced RAG (Retrieval Augmented Generation) system that integrates Unsloth's optimized Llama-3.2-1B-Instruct model for question answering on top of Hindi document retrieval.
|
42 |
+
|
43 |
+
#### Setup and Installation
|
44 |
+
|
45 |
+
1. Install additional dependencies:
|
46 |
+
```bash
|
47 |
+
pip install unsloth transformers bitsandbytes accelerate langchain langchain-community faiss-cpu
|
48 |
+
```
|
49 |
+
|
50 |
+
2. Index your documents:
|
51 |
+
```bash
|
52 |
+
python hindi-rag-system.py --model_dir /path/to/your/model --tokenizer_dir /path/to/tokenizer --data_dir ./data --output_dir ./output --index
|
53 |
+
```
|
54 |
+
|
55 |
+
3. Run in QA mode with LLM:
|
56 |
+
```bash
|
57 |
+
python hindi-rag-system.py --model_dir /path/to/your/model --tokenizer_dir /path/to/tokenizer --output_dir ./output --interactive --qa
|
58 |
+
```
|
59 |
+
|
60 |
+
### Basic Embedding Usage
|
61 |
+
|
62 |
+
```python
|
63 |
+
from hindi_embeddings import HindiEmbedder
|
64 |
+
|
65 |
+
# Initialize the embedder
|
66 |
+
model = HindiEmbedder("path/to/hindi-embedding-foundational-model")
|
67 |
+
|
68 |
+
# Encode sentences to embeddings
|
69 |
+
sentences = [
|
70 |
+
"मुझे हिंदी भाषा बहुत पसंद है।",
|
71 |
+
"मैं हिंदी भाषा सीख रहा हूँ।"
|
72 |
+
]
|
73 |
+
embeddings = model.encode(sentences)
|
74 |
+
print(f"Embedding shape: {embeddings.shape}")
|
75 |
+
|
76 |
+
# Compute similarity between sentences
|
77 |
+
similarity = model.compute_similarity(sentences[0], sentences[1])
|
78 |
+
print(f"Similarity: {similarity:.4f}")
|
79 |
+
|
80 |
+
# Perform semantic search
|
81 |
+
query = "भारत की राजधानी"
|
82 |
+
documents = [
|
83 |
+
"दिल्ली भारत की राजधानी है।",
|
84 |
+
"मुंबई भारत का सबसे बड़ा शहर है।",
|
85 |
+
"हिमालय पर्वत भारत के उत्तर में स्थित है।"
|
86 |
+
]
|
87 |
+
results = model.search(query, documents)
|
88 |
+
for i, result in enumerate(results):
|
89 |
+
print(f"{i+1}. Score: {result['score']:.4f}")
|
90 |
+
print(f" Document: {result['document']}")
|
91 |
+
|
92 |
+
# Visualize embeddings
|
93 |
+
example_sentences = [
|
94 |
+
"मुझे हिंदी में पढ़ना बहुत पसंद है।",
|
95 |
+
"आज मौसम बहुत अच्छा है।",
|
96 |
+
"भारत एक विशाल देश है।"
|
97 |
+
]
|
98 |
+
model.visualize_embeddings(example_sentences)
|
99 |
+
```
|
100 |
+
|
101 |
+
## Model Details
|
102 |
+
|
103 |
+
This model uses an advanced transformer-based architecture with the following enhancements:
|
104 |
+
|
105 |
+
- Pre-layer normalization for stable training
|
106 |
+
- Specialized attention mechanism with relative positional encoding
|
107 |
+
- Multiple pooling strategies (weighted, mean, attention-based)
|
108 |
+
- L2-normalized vectors for cosine similarity
|
109 |
+
|
110 |
+
Technical specifications:
|
111 |
+
- Embedding dimension: 768
|
112 |
+
- Hidden dimension: 768
|
113 |
+
- Layers: 12
|
114 |
+
- Attention heads: 12
|
115 |
+
- Vocabulary size: 50,000
|
116 |
+
- Context length: 128 tokens
|
117 |
+
|
118 |
+
## Applications
|
119 |
+
|
120 |
+
- Semantic search and information retrieval
|
121 |
+
- Text clustering and categorization
|
122 |
+
- Recommendation systems
|
123 |
+
- Question answering
|
124 |
+
- Document similarity comparison
|
125 |
+
- Content-based filtering
|
126 |
+
- RAG systems for Hindi language content
|
127 |
+
|
128 |
+
## License
|
129 |
+
|
130 |
+
This model is released under the MIT License.
|
131 |
+
|
132 |
+
## Citation
|
133 |
+
|
134 |
+
If you use this model in your research or application, please cite us:
|
135 |
+
|
136 |
+
```
|
137 |
+
@misc{DeepMostInnovations2025hindi,
|
138 |
+
author = {DeepMost Innovations},
|
139 |
+
title = {Hindi Sentence Embeddings Model},
|
140 |
+
year = {2025},
|
141 |
+
publisher = {Hugging Face},
|
142 |
+
howpublished = {\url{https://huggingface.co/DeepMostInnovations/hindi-embedding-foundational-model}}
|
143 |
+
}
|
144 |
+
```
|