-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_github.py
More file actions
317 lines (256 loc) · 7.72 KB
/
setup_github.py
File metadata and controls
317 lines (256 loc) · 7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/usr/bin/env python3
"""
Setup script to prepare the repository for GitHub and Kaggle
"""
import os
import shutil
import json
from pathlib import Path
def create_gitignore():
"""Create a comprehensive .gitignore file"""
gitignore_content = """
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# Virtual environments
venv/
env/
ENV/
# IDE
.vscode/
.idea/
*.swp
*.swo
# Jupyter Notebook
.ipynb_checkpoints
# Data and Models (too large for GitHub)
data/
models/
processed_data/
checkpoints/
*.pt
*.pth
*.parquet
*.csv
*.json.gz
# Logs
logs/
training_logs/
*.log
# API Keys (security)
kaggle.json
.env
config/secrets.py
# OS
.DS_Store
Thumbs.db
# Temporary files
*.tmp
*.temp
debug_*.py
test_*.py
check_*.py
fix_*.py
validate_*.py
"""
with open('.gitignore', 'w') as f:
f.write(gitignore_content.strip())
print("✅ Created comprehensive .gitignore")
def create_requirements_txt():
"""Create requirements.txt for easy installation"""
requirements = """
torch>=2.0.0
transformers>=4.30.0
datasets>=2.12.0
scikit-learn>=1.3.0
umap-learn>=0.5.3
hdbscan>=0.8.29
structlog>=23.1.0
fastapi>=0.100.0
uvicorn>=0.22.0
google-generativeai>=0.3.0
nltk>=3.8
pandas>=2.0.0
numpy>=1.24.0
python-multipart>=0.0.6
pydantic>=2.0.0
pydantic-settings>=2.0.0
"""
with open('requirements.txt', 'w') as f:
f.write(requirements.strip())
print("✅ Created requirements.txt")
def create_readme():
"""Create a comprehensive README for GitHub"""
readme_content = """
# 🚀 CADENCE: Enhanced E-commerce Autocomplete System
A production-ready implementation of the CADENCE (Context-Aware Deep E-commerce Neural Completion Engine) model for intelligent product search and autocomplete.
## 🌟 Features
- **Real Amazon Data**: Trained on Amazon QAC and Products datasets
- **Enhanced Architecture**: Multi-task learning with attention mechanisms
- **E-commerce Optimized**: Product-specific autocomplete suggestions
- **Personalization Layer**: Re-ranking based on user behavior
- **Production Ready**: FastAPI backend with React frontend
- **GPU Accelerated**: Optimized for Kaggle/Colab training
## 🏗️ Architecture
```
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ User Query │───▶│ CADENCE Model │───▶│ Autocomplete │
└─────────────────┘ │ (Query LM + │ │ Suggestions │
│ Catalog LM) │ └─────────────────┘
└──────────────────┘ │
│ ▼
┌──────────────────┐ ┌─────────────────┐
│ Personalization │───▶│ Re-ranked │
│ Layer │ │ Results │
└──────────────────┘ └─────────────────┘
```
## 🚀 Quick Start
### Option 1: Train on Kaggle (Recommended)
1. **Push to GitHub**:
```bash
git add .
git commit -m "Add CADENCE implementation"
git push origin main
```
2. **Create Kaggle Dataset**:
- Go to [Kaggle Datasets](https://www.kaggle.com/datasets)
- Click "New Dataset" → "GitHub"
- Enter your repository URL
- Set dataset name: `flipkart-grid-cadence`
3. **Run Training Notebook**:
- Upload `kaggle_training_notebook.ipynb` to Kaggle
- Enable GPU (T4 x2) and Internet
- Add your GitHub dataset
- Run all cells
4. **Download Results**:
- Download `trained_cadence_models.zip`
- Extract to your local `models/` directory
### Option 2: Local Training
```bash
# Install dependencies
pip install -r requirements.txt
# Train models
python train_enhanced_model.py
# Start backend
python api/main.py
# Start frontend (in another terminal)
cd frontend && npm start
```
## 📊 Model Architecture
- **Embedding Dimension**: 512
- **Hidden Layers**: [3008, 2496, 2000, 1536]
- **Attention Heads**: 8
- **Multi-task Learning**: Query completion + Intent classification + Category prediction
- **Memory Networks**: GRU-based with external memory tapes
## 🎯 Performance
- **Training Data**: 100K Amazon queries + 25K products
- **Vocabulary Size**: ~50K tokens
- **GPU Training Time**: ~30 minutes on T4 x2
- **Inference Speed**: <50ms per query
## 📁 Project Structure
```
├── api/ # FastAPI backend
├── core/ # Core model implementations
├── frontend/ # React frontend
├── training/ # Training scripts
├── config/ # Configuration
├── data_generation/ # Synthetic data generation
└── kaggle_training_notebook.ipynb # Kaggle training notebook
```
## 🔧 Configuration
Update `config/settings.py`:
- Set your Gemini API key for synthetic data generation
- Adjust model parameters as needed
- Configure data paths
## 🧪 Testing
```bash
# Run validation
python validate_real_implementation.py
# Check data status
python check_data_status.py
# Test API endpoints
curl http://localhost:8000/autocomplete?query=laptop
```
## 📈 Results
The enhanced CADENCE model achieves:
- **Relevance**: High-quality product-specific suggestions
- **Speed**: Real-time autocomplete performance
- **Scalability**: Handles large product catalogs
- **Personalization**: Context-aware re-ranking
## 🤝 Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Test thoroughly
5. Submit a pull request
## 📄 License
This project is licensed under the MIT License.
## 🙏 Acknowledgments
- Amazon for the QAC and Products datasets
- Hugging Face for the transformers library
- The original CADENCE paper authors
"""
with open('README.md', 'w') as f:
f.write(readme_content.strip())
print("✅ Created comprehensive README.md")
def clean_repository():
"""Clean up temporary and debug files"""
files_to_remove = [
'debug_categories.py',
'check_data_status.py',
'check_model_architecture.py',
'fix_training_file.py',
'validate_real_implementation.py',
'kaggle.json' # Remove API keys for security
]
dirs_to_remove = [
'checkpoints',
'processed_data',
'logs',
'training_logs'
]
for file in files_to_remove:
if os.path.exists(file):
os.remove(file)
print(f"🗑️ Removed {file}")
for dir_name in dirs_to_remove:
if os.path.exists(dir_name):
shutil.rmtree(dir_name)
print(f"🗑️ Removed directory {dir_name}")
def main():
"""Main setup function"""
print("🚀 Setting up repository for GitHub and Kaggle...")
create_gitignore()
create_requirements_txt()
create_readme()
clean_repository()
print("\n✅ Repository setup complete!")
print("\n📋 Next steps:")
print("1. Review the generated files")
print("2. Commit and push to GitHub:")
print(" git add .")
print(" git commit -m 'Prepare for Kaggle training'")
print(" git push origin main")
print("3. Create Kaggle dataset from your GitHub repo")
print("4. Upload kaggle_training_notebook.ipynb to Kaggle")
print("5. Run training with GPU acceleration!")
if __name__ == "__main__":
main()