Java CodeGen: SFT vs Meta
Collection
Comparative study of standard SFT vs META-cognitive reasoning for Java code generation.
•
3 items
•
Updated
This model is a fine-tuned version of meta-llama/Llama-3.2-3B specifically trained for Java method generation using supervised fine-tuning (SFT).
Trained on [https://github.com/microsoft/CodeXGLUE/blob/main/Text-Code/text-to-code/dataset/concode/train.json):
pip install transformers torch
from transformers import AutoTokenizer, AutoModelForCausalLM
# Load model and tokenizer
model_name = "Naholav/llama-3.2-3b-100k-codeXGLUE-sft"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
# Prepare prompt
task_description = "returns the sum of two integers"
prompt = f"""You are an expert Java programmer. Generate a complete, working Java method for the given description.
Task: {task_description}
Requirements:
- Write a complete Java method
- Use proper syntax and naming conventions
- Include return statements where needed
- Keep it concise but functional
```java
"""
# Generate code
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=150,
temperature=0.2,
do_sample=True,
top_p=0.95,
pad_token_id=tokenizer.eos_token_id
)
generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_code)
The model generates Java methods following this pattern:
public int sum(int a, int b) {
return a + b;
}
For local evaluation, you can use:
Important: Remember to clean the natural language descriptions before inference:
def clean_nl(nl_description):
cleaned = nl_description.replace("concode_field_sep", " | ")
cleaned = cleaned.replace("concode_elem_sep", ", ")
return ' '.join(cleaned.split())
The model was evaluated during training with:
This is the standard SFT version. For comparison with the reflection-based training approach, see:
Base model
meta-llama/Llama-3.2-3B