Views
No views yet
gemma-2b-it model, specialized for bidirectional tasks related to the Python pandas library. It was trained on a high-quality, curated dataset to become a reliable assistant for both novice and experienced developers.pandas code.pandas code snippets in clear, easy-to-understand language.transformers library. Ensure you have transformers, accelerate, and bitsandbytes installed.1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4# Model repository on Hugging Face
5model_name = "csmishra952/Pandas-Tutor-Gemma-2B"
6
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForCausalLM.from_pretrained(
9 model_name,
10 device_map="auto",
11 torch_dtype=torch.bfloat16
12)
13
14def get_response(instruction, input_text=""):
15 """A helper function to format the prompt and generate a response."""
16 prompt = f"<bos><start_of_turn>user\n{instruction}\n{input_text}<end_of_turn>\n<start_of_turn>model\n"
17 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
18 outputs = model.generate(**inputs, max_new_tokens=128)
19 result = tokenizer.decode(outputs[0], skip_special_tokens=True)
20 return result.split("model\n")[-1]
21
22# --- Example 1: Code Explanation (Code-to-NL) ---
23explanation = get_response(
24 instruction="Explain what this Pandas code does.",
25 input_text="df.groupby('department')['salary'].agg(['mean', 'max'])"
26)
27print("--- Code Explanation ---")
28print(explanation)
29
30# --- Example 2: Code Generation (NL-to-Code) ---
31generated_code = get_response(
32 instruction="Write the Pandas code to select all rows where the 'product_category' is 'Electronics' and the 'price' is less than 500."
33)
34print("\n--- Generated Code ---")
35print(generated_code)
36⚙️ Training DetailsModel ArchitectureThe model uses a Low-Rank Adaptation (LoRA) architecture. Instead of retraining the entire 2-billion-parameter base model, we freeze the base model and train only a small number of "adapter" matrices. This makes the training process incredibly efficient.┌───────────────────────────┐
37│ │
38│ Frozen Gemma-2B Model │
39│ (2 Billion Parameters) │
40│ │
41└───────────┬───────────────┘
42 │
43┌───────────▼───────────────┐
44│ Trainable LoRA Adapters │
45│ (~0.1% of Parameters) │
46└───────────────────────────┘
47Fine-Tuning TechniqueThe model was fine-tuned using QLoRA, which further optimizes LoRA by loading the base model in a quantized 4-bit precision. This drastically reduces memory consumption, allowing the fine-tuning to be performed on a single T4 GPU in Google Colab.Training HyperparametersHyperparameterValueBase Modelgoogle/gemma-2b-itFine-tuning MethodQLoRALoRA r (Rank)8LoRA alpha32Precision4-bit (nf4)Compute dtypebfloat16OptimizerPaged AdamW (32-bit)Learning Rate2e-4Epochs1Batch Size1 per deviceGradient Accumulation8Training DataThe model was trained on a custom dataset of 181 high-quality examples derived from highly-voted pandas questions and their accepted answers on Stack Overflow. The data was manually cleaned, verified, and structured into a bidirectional, instruction-following format (JSONL).⚖️ LicenseThis model is licensed under the MIT License. You are free to use, modify, and distribute this model for any purpose, including commercial use.✍️ CitationIf you use this model or find this project helpful in your own work, please consider citing it:@misc{pandas_tutor_gemma_mishra,
48 author = {Chandrasekhar Mishra},
49 title = {Pandas-Tutor-Gemma-2B: A Specialized Code Assistant},
50 year = {2025},
51 publisher = {Hugging Face},
52 journal = {Hugging Face repository},
53 howpublished = {\url{[https://huggingface.co/csmishra952/Pandas-Tutor-Gemma-2B](https://huggingface.co/csmishra952/Pandas-Tutor-Gemma-2B)}}
54}