Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,22 +1,124 @@
|
|
| 1 |
---
|
| 2 |
-
|
|
|
|
| 3 |
tags:
|
| 4 |
-
-
|
| 5 |
-
-
|
|
|
|
|
|
|
| 6 |
- unsloth
|
| 7 |
-
-
|
| 8 |
-
- trl
|
| 9 |
license: apache-2.0
|
| 10 |
-
|
| 11 |
-
-
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
tags:
|
| 5 |
+
- sql
|
| 6 |
+
- text-to-sql
|
| 7 |
+
- daraz
|
| 8 |
+
- llama3
|
| 9 |
- unsloth
|
| 10 |
+
- ecommerce
|
|
|
|
| 11 |
license: apache-2.0
|
| 12 |
+
datasets:
|
| 13 |
+
- custom
|
| 14 |
+
base_model: unsloth/llama-3-8b-bnb-4bit
|
| 15 |
---
|
| 16 |
|
| 17 |
+
# drz-sql-llama3
|
| 18 |
+
|
| 19 |
+
This model is a fine-tuned version of Llama 3 (8B) for generating SQL queries specific to the Daraz e-commerce platform.
|
| 20 |
+
|
| 21 |
+
## Model Description
|
| 22 |
+
|
| 23 |
+
- **Base Model:** Llama 3 8B (4-bit quantized)
|
| 24 |
+
- **Fine-tuning Method:** LoRA (Low-Rank Adaptation)
|
| 25 |
+
- **Training Data:** 20 Daraz-specific SQL query examples
|
| 26 |
+
- **Use Case:** Converting natural language questions to SQL queries for Daraz analytics
|
| 27 |
+
|
| 28 |
+
## Training Details
|
| 29 |
+
|
| 30 |
+
- **Framework:** Unsloth
|
| 31 |
+
- **LoRA Rank:** 16
|
| 32 |
+
- **Training Steps:** 100
|
| 33 |
+
- **Batch Size:** 2
|
| 34 |
+
- **Gradient Accumulation:** 4
|
| 35 |
+
- **Learning Rate:** 0.0002
|
| 36 |
+
|
| 37 |
+
## Key Features
|
| 38 |
+
|
| 39 |
+
This model understands Daraz-specific:
|
| 40 |
+
- Table schemas (e.g., `daraz_cdm.dwd_drz_trd_core_df`, `daraz_cdm.dwd_drz_prd_sku_extension`)
|
| 41 |
+
- Business logic (Choice classification, KAM assignments, industry mapping)
|
| 42 |
+
- Query patterns (MAX_PT for partitions, DATEADD for date filtering)
|
| 43 |
+
- Metrics (GMV, L7/L30 calculations, order types)
|
| 44 |
+
|
| 45 |
+
## Usage
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
from unsloth import FastLanguageModel
|
| 49 |
+
|
| 50 |
+
# Load model
|
| 51 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 52 |
+
model_name = "Bilal326/drz-sql-llama3",
|
| 53 |
+
max_seq_length = 2048,
|
| 54 |
+
dtype = None,
|
| 55 |
+
load_in_4bit = True,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
FastLanguageModel.for_inference(model)
|
| 59 |
+
|
| 60 |
+
# Generate SQL
|
| 61 |
+
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
| 62 |
+
|
| 63 |
+
### Instruction:
|
| 64 |
+
{}
|
| 65 |
+
|
| 66 |
+
### Input:
|
| 67 |
+
{}
|
| 68 |
+
|
| 69 |
+
### Response:
|
| 70 |
+
{}"""
|
| 71 |
+
|
| 72 |
+
prompt = alpaca_prompt.format(
|
| 73 |
+
"Generate SQL for the following request:",
|
| 74 |
+
"Get total GMV for last 30 days in Pakistan",
|
| 75 |
+
""
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
|
| 79 |
+
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.5)
|
| 80 |
+
print(tokenizer.decode(outputs[0]))
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
## Example Queries
|
| 84 |
+
|
| 85 |
+
The model can handle:
|
| 86 |
+
- Simple aggregations: "Get total GMV and orders for last 30 days"
|
| 87 |
+
- Complex joins: "Get seller performance with KAM assignments"
|
| 88 |
+
- Time-based analysis: "Show monthly GMV trend by industry"
|
| 89 |
+
- Advanced logic: "Compare Choice vs Non-Choice GMV in Crossborder"
|
| 90 |
+
|
| 91 |
+
## Limitations
|
| 92 |
+
|
| 93 |
+
- Trained specifically for Daraz schema and business logic
|
| 94 |
+
- May not generalize to other SQL dialects or schemas
|
| 95 |
+
- Requires Daraz-specific tables to be available
|
| 96 |
+
|
| 97 |
+
## Training Dataset
|
| 98 |
+
|
| 99 |
+
Custom dataset of 20 SQL query examples covering:
|
| 100 |
+
- Revenue and GMV analysis
|
| 101 |
+
- Product performance metrics
|
| 102 |
+
- Seller segmentation
|
| 103 |
+
- Category and brand analysis
|
| 104 |
+
- Time-based trends
|
| 105 |
+
|
| 106 |
+
## Citation
|
| 107 |
+
|
| 108 |
+
If you use this model, please cite:
|
| 109 |
|
| 110 |
+
```
|
| 111 |
+
@misc{drz-sql-llama3,
|
| 112 |
+
author = {Bilal326},
|
| 113 |
+
title = {drz-sql-llama3: Daraz SQL Generation Model},
|
| 114 |
+
year = {2025},
|
| 115 |
+
publisher = {HuggingFace},
|
| 116 |
+
url = {https://huggingface.co/Bilal326/drz-sql-llama3}
|
| 117 |
+
}
|
| 118 |
+
```
|
| 119 |
|
| 120 |
+
## Acknowledgments
|
| 121 |
|
| 122 |
+
- Built with [Unsloth](https://github.com/unslothai/unsloth)
|
| 123 |
+
- Based on Meta's Llama 3
|
| 124 |
+
- Fine-tuned for Daraz e-commerce analytics
|