Downloads · 30 days
0
AlbertoB12/Mistral-7B-Instruct-german-level-tuner
Mistral-7B-Instruct-german-level-tuner is a machine learning model from AlbertoB12. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
This is a fine-tuned version of mistralai/Mistral-7B-Instruct-v0.3, adapted to rephrase German texts between different CEFR (Common European Framework of Reference for Languages) proficiency levels. The model speciali…
Downloads · 30 days
0
Access
Public
Updated Aug 25, 2025
Repo size
672 MB
Likes
0
Public
Click a slice to open those files.
.safetensors671 MB · 99%
From the Hugging Face model README
This is a fine-tuned version of mistralai/Mistral-7B-Instruct-v0.3, adapted to rephrase German texts between different CEFR (Common European Framework of Reference for Languages) proficiency levels. The model specializes in transforming texts between B1, B2, and C1 levels.
The model was trained using a LoRA (Low-Rank Adaptation) adapter, making it parameter-efficient and easy to integrate with the base model.
This project was developed to showcase practical AI applications in the educational technology sector. It is the core model intended to power applications like my KultuRAG - AI Language Learning Assistant project.
mistralai/Mistral-7B-Instruct-v0.3The model takes an instruction, a source text, and its CEFR level as input and generates a rewritten version of the text at the target CEFR level.
This model is designed for educational applications, including:
To use this model, you need to load the base mistralai/Mistral-7B-Instruct-v0.3 model in 4-bit precision and then apply the LoRA adapter.
import torch
from peft import PeftModel
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
# --- Model Configuration ---
base_model_id = "mistralai/Mistral-7B-Instruct-v0.3"
adapter_id = "AlbertoB12/Mistral-7B-Instruct-german-level-tuner"
# --- Quantization Configuration ---
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16
)
# --- Load Tokenizer and Base Model ---
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
base_model = AutoModelForCausalLM.from_pretrained(
base_model_id,
quantization_config=bnb_config,
device_map="auto",
trust_remote_code=True,
)
# --- Load the LoRA Adapter ---
model = PeftModel.from_pretrained(base_model, adapter_id)
# --- Prepare the Prompt ---
# The model was trained with a specific instruction format.
source_level = "C1"
target_level = "B1"
source_text = "Der Krieg stellt stets eine tiefgreifende Zäsur für Gesellschaften dar, da er nicht nur Menschenleben kostet, sondern auch das Vertrauen in politische und soziale Strukturen erschüttert. Umso dringlicher stellt sich die Frage, wie globale Zusammenarbeit gestärkt werden kann, um künftige Generationen vor ähnlichen Katastrophen zu bewahren."
# Format the prompt using the required template
prompt = f"""### Instruction:
Schreibe den folgenden deutschen Text von seinem ursprünglichen GER-Niveau ({source_level}) auf das Zielniveau ({target_level}) um.
### Input:
{source_text}
### Output:
"""
# --- Generate the Response ---
input_ids = tokenizer(prompt, return_tensors="pt", truncation=True).input_ids.cuda()
outputs = model.generate(
input_ids=input_ids,
max_new_tokens=512, # Adjust as needed
do_sample=True,
temperature=0.7,
top_k=50,
top_p=0.95
)
# --- Decode and Print ---
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
output_only = generated_text.split("### Output:")[1].strip()
print(output_only)
The model was trained on a synthetic dataset of 1,895 examples. This dataset was generated by using Google's Gemini model to rewrite German texts from the UniversalCEFR/merlin_de and UniversalCEFR/elg_cefr_de datasets to different CEFR levels. Each entry in the training data follows an "Instruction-Input-Output" format.
The model was fine-tuned using the following key hyperparameters:
num_train_epochs: 3
per_device_train_batch_size: 16
gradient_accumulation_steps: 1
learning_rate: 2e-5
lr_scheduler_type: "cosine"
lora_r: 64
lora_alpha: 128
lora_dropout: 0.05