Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,62 +1,175 @@
|
|
| 1 |
---
|
| 2 |
base_model: google/gemma-3-270m-it
|
| 3 |
library_name: peft
|
| 4 |
-
model_name: form-generator-gemma-adapters
|
| 5 |
tags:
|
| 6 |
-
-
|
|
|
|
|
|
|
|
|
|
| 7 |
- lora
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
-
#
|
| 16 |
|
| 17 |
-
|
| 18 |
-
It has been trained using [TRL](https://github.com/huggingface/trl).
|
| 19 |
|
| 20 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
```python
|
| 23 |
-
from transformers import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
```
|
| 30 |
|
| 31 |
-
## Training
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
|
|
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
|
| 40 |
-
-
|
| 41 |
-
-
|
| 42 |
-
-
|
| 43 |
-
-
|
| 44 |
-
- Datasets: 4.3.0
|
| 45 |
-
- Tokenizers: 0.22.1
|
| 46 |
|
| 47 |
-
##
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
Cite TRL as:
|
| 52 |
-
|
| 53 |
```bibtex
|
| 54 |
-
@misc{
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
howpublished = {\url{https://github.com/huggingface/trl}}
|
| 61 |
}
|
| 62 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
base_model: google/gemma-3-270m-it
|
| 3 |
library_name: peft
|
|
|
|
| 4 |
tags:
|
| 5 |
+
- text-generation
|
| 6 |
+
- form-generation
|
| 7 |
+
- json
|
| 8 |
+
- gemma
|
| 9 |
- lora
|
| 10 |
+
- peft
|
| 11 |
+
- bahasa-indonesia
|
| 12 |
+
language:
|
| 13 |
+
- id
|
| 14 |
+
datasets:
|
| 15 |
+
- bhismaperkasa/form_dinamis
|
| 16 |
+
license: apache-2.0
|
| 17 |
---
|
| 18 |
|
| 19 |
+
# Form Generator - Gemma 3 270M (LoRA Adapters)
|
| 20 |
|
| 21 |
+
Fine-tuned LoRA adapters for `google/gemma-3-270m-it` to generate form definitions in JSON format from natural language descriptions in Bahasa Indonesia.
|
|
|
|
| 22 |
|
| 23 |
+
## π― Model Description
|
| 24 |
+
|
| 25 |
+
This repository contains **LoRA adapters** (not a merged model) that can be loaded on top of the base Gemma 3 270M model. The adapters were trained to generate dynamic form definitions in JSON format.
|
| 26 |
+
|
| 27 |
+
## β οΈ Important Note
|
| 28 |
+
|
| 29 |
+
**This is a LoRA adapter model, NOT a standalone model.** You need to load it together with the base model `google/gemma-3-270m-it`.
|
| 30 |
+
|
| 31 |
+
## π Usage
|
| 32 |
+
|
| 33 |
+
### Installation
|
| 34 |
+
|
| 35 |
+
```bash
|
| 36 |
+
pip install transformers peft torch
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
### Loading the Model
|
| 40 |
|
| 41 |
```python
|
| 42 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 43 |
+
from peft import PeftModel
|
| 44 |
+
import torch
|
| 45 |
+
|
| 46 |
+
# Load base model
|
| 47 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 48 |
+
"google/gemma-3-270m-it",
|
| 49 |
+
device_map="auto",
|
| 50 |
+
torch_dtype=torch.bfloat16
|
| 51 |
+
)
|
| 52 |
|
| 53 |
+
# Load LoRA adapters
|
| 54 |
+
model = PeftModel.from_pretrained(base_model, "bhismaperkasa/form-generator-lora-adapters")
|
| 55 |
+
tokenizer = AutoTokenizer.from_pretrained("bhismaperkasa/form-generator-lora-adapters")
|
| 56 |
+
|
| 57 |
+
# Generate
|
| 58 |
+
messages = [
|
| 59 |
+
{"role": "system", "content": "You are a helpful assistant that generates form definitions in JSON format based on user requests."},
|
| 60 |
+
{"role": "user", "content": "buatkan form pendaftaran event dengan nama dan email"}
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 64 |
+
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
|
| 65 |
+
|
| 66 |
+
outputs = model.generate(
|
| 67 |
+
**inputs,
|
| 68 |
+
max_new_tokens=512,
|
| 69 |
+
temperature=0.7,
|
| 70 |
+
do_sample=True
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 74 |
+
generated = result.split("<start_of_turn>model\n")[-1].strip()
|
| 75 |
+
print(generated)
|
| 76 |
```
|
| 77 |
|
| 78 |
+
## π Training Details
|
| 79 |
|
| 80 |
+
- **Base Model**: google/gemma-3-270m-it
|
| 81 |
+
- **Method**: QLoRA (4-bit quantization + LoRA)
|
| 82 |
+
- **Dataset**: bhismaperkasa/form_dinamis (10,000 samples)
|
| 83 |
+
- **Training Samples**: ~9,000
|
| 84 |
+
- **Validation Samples**: ~1,000
|
| 85 |
+
- **Epochs**: 3
|
| 86 |
+
- **Final Eval Loss**: 0.2256
|
| 87 |
+
- **Token Accuracy**: 93.5%
|
| 88 |
|
| 89 |
+
### Hyperparameters
|
| 90 |
|
| 91 |
+
- LoRA Rank: 16
|
| 92 |
+
- LoRA Alpha: 32
|
| 93 |
+
- LoRA Dropout: 0.05
|
| 94 |
+
- Learning Rate: 5e-5
|
| 95 |
+
- Batch Size: 4
|
| 96 |
+
- Max Length: 512 tokens
|
| 97 |
|
| 98 |
+
## π Performance
|
| 99 |
|
| 100 |
+
- **Evaluation Loss**: 0.2256
|
| 101 |
+
- **Token Accuracy**: 93.50%
|
| 102 |
+
- **Train-Eval Gap**: 4.9% (healthy, no overfitting)
|
| 103 |
+
- **Entropy**: 0.1881 (high confidence)
|
|
|
|
|
|
|
| 104 |
|
| 105 |
+
## π‘ Example Outputs
|
| 106 |
|
| 107 |
+
**Input:**
|
| 108 |
+
```
|
| 109 |
+
buatkan form login sederhana
|
| 110 |
+
```
|
| 111 |
|
| 112 |
+
**Output:**
|
| 113 |
+
```json
|
| 114 |
+
{
|
| 115 |
+
"id": "form_login_sims",
|
| 116 |
+
"title": "Form Login",
|
| 117 |
+
"description": "Form untuk login akun",
|
| 118 |
+
"formDefinition": {
|
| 119 |
+
"fields": [
|
| 120 |
+
{"fieldId": "email", "label": "Email", "fieldType": "EMAIL", "required": true},
|
| 121 |
+
{"fieldId": "password", "label": "Password", "fieldType": "PASSWORD", "required": true}
|
| 122 |
+
]
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
## π Use Cases
|
| 128 |
+
|
| 129 |
+
- Dynamic form generation for web applications
|
| 130 |
+
- Survey and questionnaire creation
|
| 131 |
+
- User registration forms
|
| 132 |
+
- Data collection forms
|
| 133 |
+
- Event registration forms
|
| 134 |
+
|
| 135 |
+
## βοΈ Technical Details
|
| 136 |
+
|
| 137 |
+
### Why LoRA Adapters?
|
| 138 |
+
|
| 139 |
+
- **Smaller size**: ~50MB vs ~500MB for merged model
|
| 140 |
+
- **Better quality**: Works more reliably than merged model
|
| 141 |
+
- **Flexibility**: Can be combined with different base models
|
| 142 |
+
- **Efficiency**: Faster to download and deploy
|
| 143 |
+
|
| 144 |
+
### Model Architecture
|
| 145 |
+
|
| 146 |
+
- Base: Gemma 3 270M (270 million parameters)
|
| 147 |
+
- Adapters: LoRA with rank 16 (few million trainable parameters)
|
| 148 |
+
- Target modules: All linear layers
|
| 149 |
+
- Quantization: 4-bit NormalFloat (NF4)
|
| 150 |
+
|
| 151 |
+
## π Citation
|
| 152 |
|
|
|
|
|
|
|
| 153 |
```bibtex
|
| 154 |
+
@misc{form-generator-gemma-lora,
|
| 155 |
+
author = {bhismaperkasa},
|
| 156 |
+
title = {Form Generator - Gemma 3 270M LoRA Adapters},
|
| 157 |
+
year = {2025},
|
| 158 |
+
publisher = {Hugging Face},
|
| 159 |
+
howpublished = {\url{https://huggingface.co/bhismaperkasa/form-generator-lora-adapters}}
|
|
|
|
| 160 |
}
|
| 161 |
+
```
|
| 162 |
+
|
| 163 |
+
## π License
|
| 164 |
+
|
| 165 |
+
This model is based on Gemma 3 270M which is licensed under Apache 2.0.
|
| 166 |
+
|
| 167 |
+
## π Acknowledgments
|
| 168 |
+
|
| 169 |
+
- Google for Gemma 3 270M model
|
| 170 |
+
- Hugging Face for transformers, PEFT, and TRL libraries
|
| 171 |
+
- Dataset: bhismaperkasa/form_dinamis
|
| 172 |
+
|
| 173 |
+
---
|
| 174 |
+
|
| 175 |
+
**Note**: For production use, consider using these adapters instead of a merged model for better reliability and performance.
|