ankitkushwaha90 commited on
Commit
2bd340f
·
verified ·
1 Parent(s): d459458

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +141 -74
README.md CHANGED
@@ -12,88 +12,91 @@ library_name: adapter-transformers
12
  tags:
13
  - code
14
  ---
15
-
16
- T5 Command Description Generator
17
- This project fine-tunes a T5 model (t5-small) to generate descriptions of terminal commands based on prompts in the format "Describe the command: {name} in {source}". The model is trained on a dataset (all_commands.csv) containing command names, descriptions, and sources (e.g., cmd, linux, macos, vbscript). After fine-tuning, the model can generate descriptions for commands, such as "List information about file(s)" for ls in linux.
18
- Table of Contents
19
-
20
- Overview
21
- Dataset
22
- Requirements
23
- Setup
24
- Fine-Tuning the Model
25
- Using the Model
26
- Example Output
27
- Troubleshooting
28
- Future Improvements
29
-
30
- Overview
31
- The T5 (Text-to-Text Transfer Transformer) model is fine-tuned to map prompts like "Describe the command: ls in linux" to descriptions like "List information about file(s)". The dataset used for training is all_commands.csv, which includes commands from various environments (cmd, linux, macos, vbscript). The fine-tuned model is saved to ./new_cmd_model and can be used to generate command descriptions interactively or programmatically.
32
- Dataset
33
- The dataset (all_commands.csv) contains the following columns:
34
-
35
- name: The command name (e.g., ls, dir, chmod, MsgBox).
36
- description: A brief description of what the command does (e.g., "List information about file(s)").
37
- source: The environment the command belongs to (cmd, linux, macos, vbscript).
38
 
39
  Example entries:
 
40
  name,description,source
41
  ls,List information about file(s),linux
42
  dir,Display a list of files and folders,cmd
43
  chmod,Change access permissions,macos
44
  MsgBox,Display a dialogue box message,vbscript
 
45
 
46
  The dataset is split into 80% training and 20% validation sets for fine-tuning.
47
- Requirements
48
-
49
- Python 3.8+
50
- Libraries:
51
- transformers
52
- torch
53
- sentencepiece
54
- datasets
55
-
56
 
57
- CUDA-enabled GPU (optional, for faster training; fp16=True in the script enables mixed precision if available)
58
- Dataset file: all_commands.csv (place in the project directory)
 
 
 
 
 
 
 
59
 
60
  Install dependencies:
 
61
  pip install transformers torch sentencepiece datasets
62
-
63
- Setup
64
-
65
- Activate the Environment:Ensure you're in a Python environment with the required libraries. For example, using Conda:
66
- conda activate safetensor_new
67
-
68
-
69
- Prepare the Dataset:Place all_commands.csv in the project directory (e.g., C:\app\dataset).
70
-
71
- Directory Structure:
72
- C:\app\dataset\
73
- ├── all_commands.csv
74
- ├── new_cmd_model\ (created after fine-tuning)
75
- └── fine_tune_script.py
76
-
77
-
78
-
79
- Fine-Tuning the Model
80
- The fine-tuning script (fine_tune_script.py) trains a t5-small model on the all_commands.csv dataset to generate command descriptions.
81
- Script Overview
82
-
83
- Model: t5-small (can be upgraded to t5-base for better performance).
84
- Input Prompt: "Describe the command: {name} in {source}" (e.g., "Describe the command: ls in linux").
85
- Output: The command’s description (e.g., "List information about file(s)").
86
- Training Parameters:
87
- Epochs: 3
88
- Learning rate: 5e-5
89
- Batch size: 8
90
- Output directory: ./new_cmd_model
91
- Mixed precision training: Enabled if CUDA is available
92
-
93
-
94
-
95
- Running the Script
96
- Save the following script as fine_tune_script.py and run it:
 
 
97
  from transformers import T5ForConditionalGeneration, T5Tokenizer, Trainer, TrainingArguments
98
  from datasets import load_dataset
99
  import torch
@@ -151,15 +154,21 @@ trainer.train()
151
  model.save_pretrained("./new_cmd_model")
152
  tokenizer.save_pretrained("./new_cmd_model")
153
  print("Fine-tuning complete. Model saved to './new_cmd_model'.")
 
154
 
155
  Run the script:
 
156
  python fine_tune_script.py
 
 
 
157
 
158
- This will train the model and save it to ./new_cmd_model.
159
- Using the Model
160
  After fine-tuning, you can use the model to generate command descriptions with prompts like "Describe the command: {name} in {source}". Below is a script to load and use the model interactively or programmatically.
161
- Usage Script
162
- Save the following as use_t5_command_description.py:
 
 
163
  import os
164
  from transformers import T5ForConditionalGeneration, T5Tokenizer
165
  import torch
@@ -239,12 +248,16 @@ while True:
239
  print("-" * 50)
240
 
241
  print("Exiting interactive mode.")
 
242
 
243
  Run the script:
 
244
  python use_t5_command_description.py
 
245
 
246
- Example Output
247
  After fine-tuning and running the usage script, you should see output like:
 
248
  [2025-09-04 11:50:00] Model and tokenizer loaded successfully.
249
 
250
  Generated Descriptions:
@@ -259,4 +272,58 @@ Description: List information about file(s)
259
  Command: dir (cmd)
260
  Description: Display a list of files and folders
261
  --------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  [2025-09-04
 
12
  tags:
13
  - code
14
  ---
15
+ # T5 Command Description Generator
16
+
17
+ This project fine-tunes a T5 model (`t5-small`) to generate descriptions of terminal commands based on prompts in the format "Describe the command: {name} in {source}". The model is trained on a dataset (`all_commands.csv`) containing command names, descriptions, and sources (e.g., `cmd`, `linux`, `macos`, `vbscript`). After fine-tuning, the model can generate descriptions for commands, such as "List information about file(s)" for `ls` in `linux`.
18
+
19
+ ## Table of Contents
20
+ - [Overview](#overview)
21
+ - [Dataset](#dataset)
22
+ - [Requirements](#requirements)
23
+ - [Setup](#setup)
24
+ - [Fine-Tuning the Model](#fine-tuning-the-model)
25
+ - [Using the Model](#using-the-model)
26
+ - [Example Output](#example-output)
27
+ - [Troubleshooting](#troubleshooting)
28
+ - [Future Improvements](#future-improvements)
29
+
30
+ ## Overview
31
+ The T5 (Text-to-Text Transfer Transformer) model is fine-tuned to map prompts like "Describe the command: ls in linux" to descriptions like "List information about file(s)". The dataset used for training is `all_commands.csv`, which includes commands from various environments (`cmd`, `linux`, `macos`, `vbscript`). The fine-tuned model is saved to `./new_cmd_model` and can be used to generate command descriptions interactively or programmatically.
32
+
33
+ ## Dataset
34
+ The dataset (`all_commands.csv`) contains the following columns:
35
+ - `name`: The command name (e.g., `ls`, `dir`, `chmod`, `MsgBox`).
36
+ - `description`: A brief description of what the command does (e.g., "List information about file(s)").
37
+ - `source`: The environment the command belongs to (`cmd`, `linux`, `macos`, `vbscript`).
38
 
39
  Example entries:
40
+ ```
41
  name,description,source
42
  ls,List information about file(s),linux
43
  dir,Display a list of files and folders,cmd
44
  chmod,Change access permissions,macos
45
  MsgBox,Display a dialogue box message,vbscript
46
+ ```
47
 
48
  The dataset is split into 80% training and 20% validation sets for fine-tuning.
 
 
 
 
 
 
 
 
 
49
 
50
+ ## Requirements
51
+ - Python 3.8+
52
+ - Libraries:
53
+ - `transformers`
54
+ - `torch`
55
+ - `sentencepiece`
56
+ - `datasets`
57
+ - CUDA-enabled GPU (optional, for faster training; `fp16=True` in the script enables mixed precision if available)
58
+ - Dataset file: `all_commands.csv` (place in the project directory)
59
 
60
  Install dependencies:
61
+ ```bash
62
  pip install transformers torch sentencepiece datasets
63
+ ```
64
+
65
+ ## Setup
66
+ 1. **Activate the Environment**:
67
+ Ensure you're in a Python environment with the required libraries. For example, using Conda:
68
+ ```bash
69
+ conda activate safetensor_new
70
+ ```
71
+
72
+ 2. **Prepare the Dataset**:
73
+ Place `all_commands.csv` in the project directory (e.g., `C:\app\dataset`).
74
+
75
+ 3. **Directory Structure**:
76
+ ```
77
+ C:\app\dataset\
78
+ ├── all_commands.csv
79
+ ├── new_cmd_model\ (created after fine-tuning)
80
+ └── fine_tune_script.py
81
+ ```
82
+
83
+ ## Fine-Tuning the Model
84
+ The fine-tuning script (`fine_tune_script.py`) trains a `t5-small` model on the `all_commands.csv` dataset to generate command descriptions.
85
+
86
+ ### Script Overview
87
+ - **Model**: `t5-small` (can be upgraded to `t5-base` for better performance).
88
+ - **Input Prompt**: "Describe the command: {name} in {source}" (e.g., "Describe the command: ls in linux").
89
+ - **Output**: The command’s description (e.g., "List information about file(s)").
90
+ - **Training Parameters**:
91
+ - Epochs: 3
92
+ - Learning rate: 5e-5
93
+ - Batch size: 8
94
+ - Output directory: `./new_cmd_model`
95
+ - Mixed precision training: Enabled if CUDA is available
96
+
97
+ ### Running the Script
98
+ Save the following script as `fine_tune_script.py` and run it:
99
+ ```python
100
  from transformers import T5ForConditionalGeneration, T5Tokenizer, Trainer, TrainingArguments
101
  from datasets import load_dataset
102
  import torch
 
154
  model.save_pretrained("./new_cmd_model")
155
  tokenizer.save_pretrained("./new_cmd_model")
156
  print("Fine-tuning complete. Model saved to './new_cmd_model'.")
157
+ ```
158
 
159
  Run the script:
160
+ ```bash
161
  python fine_tune_script.py
162
+ ```
163
+
164
+ This will train the model and save it to `./new_cmd_model`.
165
 
166
+ ## Using the Model
 
167
  After fine-tuning, you can use the model to generate command descriptions with prompts like "Describe the command: {name} in {source}". Below is a script to load and use the model interactively or programmatically.
168
+
169
+ ### Usage Script
170
+ Save the following as `use_t5_command_description.py`:
171
+ ```python
172
  import os
173
  from transformers import T5ForConditionalGeneration, T5Tokenizer
174
  import torch
 
248
  print("-" * 50)
249
 
250
  print("Exiting interactive mode.")
251
+ ```
252
 
253
  Run the script:
254
+ ```bash
255
  python use_t5_command_description.py
256
+ ```
257
 
258
+ ## Example Output
259
  After fine-tuning and running the usage script, you should see output like:
260
+ ```
261
  [2025-09-04 11:50:00] Model and tokenizer loaded successfully.
262
 
263
  Generated Descriptions:
 
272
  Command: dir (cmd)
273
  Description: Display a list of files and folders
274
  --------------------------------------------------
275
+ [2025-09-04 11:50:03] Input prompt: Describe the command: chmod in macos
276
+ [2025-09-04 11:50:03] Using device: cuda
277
+ Command: chmod (macos)
278
+ Description: Change access permissions
279
+ --------------------------------------------------
280
+ [2025-09-04 11:50:04] Input prompt: Describe the command: MsgBox in vbscript
281
+ [2025-09-04 11:50:04] Using device: cuda
282
+ Command: MsgBox (vbscript)
283
+ Description: Display a dialogue box message
284
+ --------------------------------------------------
285
+
286
+ Interactive Mode: Enter a command and source to get its description.
287
+ Valid sources: cmd, linux, macos, vbscript
288
+ Type 'exit' to quit.
289
+
290
+ Enter command name (or 'exit' to quit): ping
291
+ Enter source (e.g., cmd, linux, macos, vbscript): linux
292
+ [2025-09-04 11:50:05] Input prompt: Describe the command: ping in linux
293
+ [2025-09-04 11:50:05] Using device: cuda
294
+ Command: ping (linux)
295
+ Description: Test a network connection
296
+ --------------------------------------------------
297
+ Enter command name (or 'exit' to quit): exit
298
+ Exiting interactive mode.
299
+ ```
300
+
301
+ ## Troubleshooting
302
+ - **Empty Descriptions**:
303
+ - Ensure `all_commands.csv` has valid entries with no missing descriptions.
304
+ - Increase `num_train_epochs` to 5–10 or use `t5-base` for better performance.
305
+ - Check training logs in `./new_cmd_model` for high loss values.
306
+ - **Model Loading Issues**:
307
+ - Verify the model saved correctly in `./new_cmd_model`.
308
+ - Try loading a checkpoint (e.g., `./new_cmd_model/checkpoint-XXX`) if issues persist.
309
+ - **Environment Errors**:
310
+ - Ensure dependencies are installed: `pip install transformers torch sentencepiece datasets`.
311
+ - For CUDA errors, ensure your GPU drivers are up-to-date or set `fp16=False` in the training script.
312
+ - **Deprecation Warning**:
313
+ - The script uses `evaluation_strategy`, which is deprecated. Update to `eval_strategy` in newer `transformers` versions:
314
+ ```python
315
+ training_args = TrainingArguments(
316
+ output_dir="./new_cmd_model",
317
+ eval_strategy="epoch",
318
+ ...
319
+ )
320
+ ```
321
+
322
+ ## Future Improvements
323
+ - **Augment Dataset**: Add more command descriptions or variations to improve generalization.
324
+ - **Use Larger Model**: Switch to `t5-base` for better accuracy (update `model_name` and retrain).
325
+ - **Extend Task**: Modify to generate commands from task descriptions (e.g., "List files in linux" → `ls`) by retraining with swapped inputs/outputs.
326
+ - **Command Execution**: Add functionality to execute generated commands (requires careful validation for security).
327
+
328
+ For questions about xAI’s API, visit [https://x.ai/api](https://x.ai/api).
329
  [2025-09-04