--- base_model: openbmb/MiniCPM4-8B library_name: peft pipeline_tag: text-generation tags: - twi - akan - ghana - lora - peft - llama-factory license: apache-2.0 language: - tw - en --- # TwiGen MiniCPM4 LoRA adapter for [MiniCPM4-8B](https://huggingface.co/openbmb/MiniCPM4-8B) fine-tuned on Twi (Akan) instruction data. Part of the TwiGen project. Generates coherent Twi text from English instructions. ## Usage ```python import torch from transformers import AutoModelForCausalLM, AutoTokenizer from peft import PeftModel base_id = "openbmb/MiniCPM4-8B" lora_id = "ghananlpcommunity/twi-gen-minicpm4" tokenizer = AutoTokenizer.from_pretrained(base_id, trust_remote_code=True) tokenizer.pad_token = tokenizer.eos_token model = AutoModelForCausalLM.from_pretrained( base_id, trust_remote_code=True, torch_dtype=torch.bfloat16, device_map="cuda:0", ) model = PeftModel.from_pretrained(model, lora_id) model.eval() messages = [{"role": "user", "content": "Write a story about a farmer in Ghana."}] prompt = tokenizer.apply_chat_template(messages, tokenize=False) + "<|im_start|>assistant\n" inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=2048).to(model.device) outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7, do_sample=True) print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)) ``` ## Training - **Base model:** MiniCPM4-8B - **Data:** ~495k Twi instruction samples (translated + synthetic) - **Method:** LoRA (rank 16, alpha 32) - **Hardware:** NVIDIA H200 (140 GB VRAM) - **Framework:** LLaMA-Factory ## Model | Model | Adapter | |-------|---------| | [twi-gen-qwen](https://huggingface.co/ghananlpcommunity/twi-gen-qwen) | Qwen3.5-0.8B version (lighter, faster) |