{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# नोटबुक 4: डीप लर्निंग, आर्टिफिशियल न्यूरॉन और लैंग्वेज मॉडल (LLM)\n", "\n", "अध्याय 5 में हमने **न्यूरल नेटवर्क (Neural Networks) और डीप लर्निंग** के बारे में जाना कि कैसे जैविक दिमाग से प्रेरित होकर आर्टिफिशियल नोड्स (Perceptrons), बैकरोपोगेशन और अत्याधुनिक जेनरेटिव लैंग्वेज मॉडल (LLM) बनाए गए।\n", "\n", "इस अंतिम व्यावहारिक नोटबुक में हम एक आर्टिफिशियल न्यूरॉन का सिमुलेशन करेंगे और एक छोटा सा शब्द-अनुमान लगाने वाला मॉडल (LLM) बनाएंगे!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## प्रयोग 1: आर्टिफिशियल न्यूरॉन (Perceptron) का सिमुलेशन\n", "\n", "एक आर्टिफिशियल न्यूरॉन इनपुट (`x1`, `x2`) लेता है, हर एक को एक वेट (`w1`, `w2`) से गुणा करता है, उसमें बायस (`bias`) जोड़ता है, और यदि कुल योग एक तय सीमा को पार कर जाए तो वह सक्रिय (Activate) हो जाता है।\n", "\n", "आइए एक न्यूरॉन बनाते हैं जो मिट्टी के सूखेपन और फसल की ज़रूरत के हिसाब से तय करता है कि पानी का पंप चालू (ON) करना है या बंद (OFF)।" ] }, { "cell_type": "code", "metadata": {}, "source": [ "class ArtificialNeuron:\n", " def __init__(self, weight1, weight2, bias):\n", " self.w1 = weight1\n", " self.w2 = weight2\n", " self.bias = bias\n", " \n", " def activate(self, x1, x2):\n", " # वेट के साथ योग और बायस जोड़ना\n", " total = (x1 * self.w1) + (x2 * self.w2) + self.bias\n", " # निर्णय: यदि total > 0 है तो 1 (पंप ON), वरना 0 (OFF)\n", " return 1 if total > 0 else 0, total\n", "\n", "# आइए अपने न्यूरॉन को तैयार करते हैं\n", "pump_neuron = ArtificialNeuron(weight1=0.6, weight2=0.8, bias=-0.7)\n", "\n", "# परीक्षण: मिट्टी में सूखापन (0.9) और फसल की ज़रूरत (0.8)\n", "decision, score = pump_neuron.activate(0.9, 0.8)\n", "print(f\"न्यूरॉन का स्कोर: {score:.2f} -> पंप का निर्णय: {'चालू ON (1)' if decision else 'बंद OFF (0)'}\")" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## प्रयोग 2: छोटा लैंग्वेज मॉडल (ChatGPT की तरह अगला शब्द चुनना)\n", "\n", "Gemini या ChatGPT जैसे लार्ज लैंग्वेज मॉडल (LLM) एक मूल सिद्धांत पर काम करते हैं: शब्दों के एक क्रम को देखकर यह अनुमान लगाना कि अगला शब्द क्या होना चाहिए।\n", "\n", "आइए एक छोटे से टेक्स्ट पर अपने मॉडल को ट्रेनिंग देते हैं और देखते हैं कि वह अपने आप वाक्य कैसे बनाता है!" ] }, { "cell_type": "code", "metadata": {}, "source": [ "# हमारा ट्रेनिंग टेक्स्ट (आप इसे बदलकर दोबारा रन कर सकते हैं!)\n", "training_text = \"\"\"\n", "the village farmer goes to the market\n", "the village farmer grows grain in the field\n", "the children go to the school\n", "the children learn science at the school\n", "the market opens in the morning\n", "the school opens in the morning\n", "\"\"\"\n", "\n", "words = training_text.split()\n", "# गिनें कि किस शब्द के बाद कौन सा शब्द आता है\n", "follow_counts = {}\n", "for i in range(len(words) - 1):\n", " curr, next_w = words[i], words[i + 1]\n", " if curr not in follow_counts:\n", " follow_counts[curr] = {}\n", " follow_counts[curr][next_w] = follow_counts[curr].get(next_w, 0) + 1\n", "\n", "def predict_next_word(word):\n", " counts = follow_counts.get(word)\n", " if not counts:\n", " return \"(unknown)\"\n", " return max(counts, key=counts.get)\n", "\n", "# आइए 'the' शब्द से शुरू करके एक वाक्य बनाते हैं\n", "current_word = \"the\"\n", "generated = [current_word]\n", "for _ in range(7):\n", " current_word = predict_next_word(current_word)\n", " generated.append(current_word)\n", "\n", "print(\"हमारे छोटे LLM द्वारा बनाया गया वाक्य:\", \" \".join(generated))" ], "execution_count": null, "outputs": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3" } }, "nbformat": 4, "nbformat_minor": 5 }