Downloads · 30 days
64
25% of all-time downloads
uDivy/codet5p-220m-bimodal-finetune-english-to-bash
codet5p-220m-bimodal-finetune-english-to-bash is a text generation model from uDivy. Use it when you need the model to write or continue text. The card lists the license as bsd-3-clause.
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 a…
Downloads · 30 days
64
25% of all-time downloads
All-time downloads
256
Public
Parameters
223M
892 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors892 MB · 100%
From the Hugging Face model README
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.
The dataset used for training consists of natural language and Bash code pairs:
Each sample contains:
nl_command)bash_code)srno)DataCollatorForSeq2Seq| Epoch | Training Loss | Validation Loss | BLEU | Precision Scores | Brevity Penalty | Length Ratio | Translation Length | Reference Length |
|---|---|---|---|---|---|---|---|---|
| 1 | 0.1882 | 0.1534 | 0.2751 | [0.682, 0.516, 0.405, 0.335] | 0.5886 | 0.6536 | 26,316 | 40,264 |
| 2 | 0.1357 | 0.1198 | 0.3016 | [0.731, 0.575, 0.470, 0.401] | 0.5684 | 0.6390 | 25,729 | 40,264 |
| 3 | 0.0932 | 0.1007 | 0.3399 | [0.769, 0.629, 0.530, 0.464] | 0.5789 | 0.6465 | 26,032 | 40,264 |
| 4 | 0.0738 | 0.0889 | 0.3711 | [0.795, 0.669, 0.582, 0.522] | 0.5851 | 0.6511 | 26,214 | 40,264 |
| 5 | 0.0641 | 0.0810 | 0.3939 | [0.810, 0.700, 0.622, 0.566] | 0.5893 | 0.6541 | 26,336 | 40,264 |
from transformers import AutoTokenizer, AutoModel
model_name = "your-username/model-name" # Replace with the actual model name on Hugging Face
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModel.from_pretrained(model_name)
# Option 2: Load from local directory
# local_model_path = "path/to/your/downloaded/model" # Replace with your local path
# tokenizer = AutoTokenizer.from_pretrained(local_model_path)
# model = AutoModel.from_pretrained(local_model_path)
import torch
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
model.eval() # Set the model to evaluation mode
# Add the prefix to the input command
nl_command = "Your natural language command here"
input_text_with_prefix = f"bash: {nl_command}"
# Tokenize the input
inputs_with_prefix = tokenizer(input_text_with_prefix, return_tensors="pt", truncation=True, max_length=128).to(device)
# Generate bash code
with torch.no_grad():
outputs_with_prefix = model.generate(
**inputs_with_prefix,
max_new_tokens=200,
num_return_sequences=1,
temperature=0.3,
top_p=0.95,
do_sample=True,
eos_token_id=tokenizer.eos_token_id,
)
generated_code_with_prefix = tokenizer.decode(outputs_with_prefix[0], skip_special_tokens=True)
print("Generated Bash Command:", generated_code_with_prefix)
Input: "bash: Enable the shell option 'cmdhist'"
Expected Output: shopt -s cmdhist
Generated Output: shopt -s cmdhist
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:
Original Command: "Find all files under /path/to/base/dir and change their permission to 644."
Generated Bash Code: find /path/to/base/dir -type f -exec chmod 644 {} +
Variant Command: "Modify the permissions to 644 for every file in the directory /path/to/base/dir."
Generated Bash Code: find /path/to/base/dir -type f -exec chmod 644 {} \;
The model generally captures the intended functionality, but minor variations in output can occur.