FixerX: The AI That Turns Math Mishaps into Masterpieces! 🎯✨ | Fine-Tuning DeepSeek-Math for Meme Corrections

Abdullah Grewal
5 min read3 days ago

--

Introduction 🧮

Ever scrolled through social media and spotted a viral math meme that just felt wrong? You’re not alone! From incorrectly solved equations to misleading simplifications, incorrect math spreads like wildfire online. That’s where FixerX comes in — a powerful AI-driven tool designed to correct these viral math mistakes with precision and clarity.

In this blog, I’ll walk you through the end-to-end development of FixerX, including why I chose deepseek-ai/deepseek-math-7b-rl, how I fine-tuned it, the tech stack used, and the challenges I faced along the way.

Let’s dive in! 🚀

Why DeepSeek-Math-7B-R1? 🤖

What is DeepSeek-Math-7B-R1?

DeepSeek-Math-7B-R1 is a powerful open-source model trained specifically for mathematical reasoning. Unlike generic language models, this model excels in solving complex equations, making logical deductions, and handling structured math problems.

Why Did I Choose It?

🔹 Math-Specialized Training — It has been fine-tuned on a vast dataset of mathematical problems, making it perfect for this task.
🔹 Open-Source and Efficient — Unlike proprietary models, it allows customization through LoRA fine-tuning.
🔹 Handles Symbolic Reasoning — Can process symbols, algebraic expressions, and numerical calculations effectively.

How It Works: The model uses a transformer-based architecture to predict mathematical solutions based on a given input. By fine-tuning it on incorrect and corrected math memes, I customized it to recognize and fix common mistakes.

Tech Stack Used 🛠️

🔹 Model: deepseek-ai/deepseek-math-7b-rl
🔹 Fine-Tuning Framework: Hugging Face PEFT + LoRA
🔹 Training Environment: Google Colab / Kaggle
🔹 Dataset: Curated CSV of incorrect math memes and their correct solutions
🔹 Deployment: Streamlit for an interactive UI
🔹 Optimization: Parameter-efficient fine-tuning via LoRA
🔹 Inference & Testing: PyTorch

Step-by-Step: How I Built FixerX 🏗️

Step 1: Preparing the Dataset 📊

I manually collected incorrect math equations and their corrected versions, storing them in a CSV file. Each entry had:
incorrect_equation: The viral math meme's incorrect statement
corrected_equation: The correct mathematical expression

Example Data:

Incorrect Equation Corrected Equation 8 ÷ 2(2+2) = 1 8 ÷ 2 × (2+2) = 16 -³² = 9 -³² = -9

Since I already had the dataset, I skipped the data creation step and moved directly to fine-tuning.

Step 2: Tokenization & Preprocessing 📝

To train the model effectively, I tokenized the dataset using DeepSeek-Math’s tokenizer. However, I ran into some common tokenizer issues:

Error: Missing pad_token
💡 Fix: Set tokenizer.pad_token = tokenizer.eos_token

Error: Inconsistent sequence lengths (ArrowInvalid)
💡 Fix: Standardized tokenization using truncation=True, padding=max_length

def tokenize_function(example):
prompt = f"Incorrect: {example['input']}\nCorrect: {example['output']}"

tokenized_output = tokenizer(prompt, padding="max_length", truncation=True, max_length=512)
return {
"input_ids": tokenized_output["input_ids"],
"attention_mask": tokenized_output["attention_mask"],
"labels": tokenized_output["input_ids"]
}
tokenized_dataset = dataset.map(tokenize_function, batched=False)

Step 3: Fine-Tuning with LoRA 🎯

Instead of full model fine-tuning (which is expensive 💰), I used LoRA (Low-Rank Adaptation) to update only a subset of parameters efficiently.

lora_config = LoraConfig(
task_type=TaskType.CAUSAL_LM,
r=16,
lora_alpha=32,
lora_dropout=0.1,
target_modules=["q_proj", "v_proj"]
)
model = get_peft_model(model, lora_config)
model.print_trainable_parameters()

Why LoRA?

  • Reduces GPU memory usage
  • Speeds up training
  • Maintains model accuracy

Step 4: Training the Model 🚀

To avoid evaluation errors, I disabled validation since I had no separate test set.

training_args = TrainingArguments(
output_dir="./math-meme-corrector",
per_device_train_batch_size=2,
per_device_eval_batch_size=2,
num_train_epochs=100,
save_strategy="epoch",
logging_dir="./logs",
logging_steps=10,
report_to="none",
evaluation_strategy="no",
gradient_accumulation_steps=4,
fp16=True,
push_to_hub=False,
remove_unused_columns=False,
save_total_limit=2,
)

trainer = Trainer(
model=model,
args=training_args,
train_dataset=tokenized_dataset,
)

Step 5: Saving the Model 💾

I encountered an issue where config.json and pytorch_model.bin were not saving correctly.
Solution: Merging LoRA adapters before saving.

from transformers import AutoModelForCausalLM
from peft import PeftModel
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-math-7b-rl")
model = PeftModel.from_pretrained(model, "./math-meme-corrector")
model = model.merge_and_unload()
model.save_pretrained("FixerX_deepseekmath-r1")

Step 6: Building a Streamlit UI 🎨

To make testing fun, I built an interactive Streamlit app that allows users to input incorrect math memes and see real-time corrections!

Result 📝

🔥 Error Rating — Adding Some Fun to Math Fixing! 🎭

To make FixerX more engaging and interactive, I added a fun “Error Rating” feature. Instead of just fixing the incorrect math memes, why not add a bit of personality to the corrections?

This feature randomly assigns a “sass” and “patience” score to each correction, making it entertaining for users. Here’s how it works:

📝 Code for Error Rating:

import random
def error_rating():
sass = random.randint(50, 100)
patience = 100 - sass
return f"{sass}% sass, {patience}% patience!"
print(error_rating())

🛠️ How It Works?

  • The sass percentage represents how blunt or humorous the correction is.
  • The patience percentage shows how gently the AI is handling the correction.
  • Every time a user submits an incorrect math meme, FixerX generates a new Error Rating, making it feel fresh and dynamic.

🧑‍🎓 Example Output:

82% sass, 18% patience!
65% sass, 35% patience!
97% sass, 3% patience!

This makes FixerX not just a math meme corrector but a fun and engaging AI experience! 🤖✨

Final Thoughts & Challenges Faced 🤯

Tokenizer padding issues → Fixed by setting pad_token = eos_token
Dataset format issues → Ensured correct column mapping
Model saving issues → Used LoRA merging before saving
Trainer evaluation errors → Disabled evaluation mode

FixerX is now a fully functional AI tool that corrects viral math memes in real time! 🚀

🔖 Hashtags

#ArtificialIntelligence #AIModel #AIFineTuning #MachineLearningModels #ML #DeepLearningAI #NeuralNetworks #AIDevelopment #AIInnovation #MathAI #MathMemeFixer #MathEducation #MathLover #MathIsFun #Mathematics #MathErrors #MathCorrections #STEM #EdTech#HuggingFace #TransformersAI #NaturalLanguageProcessing #NLP #LanguageModels #AIModels #OpenSourceAI #GenerativeAI#LoRA #LowRankAdaptation #EfficientAI #ModelOptimization #PEFT #ParameterEfficientFineTuning#Streamlit #PythonProgramming #TechTools #DataScience #AIForGood #Colab #Kaggle #DeepSeekMath #AIEngineering #AIResearch

--

--

Abdullah Grewal
Abdullah Grewal

Written by Abdullah Grewal

0 Followers

Caffeine-fueled tech maestro, equally at home, building intelligent AI, machine learning, and NLP models as crafting seamless MERN stack applications.

No responses yet