File size: 3,527 Bytes
bc8830b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc074eb
 
9954e86
 
 
 
 
bc074eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9954e86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
tags:
- text2api
- t5
- pytorch
- transformers
- machine-learning
- natural-language-processing
- api
license: apache-2.0
library_name: transformers
datasets:
- custom-dataset
language: en
finetuned_from: t5-small
model_type: t5
---

# **Text-to-API Command Model**

This repository contains a fine-tuned T5-Small model trained to convert natural language commands into 
standardized API commands. The model is designed for use cases where human-written instructions need
to be translated into machine-readable commands for home automation systems or other API-driven platforms.

---

## **Model Details**

- **Base Model:** T5-Small
- **Task:** Text-to-API command generation
- **Dataset:** A custom dataset of natural language commands paired with their corresponding API commands.
- **Training Framework:** PyTorch and Hugging Face Transformers
- **Input Format:** Natural language text, such as "Turn off the kitchen lights."
- **Output Format:** API command, such as `turn_off.kitchen_lights`.

---

## **Training Details**

- **Dataset Details**:The model was trained on a dataset of command pairs. Each pair consisted of:
  - A natural language input (e.g., "Please lock the front door.")
  - A corresponding API-style output (e.g., `lock.front_door`).
  - The dataset was split into:
    - **90% Training Data**
    - **10% Validation Data**

- **Model Configuration**
  - **Pre-trained Model:** T5-Small
  - **Maximum Input and Output Sequence Lengths:** 128 tokens
  - **Learning Rate:** 5e-5
  - **Batch Size:** 16
- **Hardware:** The model was fine-tuned using a CUDA-enabled GPU.

---

## **Evaluation**

The model was evaluated using validation data during training. Metrics used for evaluation include:

- **Loss:** Averaged across training and validation batches.
- **Qualitative Analysis:** Demonstrates strong alignment between input commands and output API commands.

---

## **Intended Use**

This model is designed for:

- Translating user-friendly commands into machine-readable API instructions.
- Home automation systems, IoT devices, and other API-driven platforms requiring natural language input.

---

## **Limitations**

- The model may not generalize well to commands outside the scope of its training data.
- Ambiguous or overly complex inputs may produce unexpected outputs.
- Fine-tuning on domain-specific data is recommended for specialized use cases.


## **How to Use the Model**

### **Loading the Model**

### **Step 1: Install Required Libraries**

To use this model, first install the required libraries:

```bash
pip install transformers torch
```

### **Step 2: Load and Use the Model**

You can use the following Python code to generate API commands from natural language inputs:

```python
from transformers import T5Tokenizer, T5ForConditionalGeneration

# Load the tokenizer and model
tokenizer = T5Tokenizer.from_pretrained('vincenthuynh/SLM_CS576')
model = T5ForConditionalGeneration.from_pretrained('vincenthuynh/SLM_CS576')

# Function to generate API commands
def generate_api_command(model, tokenizer, text, device='cpu', max_length=50):
    input_ids = tokenizer.encode(text, return_tensors='pt').to(device)
    with torch.no_grad():
        generated_ids = model.generate(input_ids=input_ids, max_length=max_length, num_beams=5, early_stopping=True)
    return tokenizer.decode(generated_ids[0], skip_special_tokens=True)

# Example usage
command = "Please turn off the kitchen lights"
api_command = generate_api_command(model, tokenizer, command)
print(api_command)