CoolFace
Modelpublic

kez-lab/quiz-korean

sourceHugging Faceapache-2.0updated 1mo agoView on Hugging Face
0likes17downloads
Model Card

๐Ÿง  Qwen2.5-0.5B Blog-to-Quiz (On-Device Android AI)

![License](https://opensource.org/licenses/Apache-2.0) ![Base Model](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct) ![Hardware](https://developer.android.com) ![Fine-Tuning-purple.svg)](https://github.com/huggingface/peft)

A specialized, ultra-lightweight On-Device Small Language Model (sLLM) fine-tuned to read blogs, technical articles, or personal notes and automatically synthesize 4-choice multiple-choice quizzes (Question, Options, Answer Index, and In-depth Explanation) in strictly formatted JSON.

Designed natively for mobile applications and edge runtimes (Google MediaPipe GenAI / LiteRT), running completely offline with zero cloud inference costs and 100% user privacy.


๐ŸŒŸ Key Highlights

  • โ€”๐Ÿ”’ 100% On-Device & Private: No data leaves the user's phone. Operates seamlessly without internet connectivity.
  • โ€”โšก Ultra Lightweight (~350MB in INT4): Optimized for fast token generation on mobile CPUs, GPUs, and NPUs with low thermal footprint.
  • โ€”๐ŸŽฏ Deterministic JSON Schema: Generates clean, parseable JSON objects designed for direct deserialization into Android/Kotlin data models.
  • โ€”๐Ÿ“š Educational & Productivity Focus: Ideal for flashcard apps, tech blog readers (Medium, Velog, Tistory), study assistants, and note-taking tools.

๐Ÿ“‹ Output Schema & Example

Given an input article or document, the model returns an array of structured quiz objects:

json
[
  {
    "question": "Which dispatcher in Kotlin Coroutines is specifically optimized for disk and network I/O operations?",
    "options": [
      "Dispatchers.Main",
      "Dispatchers.IO",
      "Dispatchers.Default",
      "Dispatchers.Unconfined"
    ],
    "answer_index": 1,
    "explanation": "Dispatchers.IO is designed and optimized for offloading blocking I/O tasks such as network requests and file access."
  }
]

๐Ÿš€ Quickstart & Usage

1. Python (Transformers + PEFT)

python
import json
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

BASE_MODEL = "Qwen/Qwen2.5-0.5B-Instruct"
ADAPTER_REPO = "kez-lab/qwen2.5-0.5b-blog-quiz-android"

# 1. Load Tokenizer & Base Model
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
base_model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, torch_dtype=torch.float32, trust_remote_code=True)

# 2. Merge LoRA Adapter
model = PeftModel.from_pretrained(base_model, ADAPTER_REPO)
model.eval()

# 3. Inference
article = "Kotlin Coroutines provide lightweight threads that can suspend without blocking..."
system_prompt = (
    "You are an AI that analyzes given text and generates multiple-choice quizzes.\n"
    "Respond strictly with a JSON array: [{\"question\": \"...\", \"options\": [\"...\"], \"answer_index\": 0, \"explanation\": \"...\"}]"
)

messages = [
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": f"Generate a multiple-choice quiz based on this text:\n\n{article}"}
]

prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt")

with torch.no_grad():
    outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.3, do_sample=True)

response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
print(response)

2. Android Kotlin SDK

Integrate this model directly into any Android app using the companion SDK:

kotlin
// 1. Initialize On-Device Generator
val quizGen = LocalQuizGenerator.builder(context)
    .fromHuggingFace("kez-lab/qwen2.5-0.5b-blog-quiz-android")
    .build()

// 2. Generate Quizzes on-device
val result = quizGen.generateQuiz(blogText, count = 2)

result.onSuccess { quizzes ->
    quizzes.forEach { quiz ->
        println("Question: ${quiz.question}")
        println("Options: ${quiz.options}")
        println("Correct Answer: ${quiz.correctAnswer}")
        println("Explanation: ${quiz.explanation}")
    }
}

๐Ÿ”ฌ Training Configuration

  • โ€”Base Architecture: Qwen2.5-0.5B-Instruct (0.49B parameters)
  • โ€”Fine-Tuning Technique: Parameter-Efficient Fine-Tuning (PEFT) via LoRA
  • โ€”LoRA Hyperparameters:
  • โ€”Rank ($r$): 16
  • โ€”Alpha ($\alpha$): 32
  • โ€”Dropout: 0.05
  • โ€”Target Modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
  • โ€”Training Setup:
  • โ€”Hardware: Apple Silicon (M4 Pro) via Metal Performance Shaders (torch.device("mps"))
  • โ€”Epochs: 8
  • โ€”Optimizer: AdamW (learning_rate=3e-4)
  • โ€”Final Loss: `0.4139`

โš–๏ธ License

This model and its adapter weights are released under the Apache 2.0 License.


๐Ÿ‘ค Author & Attribution

Framework versions

  • โ€”PEFT 0.20.0