| --- |
| language: |
| - en |
| license: mit |
| base_model: microsoft/Phi-3-mini-4k-instruct |
| tags: |
| - phi-3 |
| - lora |
| - spiritual |
| - ramana-maharshi |
| - advaita-vedanta |
| - self-enquiry |
| - rag |
| pipeline_tag: text-generation |
| --- |
| |
| # Ramana Maharshi Teaching Assistant — Phi-3 Mini LoRA |
|
|
| A LoRA fine-tuned version of [Phi-3-mini-4k-instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct) |
| trained on verified teachings of Sri Ramana Maharshi. |
|
|
| ## Training |
|
|
| - **Base model**: `microsoft/Phi-3-mini-4k-instruct` |
| - **Method**: QLoRA (4-bit NF4) + SFT → DPO |
| - **SFT data**: Single-turn and multi-turn Q&A grounded in canonical texts |
| - **DPO data**: Preference pairs (verified teachings vs. generic responses) |
| - **Canonical sources**: *Who Am I?*, *Talks with Sri Ramana Maharshi*, *Ulladu Narpadu* |
| - **LoRA rank**: 16 | Alpha: 32 | Target: all attention + MLP projection layers |
|
|
| ## Usage |
|
|
| ```python |
| from transformers import AutoTokenizer, AutoModelForCausalLM |
| import torch |
| |
| model_id = "SriRamanaAtmic/AtmicIntel_test" |
| tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True) |
| model = AutoModelForCausalLM.from_pretrained( |
| model_id, |
| torch_dtype = torch.bfloat16, |
| device_map = "auto", |
| trust_remote_code = True, |
| ) |
| |
| SYSTEM = ( |
| "You are a knowledgeable and compassionate guide to the teachings of " |
| "Sri Ramana Maharshi. Answer questions about Self-enquiry, the nature " |
| "of the Self, surrender, and the path to liberation, grounded in his " |
| "actual teachings." |
| ) |
| |
| messages = [ |
| {"role": "system", "content": SYSTEM}, |
| {"role": "user", "content": "What is self-enquiry?"}, |
| ] |
| text = tokenizer.apply_chat_template(messages, tokenize=False, |
| add_generation_prompt=True) |
| inputs = tokenizer(text, return_tensors="pt").to(model.device) |
| |
| with torch.no_grad(): |
| out = model.generate( |
| **inputs, |
| max_new_tokens = 512, |
| temperature = 0.7, |
| top_p = 0.9, |
| repetition_penalty = 1.1, |
| do_sample = True, |
| ) |
| print(tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)) |
| ``` |
|
|
| ## About Sri Ramana Maharshi |
|
|
| Sri Ramana Maharshi (1879–1950) was one of the greatest sages of modern India. |
| His principal teaching was *Atma Vichara* (Self-enquiry): the direct path of |
| tracing the sense of "I" back to its source, the Self — pure, undivided |
| awareness. He is revered across traditions for the simplicity, depth, and |
| transformative power of his teachings. |
|
|