Update README.md
Browse files
README.md
CHANGED
|
@@ -44,41 +44,81 @@ This model is designed for **customer support automation in the telecom industry
|
|
| 44 |
## How to Get Started with the Model
|
| 45 |
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
import torch
|
| 48 |
from unsloth import FastLanguageModel
|
| 49 |
from transformers import AutoTokenizer
|
|
|
|
| 50 |
|
| 51 |
-
|
|
|
|
| 52 |
model_path = "moo100/DeepSeek-R1-telecom-chatbot"
|
|
|
|
| 53 |
|
| 54 |
-
|
|
|
|
| 55 |
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 56 |
model_path,
|
| 57 |
max_seq_length=1024, # Ensures compatibility with training length
|
| 58 |
dtype=None # Uses default precision
|
| 59 |
)
|
|
|
|
| 60 |
|
| 61 |
-
|
|
|
|
| 62 |
model = FastLanguageModel.for_inference(model)
|
|
|
|
| 63 |
|
| 64 |
-
|
|
|
|
| 65 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 66 |
model.to(device)
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
Do NOT role-play as a customer service agent. Only answer the user's query."""
|
|
|
|
| 71 |
|
| 72 |
-
|
|
|
|
| 73 |
user_input = "What are the benefits of 5G?"
|
|
|
|
| 74 |
|
| 75 |
-
|
|
|
|
| 76 |
full_prompt = f"{system_instruction}\n\nUser: {user_input}\nAssistant:"
|
|
|
|
| 77 |
|
| 78 |
-
|
|
|
|
| 79 |
inputs = tokenizer(full_prompt, return_tensors="pt").to(device)
|
|
|
|
| 80 |
|
| 81 |
-
|
|
|
|
| 82 |
outputs = model.generate(
|
| 83 |
input_ids=inputs.input_ids, # Encoded input tokens
|
| 84 |
attention_mask=inputs.attention_mask, # Mask for input length
|
|
@@ -88,12 +128,17 @@ outputs = model.generate(
|
|
| 88 |
top_k=50, # Samples from top 50 probable words
|
| 89 |
eos_token_id=tokenizer.eos_token_id, # Stops at end-of-sentence token
|
| 90 |
)
|
|
|
|
| 91 |
|
| 92 |
-
|
|
|
|
| 93 |
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True)
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
|
|
@@ -116,3 +161,24 @@ talkmap/telecom-conversation-corpus
|
|
| 116 |
|
| 117 |
Below are the training metrics recorded during fine-tuning:
|
| 118 |
https://drive.google.com/file/d/1-SOfG8K3Qt2WSEuyj3kFhGYOYMB5Gk2r/view?usp=sharing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
## How to Get Started with the Model
|
| 45 |
|
| 46 |
|
| 47 |
+
Here is the full **markdown-formatted content** for your **Hugging Face model card**:
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
```md
|
| 52 |
+
# DeepSeek-R1-Telecom-Chatbot
|
| 53 |
+
|
| 54 |
+
## Model Description
|
| 55 |
+
|
| 56 |
+
This is a fine-tuned version of **DeepSeek-R1-Distill-Llama-8B**, optimized for **telecom-related queries**. The model has been fine-tuned to provide **concise and factual answers**, ensuring that it does **not role-play as a customer service agent**.
|
| 57 |
+
|
| 58 |
+
- **Developed by**: Mohamed Abdulaziz
|
| 59 |
+
- **Funded by (optional)**: Self-funded
|
| 60 |
+
- **Model type**: Fine-tuned DeepSeek-R1-Distill-Llama-8B
|
| 61 |
+
- **License**: MIT License
|
| 62 |
+
|
| 63 |
+
---
|
| 64 |
+
|
| 65 |
+
## 📌 How to Use the Model
|
| 66 |
+
|
| 67 |
+
### **1️⃣ Import necessary libraries**
|
| 68 |
+
```python
|
| 69 |
import torch
|
| 70 |
from unsloth import FastLanguageModel
|
| 71 |
from transformers import AutoTokenizer
|
| 72 |
+
```
|
| 73 |
|
| 74 |
+
### **2️⃣ Define model path (Modify if using a different source)**
|
| 75 |
+
```python
|
| 76 |
model_path = "moo100/DeepSeek-R1-telecom-chatbot"
|
| 77 |
+
```
|
| 78 |
|
| 79 |
+
### **3️⃣ Load the model and tokenizer**
|
| 80 |
+
```python
|
| 81 |
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 82 |
model_path,
|
| 83 |
max_seq_length=1024, # Ensures compatibility with training length
|
| 84 |
dtype=None # Uses default precision
|
| 85 |
)
|
| 86 |
+
```
|
| 87 |
|
| 88 |
+
### **4️⃣ Optimize model for fast inference with Unsloth**
|
| 89 |
+
```python
|
| 90 |
model = FastLanguageModel.for_inference(model)
|
| 91 |
+
```
|
| 92 |
|
| 93 |
+
### **5️⃣ Move model to GPU if available, otherwise use CPU**
|
| 94 |
+
```python
|
| 95 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 96 |
model.to(device)
|
| 97 |
+
```
|
| 98 |
|
| 99 |
+
### **6️⃣ Define system instruction to guide model responses**
|
| 100 |
+
```python
|
| 101 |
+
system_instruction = """You are an AI assistant. Answer user questions concisely and factually.
|
| 102 |
Do NOT role-play as a customer service agent. Only answer the user's query."""
|
| 103 |
+
```
|
| 104 |
|
| 105 |
+
### **7️⃣ Define user input (Replace with any query)**
|
| 106 |
+
```python
|
| 107 |
user_input = "What are the benefits of 5G?"
|
| 108 |
+
```
|
| 109 |
|
| 110 |
+
### **8️⃣ Construct full prompt with instructions and user query**
|
| 111 |
+
```python
|
| 112 |
full_prompt = f"{system_instruction}\n\nUser: {user_input}\nAssistant:"
|
| 113 |
+
```
|
| 114 |
|
| 115 |
+
### **9️⃣ Tokenize input prompt**
|
| 116 |
+
```python
|
| 117 |
inputs = tokenizer(full_prompt, return_tensors="pt").to(device)
|
| 118 |
+
```
|
| 119 |
|
| 120 |
+
### **🔟 Generate model response with controlled stopping criteria**
|
| 121 |
+
```python
|
| 122 |
outputs = model.generate(
|
| 123 |
input_ids=inputs.input_ids, # Encoded input tokens
|
| 124 |
attention_mask=inputs.attention_mask, # Mask for input length
|
|
|
|
| 128 |
top_k=50, # Samples from top 50 probable words
|
| 129 |
eos_token_id=tokenizer.eos_token_id, # Stops at end-of-sentence token
|
| 130 |
)
|
| 131 |
+
```
|
| 132 |
|
| 133 |
+
### **1️⃣1️⃣ Decode and extract only the newly generated response**
|
| 134 |
+
```python
|
| 135 |
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True)
|
| 136 |
+
```
|
| 137 |
|
| 138 |
+
### **1️⃣2️⃣ Print the AI-generated response**
|
| 139 |
+
```python
|
| 140 |
+
print(response.strip())
|
| 141 |
+
```
|
| 142 |
|
| 143 |
|
| 144 |
|
|
|
|
| 161 |
|
| 162 |
Below are the training metrics recorded during fine-tuning:
|
| 163 |
https://drive.google.com/file/d/1-SOfG8K3Qt2WSEuyj3kFhGYOYMB5Gk2r/view?usp=sharing
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
# Evaluation
|
| 167 |
+
|
| 168 |
+
## Methodology
|
| 169 |
+
|
| 170 |
+
The chatbot was evaluated using Meta-Llama-3.3-70B-Instruct, assessing relevance, correctness, and fluency of its responses.
|
| 171 |
+
|
| 172 |
+
## Results
|
| 173 |
+
|
| 174 |
+
Meta-Llama-3.3-70B-Instruct Evaluation:
|
| 175 |
+
|
| 176 |
+
Relevance: 9/10
|
| 177 |
+
The response is highly relevant to the user’s query about 5G benefits, providing a concise and informative summary.
|
| 178 |
+
|
| 179 |
+
Correctness: 10/10
|
| 180 |
+
The response is factually accurate, highlighting key advantages such as faster data speeds, lower latency, increased capacity, and broader device compatibility.
|
| 181 |
+
|
| 182 |
+
Fluency: 9/10
|
| 183 |
+
The response is well-structured, grammatically sound, and easy to understand. Minor refinements could further enhance readability.
|
| 184 |
+
|