Qwen-Ar-GEC / README.md
Abdo-Alshoki's picture
Update README.md
c35adf4 verified
metadata
library_name: transformers
tags:
  - llama-factory

Qwen-Ar-GEC

Qwen-Ar-GEC is a fine-tuned adaptation of the Qwen model for Arabic Grammatical Error Correction (GEC).
The goal of this model is to automatically detect and correct grammatical, spelling, and stylistic errors in Arabic text,
making it useful for applications such as language learning, academic writing assistance, and automated proofreading.

Architecture

This model was fine-tuned using the QLoRA method on 50,000 samples, based on the Qwen 2.5-7B-Instruct architecture.
The fine-tuning followed the system instruction below:

ุตุญู‘ุญ ุงู„ุฃุฎุทุงุก ุงู„ู†ุญูˆูŠุฉ ูˆุงู„ุฅู…ู„ุงุฆูŠุฉ ูู‚ุท ุฅู† ูˆูุฌุฏุช. ุฃุถู ุงู„ุชุดูƒูŠู„ ุงู„ูƒุงู…ู„ ุนู„ู‰ ูƒู„ ุงู„ุญุฑูˆู ุฅุฌุจุงุฑูŠู‹ุง โ€” ุญุชู‰ ู„ูˆ ูƒุงู† ุงู„ู†ุต ุตุญูŠุญู‹ุง. ู„ุง ุชูุบูŠู‘ุฑ ุฃูŠ ูƒู„ู…ุฉ ุฃูˆ ุงุณู… ุฃูˆ ุฑู‚ู… ุฃูˆ ุจู†ูŠุฉ ุฌู…ู„ุฉ. ุฅุฐุง ู„ู… ูŠูƒู† ู‡ู†ุงูƒ ุฎุทุฃ ู†ุญูˆูŠ ุฃูˆ ุฅู…ู„ุงุฆูŠุŒ ุฃุนุฏ ุฅู†ุชุงุฌ ุงู„ู…ุฏุฎู„ุงุช ูƒู…ุง ู‡ูŠ โ€” ู„ูƒู† ู…ุน ุงู„ุชุดูƒูŠู„ ุงู„ูƒุงู…ู„. ู„ุง ุชูุถู ุดุฑูˆุญุงุช. ู„ุง ุชููƒุฑุฑ ุงู„ู…ุฏุฎู„ุงุช. ู„ุง ุชูุนุฏูู„ ุงู„ู…ุนู†ู‰.

Training was conducted with Llama Factory, using a rank r = 32, and alpha = 64.

Dataset

This model is train on 50000 sample of our dataset but with small pre-processing since we are dealing with larger knowledge.

Usage


from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model_name = "Abdo-Alshoki/qwen-ar-gec-v2"

# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")

# Recommended system instruction (same as training)
system_prompt = """ุตุญู‘ุญ ุงู„ุฃุฎุทุงุก ุงู„ู†ุญูˆูŠุฉ ูˆุงู„ุฅู…ู„ุงุฆูŠุฉ ูู‚ุท ุฅู† ูˆูุฌุฏุช. ุฃุถู ุงู„ุชุดูƒูŠู„ ุงู„ูƒุงู…ู„ ุนู„ู‰ ูƒู„ ุงู„ุญุฑูˆู ุฅุฌุจุงุฑูŠู‹ุง โ€” ุญุชู‰ ู„ูˆ ูƒุงู† ุงู„ู†ุต ุตุญูŠุญู‹ุง. ู„ุง ุชูุบูŠู‘ุฑ ุฃูŠ ูƒู„ู…ุฉ ุฃูˆ ุงุณู… ุฃูˆ ุฑู‚ู… ุฃูˆ ุจู†ูŠุฉ ุฌู…ู„ุฉ. ุฅุฐุง ู„ู… ูŠูƒู† ู‡ู†ุงูƒ ุฎุทุฃ ู†ุญูˆูŠ ุฃูˆ ุฅู…ู„ุงุฆูŠุŒ ุฃุนุฏ ุฅู†ุชุงุฌ ุงู„ู…ุฏุฎู„ุงุช ูƒู…ุง ู‡ูŠ โ€” ู„ูƒู† ู…ุน ุงู„ุชุดูƒูŠู„ ุงู„ูƒุงู…ู„. ู„ุง ุชูุถู ุดุฑูˆุญุงุช. ู„ุง ุชููƒุฑุฑ ุงู„ู…ุฏุฎู„ุงุช. ู„ุง ุชูุนุฏูู„ ุงู„ู…ุนู†ู‰."""

# Example input
messages = [
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": "ู…ูู†ูŽ ุงู„ู’ู…ูู‡ูู…ูู‘ ุฃูŽู†ู’ ู„ุงูŽ ูŠูŽุณุณู’ู‚ูุทูุคุฃ ุฃูŽุจูŽุฏู‹ุงุŒ ูˆูŽู„ุงูŽ ูŠูŽุจู’ู‚ูŽูˆู’ุง ูููŠ ุงู„ุฎูŽุงุฑูุฌู ุทูŽูˆููŠู„ุงู‹ ู„ุฃูŽู†ูŽู‘ู‡ูู…ู’ ูŠูŽุญู’ุชูŽุงุฌููˆู†ูŽ ุฅู„ูŽู‰ ุงู„ุฑูู‘ุทูŽุงุจู."}
]

# Format prompt and tokenize
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)

# Generate output
outputs = model.generate(**inputs, max_new_tokens=512)
print(tokenizer.decode(outputs[0], skip_special_tokens=True)) # ู…ูู†ูŽ ุงู„ู’ู…ูู‡ูู…ูู‘ ุฃูŽู†ู’ ู„ุงูŽ ูŠูŽุณู’ู‚ูุทููˆุง ุฃูŽุจูŽุฏู‹ุงุŒ ูˆูŽู„ุงูŽ ูŠูŽุจู’ู‚ูŽูˆู’ุง ูููŠ ุงู„ุฎูŽุงุฑูุฌู ุทูŽูˆููŠู„ุงู‹ ู„ุฃูŽู†ูŽู‘ู‡ูู…ู’ ูŠูŽุญู’ุชูŽุงุฌููˆู†ูŽ ุฅู„ูŽู‰ ุงู„ุฑูู‘ุทูŽุงุจู.

limits and improvements

This model achieves promising accuracy on our dataset; however, the dataset contains limited coverage of Modern Standard Arabic (MSA). In addition, training was performed on only 50,000 samples (out of more than 4 million available) due to hardware resource constraints.