Text Generation
Transformers
Safetensors
English
t5
text2text-generation
code
java
codet5
optimization
code-generation
text-generation-inference
Instructions to use nlpctx/codet5-java-optimizer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nlpctx/codet5-java-optimizer with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nlpctx/codet5-java-optimizer")# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("nlpctx/codet5-java-optimizer") model = AutoModelForSeq2SeqLM.from_pretrained("nlpctx/codet5-java-optimizer") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use nlpctx/codet5-java-optimizer with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nlpctx/codet5-java-optimizer" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nlpctx/codet5-java-optimizer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/nlpctx/codet5-java-optimizer
- SGLang
How to use nlpctx/codet5-java-optimizer with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "nlpctx/codet5-java-optimizer" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nlpctx/codet5-java-optimizer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "nlpctx/codet5-java-optimizer" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nlpctx/codet5-java-optimizer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use nlpctx/codet5-java-optimizer with Docker Model Runner:
docker model run hf.co/nlpctx/codet5-java-optimizer
File size: 3,656 Bytes
2f9309e ae11703 2f9309e c5bb003 2f9309e c5bb003 2f9309e c5bb003 2f9309e c5bb003 2f9309e c5bb003 2f9309e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | ---
language: en
license: apache-2.0
library_name: transformers
tags:
- code
- java
- codet5
- optimization
- code-generation
datasets:
- nlpctx/java_optimisation
base_model: Salesforce/codet5-small
pipeline_tag: text-generation
model-index:
- name: codet5-java-optimizer
results: []
---
# CodeT5-small Java Optimization Model
A fine-tuned [Salesforce/codet5-small](https://huggingface.co/Salesforce/codet5-small) model for Java code optimization tasks.
- **Model**: [nlpctx/codet5-java-optimizer](https://huggingface.co/nlpctx/codet5-java-optimizer)
- **Dataset**: [nlpctx/java_optimisation](https://huggingface.co/datasets/nlpctx/java_optimisation)
- **Base Model**: [Salesforce/codet5-small](https://huggingface.co/Salesforce/codet5-small)
## Overview
This repository contains a fine-tuned CodeT5-small model specifically trained for Java code optimization. The model takes verbose or inefficient Java code and generates more optimal versions.
## Model Information
- **Base Model**: Salesforce/codet5-small
- **Training Dataset**: [nlpctx/java_optimisation](https://huggingface.co/datasets/nlpctx/java_optimisation)
- **Framework**: HuggingFace Transformers with Seq2SeqTrainer
- **Training Setup**: Dual-GPU DataParallel (Kaggle T4×2)
- **Dataset Size**: ~6K training / 680 validation Java optimization pairs
- **Optimization Focus**: Java code refactoring and performance improvements
## Files
- `config.json` - Model configuration
- `generation_config.json` - Generation parameters
- `model.safetensors` - Model weights (safetensors format)
- `merges.txt` - BPE merges file
- `special_tokens_map.json` - Special tokens mapping
- `tokenizer_config.json` - Tokenizer configuration
- `vocab.json` - Vocabulary file
## Usage
```python
from transformers import T5ForConditionalGeneration, RobertaTokenizer
import torch
# Load model and tokenizer
model = T5ForConditionalGeneration.from_pretrained("nlpctx/codet5-java-optimizer")
tokenizer = RobertaTokenizer.from_pretrained("nlpctx/codet5-java-optimizer")
# Prepare input Java code
java_code = "your Java code here"
input_ids = tokenizer(java_code, return_tensors="pt").input_ids
# Generate optimized code
with torch.no_grad():
outputs = model.generate(
input_ids,
max_length=512,
num_beams=4,
early_stopping=True
)
optimized_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(optimized_code)
```
## Example Optimizations
The model has been trained to recognize and optimize common Java patterns:
- **Switch Expressions**: Converting verbose switch statements to switch expressions
- **Collection Operations**: Replacing manual iterator removal with `removeIf()`
- **String Handling**: Optimizing string concatenation with `StringBuilder`
- **Loop Optimizations**: Improving iterative constructs
- **And more...**
## Training Details
The model was fine-tuned using:
- **Base Model**: Salesforce/codet5-small
- **Dataset**: nlpctx/java_optimisation from Hugging Face
- **Training Framework**: Seq2SeqTrainer with DataParallel
- **Hardware**: Kaggle T4×2 (dual GPU)
- **Approach**: Standard supervised fine-tuning on Java optimization pairs
## License
This model is licensed under the **Apache 2.0** license, matching the original [Salesforce/codet5-small](https://huggingface.co/Salesforce/codet5-small) model.
## Acknowledgements
- Model based on [Salesforce/codet5-small](https://huggingface.co/Salesforce/codet5-small)
- Training data from [nlpctx/java_optimisation](https://huggingface.co/datasets/nlpctx/java_optimisation) dataset
- Built with [HuggingFace Transformers](https://github.com/huggingface/transformers)
|