CoolFace
Modelpublic

ronantakizawa/sarashina2-7b-jreadability

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
2likes9downloads
Model Card

Sarashina2-7B Difficulty-Balanced

<div align="center"> <h3>Japanese Text Generation with Difficulty Control</h3> <p>Fine-tuned for difficulty-aware Japanese text generation with balanced learning and zero Simple text degradation</p> </div>

๐ŸŽฏ Model Overview

This model is a fine-tuned version of sbintuitions/sarashina2-7b designed to generate Japanese text at specified difficulty levels while maintaining high quality across both simple and complex text generation.

Key Achievement: This model achieves zero degradation on Simple text generation while simultaneously improving Complex text performance by +40%.

Source Code

๐Ÿ“Š Performance

MetricBaselineFine-tunedImprovement
Overall Accuracy50.0%76.7%+26.7%
Simple Text93.3%100.0%+6.7% โœ…
Complex Text6.7%53.3%+46.7% โœ…

What This Means

  • โ€”โœ… Zero unlearning - Maintains perfect Simple text generation capability (93.3%)
  • โ€”โœ… Strong Complex gains - Improved Complex text generation from 6.7% to 46.7%
  • โ€”โœ… Balanced learning - Both difficulty levels perform well without trade-offs

๐Ÿ”ฌ Training Methodology

Class Weighting Strategy

The key innovation is 2x class weighting for Simple text:

python
class_weights = {
    'Simple': 1.5,   # 2x gradient emphasis
    'Complex': 1.0   # Normal emphasis
}

This prevents the catastrophic "unlearning" problem where models forget how to generate simple text while learning complex patterns.

Training Configuration

  • โ€”Base Model: sbintuitions/sarashina2-7b (7B parameters)
  • โ€”Method: LoRA (Low-Rank Adaptation) fine-tuning
  • โ€”Dataset: ronantakizawa/japanese-text-difficulty-2level
  • โ€”Training Examples: 1,275 texts (638 Simple, 637 Complex - perfectly balanced)
  • โ€”Validation Examples: 159 texts
  • โ€”Difficulty Metric: jReadability-based scoring (0-1 scale)

Key Features

  1. 1.Balanced 50/50 Dataset - Equal representation prevents bias
  2. 2.No Artificial Length Constraints - Model learns natural linguistic complexity
  3. 3.Class Weighting - Simple text receives 2x gradient influence so complex text doesn't unlearn patterns from simple text
  4. 4.LoRA Fine-tuning - Efficient training with only 40M trainable parameters (0.54%)

Hyperparameters

python
{
  "lora_r": 16,
  "lora_alpha": 32,
  "lora_dropout": 0.1,
  "learning_rate": 1e-4,
  "num_epochs": 3,
  "batch_size": 1,
  "gradient_accumulation_steps": 16,
  "warmup_steps": 200,
  "weight_decay": 0.01,
  "optimizer": "adamw_torch",
  "bf16": true,
  "max_length": 1500
}

๐Ÿ’ป Usage

Installation

bash
pip install transformers peft torch

Basic Usage

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

# Load base model and tokenizer
base_model = AutoModelForCausalLM.from_pretrained(
    "sbintuitions/sarashina2-7b",
    torch_dtype=torch.bfloat16,
    device_map="auto"
)

# Load LoRA adapter
model = PeftModel.from_pretrained(
    base_model,
    "ronantakizawa/sarashina2-7b-difficulty-balanced"
)

tokenizer = AutoTokenizer.from_pretrained(
    "ronantakizawa/sarashina2-7b-difficulty-balanced"
)

# Generate Simple text
prompt = """### ๆŒ‡็คบ
้›ฃๆ˜“ๅบฆใƒฌใƒ™ใƒซใ€ŒSimpleใ€ใฎๆ—ฅๆœฌ่ชžๆ–‡็ซ ใ‚’ๆ›ธใ„ใฆใใ ใ•ใ„ใ€‚ๅŸบๆœฌ็š„ใช่ชžๅฝ™ใจ็ฐกๅ˜ใชๆ–‡ๆณ•ใ‚’ไฝฟ็”จใฎๆ–‡็ซ ใ‚’ไฝœๆˆใ—ใฆใใ ใ•ใ„ใ€‚

### ๅ›ž็ญ”
"""

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
    **inputs,
    max_new_tokens=200,
    temperature=0.8,
    do_sample=True,
    top_p=0.9,
    repetition_penalty=1.1
)

generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_text.split("### ๅ›ž็ญ”\n")[1])

Generate Complex Text

python
prompt = """### ๆŒ‡็คบ
้›ฃๆ˜“ๅบฆใƒฌใƒ™ใƒซใ€ŒComplexใ€ใฎๆ—ฅๆœฌ่ชžๆ–‡็ซ ใ‚’ๆ›ธใ„ใฆใใ ใ•ใ„ใ€‚่ค‡้›‘ใช่ชžๅฝ™ใจ้ซ˜ๅบฆใชๆ–‡ๆณ•ใฎๆ–‡็ซ ใ‚’ไฝœๆˆใ—ใฆใใ ใ•ใ„ใ€‚

### ๅ›ž็ญ”
"""

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
    **inputs,
    max_new_tokens=200,
    temperature=0.8,
    do_sample=True,
    top_p=0.9,
    repetition_penalty=1.1
)

generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_text.split("### ๅ›ž็ญ”\n")[1])

๐Ÿ“š Difficulty Levels

Simple (ๅˆ็ดšใƒฌใƒ™ใƒซ)

Target Audience: Beginner + Elementary Japanese learners

Characteristics:

  • โ€”Basic vocabulary (ๅŸบๆœฌ็š„ใช่ชžๅฝ™)
  • โ€”Simple grammar structures (็ฐกๅ˜ใชๆ–‡ๆณ•)
  • โ€”Common kanji or hiragana-heavy text
  • โ€”Shorter sentences
  • โ€”Everyday topics

jReadability Score Range: 0.0 - 0.5

Complex (ไธŠ็ดšใƒฌใƒ™ใƒซ)

Target Audience: Advanced + Expert Japanese learners

Characteristics:

  • โ€”Advanced vocabulary (่ค‡้›‘ใช่ชžๅฝ™)
  • โ€”Complex grammar patterns (้ซ˜ๅบฆใชๆ–‡ๆณ•)
  • โ€”Advanced kanji usage
  • โ€”Longer, more intricate sentences
  • โ€”Abstract or technical topics

jReadability Score Range: 0.5 - 1.0

๐ŸŽ“ Use Cases

Language Learning

  • โ€”Generate reading materials at appropriate difficulty levels
  • โ€”Create personalized practice texts for learners
  • โ€”Develop adaptive learning curricula

Educational Technology

  • โ€”Automated content generation for Japanese learning apps
  • โ€”Difficulty-graded reading comprehension exercises
  • โ€”Personalized study materials

Content Creation

  • โ€”Generate Japanese text for specific audiences
  • โ€”Create accessibility-focused content (simple versions)
  • โ€”Produce materials for different proficiency levels

Research

  • โ€”Study Japanese text complexity and readability
  • โ€”Analyze linguistic features across difficulty levels
  • โ€”Develop difficulty assessment tools

๐Ÿ“ˆ Evaluation Methodology

jReadability Scoring

The model is evaluated using jReadability, a research-backed Japanese readability metric based on Lee & Hasebe's work.

Formula:

readability = {mean words per sentence} ร— -0.056
            + {percentage of kango} ร— -0.126
            + {percentage of wago} ร— -0.042
            + {percentage of verbs} ร— -0.145
            + {percentage of particles} ร— -0.044
            + 11.724

Normalization: difficulty_score = (6.5 - jreadability_score) / 6.0

Accuracy Calculation

A generated text is considered "accurate" if its jReadability score falls within the target range:

  • โ€”Simple: 0.0 - 0.5
  • โ€”Complex: 0.5 - 1.0

This model achieves the best balance: highest overall accuracy while maintaining perfect Simple text generation.

๐Ÿ“– Dataset

The model was trained on ronantakizawa/japanese-text-difficulty-2level, which contains:

  • โ€”1,594 Japanese texts from Aozora Bunko (้’็ฉบๆ–‡ๅบซ) and Kyoto University's Basic Japanese Dataset
  • โ€”Perfectly balanced: 797 Simple, 797 Complex
  • โ€”jReadability-enhanced: Each text scored using research-backed metrics
  • โ€”Authentic literature: Real Japanese texts, not synthetic data