|
--- |
|
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) |
|
|
|
|