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.
-
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.
The model was evaluated using validation data during training. Metrics used for evaluation include:
You can use the following Python code to generate API commands from natural language inputs:
1from transformers import T5Tokenizer, T5ForConditionalGeneration
2
3# Load the tokenizer and model
4tokenizer = T5Tokenizer.from_pretrained('vincenthuynh/SLM_CS576')
5model = T5ForConditionalGeneration.from_pretrained('vincenthuynh/SLM_CS576')
6
7# Function to generate API commands
8def generate_api_command(model, tokenizer, text, device='cpu', max_length=50):
9 input_ids = tokenizer.encode(text, return_tensors='pt').to(device)
10 with torch.no_grad():
11 generated_ids = model.generate(input_ids=input_ids, max_length=max_length, num_beams=5, early_stopping=True)
12 return tokenizer.decode(generated_ids[0], skip_special_tokens=True)
13
14# Example usage
15command = "Please turn off the kitchen lights"
16api_command = generate_api_command(model, tokenizer, command)
17print(api_command)
18