A LoRA adapter fine-tuned on top of Qwen/Qwen3.5-2B for Arabic text semantic segmentation.
Given a block of Arabic text, the model splits it into small, self-contained, meaningful sentences and returns them as a structured JSON object.
This model was trained via knowledge distillation from a GPT-OSS-20B teacher model, using Unsloth for efficient 4-bit LoRA fine-tuning.
Intended Use
Use case
Supported
Arabic sentence segmentation
✅
Semantic chunking for RAG pipelines
✅
Pre-processing Arabic documents
✅
Non-Arabic languages
❌
Translation or paraphrasing
❌
Quick Start
python
1import json
2import torch
3from unsloth import FastLanguageModel
45MODEL_ID ="marioVIC/qwen3-5-2b-arabic-semantic-chunking"67model, tokenizer = FastLanguageModel.from_pretrained(8 model_name = MODEL_ID,9 max_seq_length =2048,10 dtype =None,11 load_in_4bit =True,12)13FastLanguageModel.for_inference(model)1415SYSTEM_PROMPT ="""
16You are an expert Arabic text segmentation assistant. Your task is to split the given Arabic text into small, meaningful sentences.
17Follow these rules strictly:
181. Each sentence must be a complete, self-contained meaningful unit.
192. Do NOT merge multiple ideas into one sentence.
203. Do NOT split a single idea across multiple sentences.
214. Preserve the original Arabic text exactly — do not paraphrase, translate, or fix grammar.
225. Remove excessive whitespace or newlines, but keep the words intact.
236. Return ONLY a valid JSON object — no explanation, no markdown, no code fences.
24The JSON format must be exactly: {"sentences": ["<sentence1>", "<sentence2>", ...]}
25"""2627defsegment(text:str)->list[str]:28 prompt =(29f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n"30f"<|im_start|>user\nText to split:\n{text}<|im_end|>\n"31f"<|im_start|>assistant\n"32)33 input_ids = tokenizer(34 prompt,35 return_tensors ="pt",36 add_special_tokens =False,37).input_ids.to(model.device)3839with torch.inference_mode():40 output_ids = model.generate(41 input_ids,42 max_new_tokens =512,43 do_sample =False,44 repetition_penalty =1.1,45 pad_token_id = tokenizer.eos_token_id,46 eos_token_id = tokenizer.convert_tokens_to_ids("<|im_end|>"),47)4849 generated = output_ids[0][input_ids.shape[-1]:]50 raw = tokenizer.decode(generated, skip_special_tokens=True).strip()51return json.loads(raw).get("sentences",[])525354text =(55"الذكاء الاصطناعي هو مجال من مجالات علوم الحاسوب يهتم بتطوير أنظمة "56"قادرة على تنفيذ مهام تتطلب عادةً ذكاءً بشرياً. تشمل هذه المهام التعرف "57"على الكلام وترجمة اللغات واتخاذ القرارات."58)5960for i, s inenumerate(segment(text),1):61print(f"[{i}] {s}")
Expected output:
[1] الذكاء الاصطناعي هو مجال من مجالات علوم الحاسوب يهتم بتطوير أنظمة قادرة على تنفيذ مهام تتطلب عادةً ذكاءً بشرياً.
[2] تشمل هذه المهام التعرف على الكلام وترجمة اللغات واتخاذ القرارات.
Knowledge distillation — a GPT-OSS-20B teacher model was used to generate segmentation labels over an Arabic corpus. The student (Qwen3.5-2B) was then fine-tuned on those labels via supervised fine-tuning (SFT).