This model translates natural language (English) instructions to Bash commands.
Model Details
Model Description
This model is a fine-tuned version of the Llama-3.2-3B-Instruct model trained on the NL2SH-ALFA dataset for the task of natural language to Bash translation (NL2SH). For more information, please refer to the paper.
This model is intended for research on machine translation. The model can also be used as an educational resource for learning Bash.
Out-of-Scope Use
This model should not be used in production or automated systems without human verification.
Considerations for use in high-risk environments: This model should not be used in high-risk environments due to its low accuracy and potential for generating harmful commands.
Bias, Risks, and Limitations
This model has a tendency to generate overly complex and incorrect Bash commands. It may produce harmful commands that delete data or corrupt a system. This model is not intended for natural languages other than English, scripting languages or than Bash, or multi-line Bash scripts.
Recommendations
Users are encouraged to use this model as Bash reference tool and should not execute commands without verification.
How to Get Started with the Model
Use the code below to get started with the model.
python
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
34deftranslate(prompt):5 model_name ="westenfelder/Llama-3.2-3B-Instruct-NL2SH"6 tokenizer = AutoTokenizer.from_pretrained(model_name, clean_up_tokenization_spaces=False)7 model = AutoModelForCausalLM.from_pretrained(model_name, device_map="cuda", torch_dtype=torch.bfloat16)89 messages =[10{"role":"system","content":"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."},11{"role":"user","content":f"{prompt}"},12]1314 tokens = tokenizer.apply_chat_template(15 messages,16 add_generation_prompt=True,17 tokenize=True,18 return_tensors="pt"19).to(model.device)2021 attention_mask = torch.ones_like(tokens)2223 terminators =[24 tokenizer.eos_token_id,25 tokenizer.convert_tokens_to_ids("<|eot_id|>")26]2728 outputs = model.generate(29 tokens,30 attention_mask=attention_mask,31 max_new_tokens=100,32 eos_token_id=terminators,33 pad_token_id=tokenizer.eos_token_id,34 do_sample=False,35 temperature=None,36 top_p=None,37 top_k=None,38)3940 response = outputs[0][tokens.shape[-1]:]41return tokenizer.decode(response, skip_special_tokens=True)424344nl ="List files in the /workspace directory that were accessed over an hour ago."45sh = translate(nl)46print(sh)
This model achieved an accuracy of 0.47 on the InterCode-ALFA benchmark.
Environmental Impact
Experiments were conducted using a private infrastructure, which has a approximate carbon efficiency of 0.432 kgCO2eq/kWh. A cumulative of 12 hours of computation was performed on hardware of type RTX A6000 (TDP of 300W). Total emissions are estimated to be 1.56 kgCO2eq of which 0 percents were directly offset. Estimations were conducted using the Machine Learning Emissions Calculator.
Citation
BibTeX:
@misc{westenfelder2025llmsupportednaturallanguagebash,
title={LLM-Supported Natural Language to Bash Translation},
author={Finnian Westenfelder and Erik Hemberg and Miguel Tulla and Stephen Moskal and Una-May O'Reilly and Silviu Chiricescu},
year={2025},
eprint={2502.06858},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2502.06858},
}