Update README.md
Browse files
README.md
CHANGED
|
@@ -5,35 +5,101 @@ tags:
|
|
| 5 |
- code-generation
|
| 6 |
- nlp
|
| 7 |
- qwen2
|
|
|
|
|
|
|
|
|
|
| 8 |
base_model: Qwen/Qwen2.5-Coder-0.5B-Instruct
|
|
|
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
# NL to Bash — Qwen2.5-Coder-0.5B Fine-tuned
|
| 12 |
|
| 13 |
-
Fine-tuned version of Qwen2.5-Coder-0.5B-Instruct on 40,639
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
## Results
|
|
|
|
| 17 |
| Metric | Score |
|
| 18 |
|---|---|
|
| 19 |
| Exact Match | 13.67% |
|
| 20 |
-
| Semantic Match (≥0.8) | 60.33% |
|
| 21 |
| Avg Similarity | 0.776 |
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
## Usage
|
|
|
|
| 24 |
```python
|
| 25 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 26 |
|
| 27 |
model = AutoModelForCausalLM.from_pretrained("dhwanichande29/nl-to-bash")
|
| 28 |
tokenizer = AutoTokenizer.from_pretrained("dhwanichande29/nl-to-bash")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
```
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
## Dataset
|
| 32 |
-
|
| 33 |
-
—
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
| 5 |
- code-generation
|
| 6 |
- nlp
|
| 7 |
- qwen2
|
| 8 |
+
- shell
|
| 9 |
+
- natural-language-processing
|
| 10 |
+
license: apache-2.0
|
| 11 |
base_model: Qwen/Qwen2.5-Coder-0.5B-Instruct
|
| 12 |
+
datasets:
|
| 13 |
+
- westenfelder/NL2SH-ALFA
|
| 14 |
---
|
| 15 |
|
| 16 |
# NL to Bash — Qwen2.5-Coder-0.5B Fine-tuned
|
| 17 |
|
| 18 |
+
Fine-tuned version of [Qwen2.5-Coder-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B-Instruct) on 40,639 natural language → Bash command pairs from the NL2SH-ALFA dataset.
|
| 19 |
+
|
| 20 |
+
Try it live: 🚀 [Gradio Demo](https://huggingface.co/spaces/dhwanichande29/nl-to-bash)
|
| 21 |
+
|
| 22 |
+
---
|
| 23 |
|
| 24 |
## Results
|
| 25 |
+
|
| 26 |
| Metric | Score |
|
| 27 |
|---|---|
|
| 28 |
| Exact Match | 13.67% |
|
| 29 |
+
| Semantic Match (cosine ≥ 0.8) | 60.33% |
|
| 30 |
| Avg Similarity | 0.776 |
|
| 31 |
|
| 32 |
+
> Evaluated on 300 held-out test examples from NL2SH-ALFA.
|
| 33 |
+
> Semantic similarity is computed using `all-MiniLM-L6-v2` embeddings and is a better indicator of real-world quality than exact match alone, since multiple Bash commands can be functionally equivalent.
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
## Usage
|
| 38 |
+
|
| 39 |
```python
|
| 40 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 41 |
|
| 42 |
model = AutoModelForCausalLM.from_pretrained("dhwanichande29/nl-to-bash")
|
| 43 |
tokenizer = AutoTokenizer.from_pretrained("dhwanichande29/nl-to-bash")
|
| 44 |
+
|
| 45 |
+
system_prompt = "Your task is to translate a natural language instruction to a Bash command. You will receive an instruction in English and output a Bash command that can be run in a Linux terminal."
|
| 46 |
+
|
| 47 |
+
def translate(instruction):
|
| 48 |
+
messages = [
|
| 49 |
+
{"role": "system", "content": system_prompt},
|
| 50 |
+
{"role": "user", "content": instruction}
|
| 51 |
+
]
|
| 52 |
+
formatted = tokenizer.apply_chat_template(
|
| 53 |
+
messages,
|
| 54 |
+
tokenize=False,
|
| 55 |
+
add_generation_prompt=True
|
| 56 |
+
)
|
| 57 |
+
inputs = tokenizer(formatted, return_tensors="pt").to(model.device)
|
| 58 |
+
outputs = model.generate(**inputs, max_new_tokens=100, do_sample=False)
|
| 59 |
+
response = outputs[0][inputs.input_ids.shape[-1]:]
|
| 60 |
+
return tokenizer.decode(response, skip_special_tokens=True).strip()
|
| 61 |
+
|
| 62 |
+
print(translate("list all files in current directory"))
|
| 63 |
+
# find . -type f
|
| 64 |
```
|
| 65 |
|
| 66 |
+
---
|
| 67 |
+
|
| 68 |
+
## Example Outputs
|
| 69 |
+
|
| 70 |
+
| Natural Language | Generated Bash |
|
| 71 |
+
|---|---|
|
| 72 |
+
| list all files in current directory | `find . -type f` |
|
| 73 |
+
| find all python files | `find . -name "*.py"` |
|
| 74 |
+
| count lines in a text file | `wc -l path/to/file` |
|
| 75 |
+
| remove all .tmp files | `find . -name "*.tmp" -exec rm {} \;` |
|
| 76 |
+
| show disk usage | `du -h /` |
|
| 77 |
+
|
| 78 |
+
---
|
| 79 |
+
|
| 80 |
+
## Training Details
|
| 81 |
+
|
| 82 |
+
- **Base model:** Qwen/Qwen2.5-Coder-0.5B-Instruct (494M parameters)
|
| 83 |
+
- **Dataset:** [westenfelder/NL2SH-ALFA](https://huggingface.co/datasets/westenfelder/NL2SH-ALFA)
|
| 84 |
+
- **Train split:** 40,639 examples
|
| 85 |
+
- **Test split:** 300 examples
|
| 86 |
+
- **Epochs:** 10
|
| 87 |
+
- **Batch size:** 15 per device (effective: 75 with gradient accumulation steps of 5)
|
| 88 |
+
- **Precision:** bfloat16
|
| 89 |
+
- **Max token length:** 150
|
| 90 |
+
- **Hardware:** NVIDIA A100-SXM4-80GB
|
| 91 |
+
- **Training time:** ~2.09 hours
|
| 92 |
+
- **Experiment tracking:** Weights & Biases (`nl2sh` project)
|
| 93 |
+
|
| 94 |
+
---
|
| 95 |
+
|
| 96 |
## Dataset
|
| 97 |
+
|
| 98 |
+
[westenfelder/NL2SH-ALFA](https://huggingface.co/datasets/westenfelder/NL2SH-ALFA) — a dataset of natural language instructions paired with corresponding Bash commands.
|
| 99 |
+
|
| 100 |
+
---
|
| 101 |
+
|
| 102 |
+
## GitHub
|
| 103 |
+
|
| 104 |
+
Full training code, evaluation notebooks, and FastAPI deployment:
|
| 105 |
+
👉 [github.com/Dhwani-Chande/Natural-Language-to-Bash-Translation-using-LLMs](https://github.com/Dhwani-Chande/Natural-Language-to-Bash-Translation-using-LLMs)
|