arhansd1/Csv-CommandToCode
Viewer • Updated • 642 • 3
Transform English instructions with data context into executable pandas code with AI
Csv-AI-Cleaner converts natural language instructions into pandas code for data cleaning, filtering, grouping, sorting, merges, and more.
Fine-tuned on synthetic + real-world datasets using CodeT5 with LoRA for efficiency.
Example:
Context:
employee_id | name | salary | department
E001 | Alice | 50000 | IT
E002 | Bob | 45000 | HR
Instruction: Show IT department employees earning over 45000
Output:
df[(df['department'] == 'IT') & (df['salary'] > 45000)]
Users should verify generated code for correctness and safety before execution.
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import torch
MODEL_REPO = "arhansd1/Csv-AI-Cleaner-V3"
tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO)
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_REPO)
def generate_code(input_text):
prefixed_input = "Generate pandas code: " + input_text
inputs = tokenizer(prefixed_input, return_tensors="pt", truncation=True, max_length=512)
with torch.no_grad():
outputs = model.generate(
input_ids=inputs.input_ids,
attention_mask=inputs.attention_mask,
max_length=128,
num_beams=5,
temperature=0.7,
early_stopping=True
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Example
input_example = """
Context:
employee_id | name | salary | department
E001 | Alice | 50000 | IT
E002 | Bob | 45000 | HR
Instruction: Show IT department employees earning over 45000
"""
print(generate_code(input_example))
| Metric | Score |
|---|---|
| Exact Match | 71% |
| Partial Match | 92% |
| Syntax Accuracy | 100% |
High syntax accuracy, good partial match rate, slightly lower exact match on multi-condition or chained operations.
Base model
Salesforce/codet5-base