Updated Readme.md
Browse files
README.md
CHANGED
@@ -16,4 +16,149 @@ tags:
|
|
16 |
- english-to-bash
|
17 |
- nl2bash
|
18 |
- nl2cmd
|
19 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
- english-to-bash
|
17 |
- nl2bash
|
18 |
- nl2cmd
|
19 |
+
---
|
20 |
+
|
21 |
+
# NL to Bash Translator
|
22 |
+
|
23 |
+
This model is a fine-tuned version of `codet5p-220m-bimodal` for translating natural language (NL) commands into Bash code. It simplifies command-line usage by allowing users to describe desired tasks in plain English and generates corresponding Bash commands.
|
24 |
+
|
25 |
+
## Model Overview
|
26 |
+
|
27 |
+
- **Task:** Natural Language to Bash Code Translation
|
28 |
+
- **Base Model:** codet5p-220m-bimodal
|
29 |
+
- **Training Focus:** Accurate command translation and efficient execution
|
30 |
+
|
31 |
+
## Dataset Description
|
32 |
+
|
33 |
+
The dataset used for training consists of natural language and Bash code pairs:
|
34 |
+
|
35 |
+
- **Total Samples:** 19,658
|
36 |
+
- **Training Set:** 19,658 samples
|
37 |
+
- **Validation Set:** 2,457 samples
|
38 |
+
- **Test Set:** 2,458 samples
|
39 |
+
|
40 |
+
Each sample contains:
|
41 |
+
- Natural language command (`nl_command`)
|
42 |
+
- Corresponding Bash code (`bash_code`)
|
43 |
+
- Serial number (`srno`)
|
44 |
+
|
45 |
+
## Training Setup
|
46 |
+
|
47 |
+
### Training Parameters
|
48 |
+
|
49 |
+
- **Learning Rate:** 5e-5
|
50 |
+
- **Batch Size:** 8 (training), 16 (evaluation)
|
51 |
+
- **Number of Epochs:** 5
|
52 |
+
- **Warmup Steps:** 500
|
53 |
+
- **Gradient Accumulation Steps:** 2
|
54 |
+
- **Weight Decay:** 0.01
|
55 |
+
- **Evaluation Strategy:** End of each epoch
|
56 |
+
- **Mixed Precision:** Enabled (FP16)
|
57 |
+
|
58 |
+
### Optimizer and Scheduler
|
59 |
+
|
60 |
+
- **Optimizer:** AdamW
|
61 |
+
- **Scheduler:** Linear learning rate with warmup
|
62 |
+
|
63 |
+
### Training Workflow
|
64 |
+
|
65 |
+
- Tokenization and processing to fit model input requirements
|
66 |
+
- Data Collator: `DataCollatorForSeq2Seq`
|
67 |
+
- Evaluation Metric: BLEU score
|
68 |
+
|
69 |
+
### Training Performance
|
70 |
+
|
71 |
+
| Epoch | Training Loss | Validation Loss | BLEU | Precision Scores | Brevity Penalty | Length Ratio | Translation Length | Reference Length |
|
72 |
+
|-------|---------------|-----------------|-------|----------------------------|-----------------|--------------|-------------------|------------------|
|
73 |
+
| 1 | 0.1882 | 0.1534 | 0.2751| [0.682, 0.516, 0.405, 0.335]| 0.5886 | 0.6536 | 26,316 | 40,264 |
|
74 |
+
| 2 | 0.1357 | 0.1198 | 0.3016| [0.731, 0.575, 0.470, 0.401]| 0.5684 | 0.6390 | 25,729 | 40,264 |
|
75 |
+
| 3 | 0.0932 | 0.1007 | 0.3399| [0.769, 0.629, 0.530, 0.464]| 0.5789 | 0.6465 | 26,032 | 40,264 |
|
76 |
+
| 4 | 0.0738 | 0.0889 | 0.3711| [0.795, 0.669, 0.582, 0.522]| 0.5851 | 0.6511 | 26,214 | 40,264 |
|
77 |
+
| 5 | 0.0641 | 0.0810 | 0.3939| [0.810, 0.700, 0.622, 0.566]| 0.5893 | 0.6541 | 26,336 | 40,264 |
|
78 |
+
|
79 |
+
### Test Performance
|
80 |
+
|
81 |
+
- **Test Loss:** 0.0867
|
82 |
+
- **Test BLEU Score:** 0.3699
|
83 |
+
- **Precision Scores:** [0.809, 0.692, 0.611, 0.555]
|
84 |
+
- **Brevity Penalty:** 0.5604
|
85 |
+
- **Length Ratio:** 0.6333
|
86 |
+
- **Translation Length:** 26,108
|
87 |
+
- **Reference Length:** 41,225
|
88 |
+
|
89 |
+
## Usage
|
90 |
+
|
91 |
+
### Load the Model and Tokenizer
|
92 |
+
|
93 |
+
from transformers import AutoTokenizer, AutoModel
|
94 |
+
|
95 |
+
# Option 1: Load from Hugging Face Hub
|
96 |
+
```python
|
97 |
+
model_name = "your-username/model-name" # Replace with the actual model name on Hugging Face
|
98 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
99 |
+
model = AutoModel.from_pretrained(model_name)
|
100 |
+
|
101 |
+
# Option 2: Load from local directory
|
102 |
+
# local_model_path = "path/to/your/downloaded/model" # Replace with your local path
|
103 |
+
# tokenizer = AutoTokenizer.from_pretrained(local_model_path)
|
104 |
+
# model = AutoModel.from_pretrained(local_model_path)
|
105 |
+
```
|
106 |
+
### Prepare Input
|
107 |
+
|
108 |
+
```python
|
109 |
+
import torch
|
110 |
+
|
111 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
112 |
+
model.to(device)
|
113 |
+
model.eval() # Set the model to evaluation mode
|
114 |
+
|
115 |
+
# Add the prefix to the input command
|
116 |
+
nl_command = "Your natural language command here"
|
117 |
+
input_text_with_prefix = f"bash: {nl_command}"
|
118 |
+
|
119 |
+
# Tokenize the input
|
120 |
+
inputs_with_prefix = tokenizer(input_text_with_prefix, return_tensors="pt", truncation=True, max_length=128).to(device)
|
121 |
+
```
|
122 |
+
|
123 |
+
### Generate Bash Code
|
124 |
+
|
125 |
+
```python
|
126 |
+
# Generate bash code
|
127 |
+
with torch.no_grad():
|
128 |
+
outputs_with_prefix = model.generate(
|
129 |
+
**inputs_with_prefix,
|
130 |
+
max_new_tokens=200,
|
131 |
+
num_return_sequences=1,
|
132 |
+
temperature=0.3,
|
133 |
+
top_p=0.95,
|
134 |
+
do_sample=True,
|
135 |
+
eos_token_id=tokenizer.eos_token_id,
|
136 |
+
)
|
137 |
+
|
138 |
+
generated_code_with_prefix = tokenizer.decode(outputs_with_prefix[0], skip_special_tokens=True)
|
139 |
+
print("Generated Bash Command:", generated_code_with_prefix)
|
140 |
+
```
|
141 |
+
|
142 |
+
## Example Outputs
|
143 |
+
|
144 |
+
Input: "bash: Enable the shell option 'cmdhist'"
|
145 |
+
Expected Output: `shopt -s cmdhist`
|
146 |
+
Generated Output: `shopt -s cmdhist`
|
147 |
+
|
148 |
+
## Language Bias and Generalization
|
149 |
+
|
150 |
+
The model exhibits some language bias, performing better when the natural language command closely matches training examples. Minor variations in output can occur based on command phrasing:
|
151 |
+
|
152 |
+
1. Original Command: "Find all files under /path/to/base/dir and change their permission to 644."
|
153 |
+
Generated Bash Code: `find /path/to/base/dir -type f -exec chmod 644 {} +`
|
154 |
+
|
155 |
+
2. Variant Command: "Modify the permissions to 644 for every file in the directory /path/to/base/dir."
|
156 |
+
Generated Bash Code: `find /path/to/base/dir -type f -exec chmod 644 {} \;`
|
157 |
+
|
158 |
+
The model generally captures the intended functionality, but minor variations in output can occur.
|
159 |
+
|
160 |
+
## Limitations and Future Work
|
161 |
+
|
162 |
+
1. **Bash Command Accuracy:** While the BLEU score and precision metrics are promising, some generated commands may still require manual refinement.
|
163 |
+
2. **Handling Complex Commands:** For highly complex tasks, the model may not always produce optimal results.
|
164 |
+
3. **Language Variation:** The model's performance might degrade if the input deviates significantly from the training data.
|