FixerX: The AI That Turns Math Mishaps into Masterpieces! ๐ŸŽฏโœจ | Fine-Tuning DeepSeek-Math for Meme Corrections

5 min readMar 7, 2025

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