library_name: transformers tags: - peft - lora - tinyllama - instruction-tuning - mathematics - machine-learning - education - domain-adaptation - two-stage-training - gsm8k license: apache-2.0
π§ TinyLlama Math & ML Tutor (LoRA)
A two-stage fine-tuned educational model specialized in Mathematics and Machine Learning
Built on TinyLlama-1.1B β lightweight, fast, and effective for learning & teaching.
π Training Strategy (Two-Stage Fine-Tuning)
This model was developed using a two-stage fine-tuning approach for maximum mathematical depth and instruction-following ability.
π₯ Stage 1: Domain Adaptation (Non-Instruction)
- Dataset: Full textbook β Mathematics of Machine Learning: Master Linear Algebra, Calculus, and Probability for Machine Learning by Tivadar Danka
- Method: Continued pre-training (non-instruction / causal language modeling)
- Goal: Inject deep mathematical knowledge, terminology, and formal reasoning into the base model.
π₯ Stage 2: Instruction Tuning
- Dataset:
openai/gsm8k(main split) - Method: Instruction tuning using
[INST]format - Goal: Teach the model to answer user questions clearly, step-by-step, and in an educational style.
Result: Strong domain expertise + natural instruction following.
π§Ύ Model Details
- Base Model: TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T
- Fine-tuning Method: LoRA (PEFT)
- LoRA Rank (r): 8
- Domain: Mathematics + Machine Learning
- Language: English
- Developed by: Nihal Jaiswal
π§ Prompt Format
Use the following format for best results:
[INST]Your question here[/INST]
π¬ Example Usage
Input:
[INST]What is a vector space? Explain with example.[/INST]
Output: A vector space is a mathematical structure consisting of a set of vectors that can be added together and multiplied by scalars...
βοΈ How to Use (Copy-Paste)
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# Load model
repo_id = "Nihal108-bi/tinyllama-math-instruct-lora"
base_model = "TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T"
tokenizer = AutoTokenizer.from_pretrained(repo_id)
model = AutoModelForCausalLM.from_pretrained(base_model, device_map="auto", torch_dtype="auto")
model = PeftModel.from_pretrained(model, repo_id)
# Generate
prompt = "[INST]Explain gradient descent with an example[/INST]"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(
**inputs,
max_new_tokens=300,
temperature=0.7,
top_p=0.9,
do_sample=True,
repetition_penalty=1.1
)
answer = tokenizer.decode(outputs[0], skip_special_tokens=True).split("[/INST]")[-1].strip()
print(answer)
π― Capabilities
- Strong explanations of Linear Algebra, Calculus, Probability & Statistics
- Clear Machine Learning concepts (Gradient Descent, Bias-Variance, etc.)
- Step-by-step mathematical reasoning
- Educational / tutor-style responses
β οΈ Limitations
- Small 1.1B model β can occasionally hallucinate on very advanced topics
- Best performance on math and ML-related questions
- Not designed for general chit-chat or coding
π Evaluation
Qualitatively evaluated on math & ML reasoning tasks.
| Category | Performance |
|---|---|
| Math Concepts | Strong |
| ML Explanations | Strong |
| Step-by-step Reasoning | Good |
| General Conversation | Limited |
π Credits & Acknowledgments
- Fine-tuned by: Nihal Jaiswal
- Base Model: TinyLlama Team
- Domain Dataset: Tivadar Danka β Mathematics of Machine Learning
- Instruction Dataset: OpenAI GSM8K
π License
Apache 2.0
Made with β€οΈ for students, educators, and ML enthusiasts.
Feel free to use, share, and build upon it!
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support