<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ali Abdelaal on Medium]]></title>
        <description><![CDATA[Stories by Ali Abdelaal on Medium]]></description>
        <link>https://medium.com/@aliabdelaal?source=rss-2248ca8a8eb2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wllZF5hYLmmoUPcrtM1iaA.jpeg</url>
            <title>Stories by Ali Abdelaal on Medium</title>
            <link>https://medium.com/@aliabdelaal?source=rss-2248ca8a8eb2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 10:51:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aliabdelaal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Introduction to Machine learning in Arabic]]></title>
            <link>https://aliabdelaal.medium.com/introduction-to-machine-learning-in-arabic-94358cba8ec6?source=rss-2248ca8a8eb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/94358cba8ec6</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[arabic]]></category>
            <category><![CDATA[gradient-descent]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Ali Abdelaal]]></dc:creator>
            <pubDate>Sat, 02 Jan 2021 00:51:30 GMT</pubDate>
            <atom:updated>2021-01-02T00:51:30.751Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MLQ2t4TJEhE7yznm0Qsmog.png" /><figcaption>Photo credit: Unsplash</figcaption></figure><p>في هذا المقال البسيط سوف نتعرض بشئ من التفصيل عن ماهية تعليم الآلة ما المقصود بها تحديدا و كيف تتعلم الآلة مع التطرق لبعض التفاصيل الرياضية لهذه العملية</p><p>مجال تعلم الآلة او (machine learning) هو احد فروع الذكاء الاصطناعي و يشتمل بداخله علم التعلم العميق (deep learning)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*8pO_PPC-74Bi4ycEdh1-VA.png" /></figure><p>و عرفه العالم آرثر سامويل</p><blockquote>ان تعطي اجهزة الكمبيوتر القدرة على التعلم بدون ان تتم برمجتها بشكل صريح</blockquote><p>لتوضيح هذا العنوان بشكل افضل، لنستعرض الفرق بين البرمجة الحرفية و تعليم الآلة بشكل مبسط</p><h3>البرمجة التقليدية (الحرفية)</h3><p>لنقل على سبيل المثال اننا نود ان نميز بين اذا ما كان في الصورة قطة ام لا</p><figure><a href="https://images.unsplash.com/photo-1520315342629-6ea920342047?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=1000&amp;q=80"><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Wgqn_Gp2WuAV10M9CbcGUA.png" /></a></figure><p>ففي حالة البرمجة التقليدية سوف نقوم بوضع جميع القواعد التي تحتاجها الآلة حتى تميز هذا القطة مثل ان اذنها يجب ان تكون مثلثة الشكل قليلا و ان وجهها يجب ان يكون دائريا نوعا ما و ايضا ان تحتوى على فراء، وهكذا إلى اخر القواعد التي يمكنك كتابتها</p><p>وفي حالة ان احد هذه القواعد لم تماثل ماقمت بتعريفه لن نتمكن من ان نتعرف على القطة في الصورة للاسف.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*_iXbV8t8HOAJrqEhreuqww.png" /><figcaption>مثال لكود يعتمد على القواعد</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*nln-prN1UEOGQmceLY8Hhg.png" /></figure><p>بالطبع يمكنك الملاحظة ان هنا لن نتمكن من تغطية جميع المواصفات التي تميز القط، ناهيك عن اختلاف القرب او البعد عن الصورة على سبيل المثال او تغيير مكان القطة في الصورة او حتى طريقة تحديد هذه المواصفات</p><p>بالتالي هذه ليست الطريقة الافضل في هذه المهمة، لذا تعالى معي نستعرض الطريقة الاخرى و هي باستخدام تعليم الآلة</p><h3>طريقة تعليم الآلة (التعلم من البيانات)</h3><p>في هذه الطريقة نعتمد بالاساس على ان نوفر صور مختلفة لقطط و اي شئ غير القطط و نترك الامر لما سوف ندعوه <strong>نموذج</strong> كي يتعلم ماهية القط و كيف يمكنه تمييزه عن غيرها من الاشياء.</p><p>بالطبع هذه الطريقة تعتمد على ان يتوفر صور عدة للقطط وكذلك لغير القطط حتى يتمكن نوذجنا من معرفة القط من غيره و من هذا المنطلق تنشأ الحاجة الى كثير من البيانات حتى نتمكن من عمل نوذج قوي يمكنه التمييز، و توفر البيانات بكثرة في العقد الاخير سمح بتقدم هائل في مجال تعلم الآلة والذكاء الصناعي بشكل عام.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VX_jbx7InPIJuaNdZEa5PA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*eoTnVva8Y_Zvesp2-hPVmQ.png" /></figure><p>حسنا عرفنا الآن الفرق الاساسي بين التعلم من البيانات و الطرق المعتمدة على البيانات التي يطلق عليها (data driven approaches) وكذلك الطرق التي تعتمد على ان نعطيها القواعد التي تم تصميمها يدويا (rule based approaches).</p><p>ولكن كيف للآلة ان تتعلم هكذا صفات؟ و ان تفهم النمط المتواجد في البيانات و بناءا عليه تمييز البيانات الجديدة التي لم يراها من قبل؟</p><p>لنفهم هذا دعنا ننظر الى مثال بسيط في هذا الشأن</p><h3>استخراج النمط من البيانات</h3><p>لنقل على سبيل المثال ان لديك منزل تريد ان تبيعه، ولا تعرف اي سعر قد يكون مناسب لك و لكنك تعلم ان اخر 3 بيوت تم بيعهم في المنطقة المحيطة لك كانت اسعارهم و مواصفاتهم كالاتى</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*_MDxFqzwbfiK94CC-BBzZQ.png" /></figure><p>و لديك مواصفات منزلك و الذي يقع في <strong>الطابق الثاني</strong> و مساحته <strong>220</strong> اذا ما هو السعر المناسب لمنزلك؟</p><p>بالطبع يمكننا ان نقوم بتحويل هذه المسألة إلى معادلات في متغيريين كما يلي</p><p>اذا اعتبرنا ان الطابق هو متغير X و ان المساحة هي متغير Y اذا يمكننا ان نصف اول منزلين كما يلي</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*PmpySQWVX2GbaZzPZajDHA.png" /></figure><p>نستطيع حل هاتان المعادلتان سويا و استخراج X بدلالة Y ثم ايجاد قيمتهما سويا كما يلي</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*KkXYwDXAdTbh29YutvpgPg.png" /></figure><p>و هكذا يمكننا ان نحسب ثمن المنزل الذي نريد ان نبيعه كالتالي</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*CHNsTRH1aUrTfdBdUCU2lA.png" /></figure><p>هنا يمكنك تفسير قيمة X و Y على انهم اهمية الطابق الذي تقع .فيه الشقة و مساحتها على الترتيب</p><p>بالتالي هنا نرى ان اهمية الطابق قيمتها 100 و اهمية المساحة قيمتها 30.</p><p>ما فعلناه للتو هو تخصيص ما يسمى <strong>اوزان او(weights)</strong> للمتغيرات او الخصائص التي لدينا وهي الطابق و المساحة، وهذا هو المبدأ الأساسي الذي تقوم عليه عملية التعلم اذ نقوم بتخصيص وزن لكل متغير يصف البيت او ما يسمى (feature) و نقوم بحساب هذه الاوزان.</p><p>دعنا نرى كيف تقوم الآلة بعمل هذه العملية.</p><h3>كيفية حساب الاوزان</h3><p>لنكمل على المثال السابق، دعنا نقول ان المنزل يتم توصيفه بعدد من المتغيرات N، مثل مساحته، الطابق، المحافظة ، وهكذا.</p><p>و ان لدينا عدد m من المنازل وهي التي سنقوم من خلالها بحساب الاوزان الخاصة بكل متغير وسوف نرمز لهذه الاوزان برمز W اذا دعنا نرى المعادلة الخاصة بالمنزل رقم i والذي سعره Y</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*yF1JMzoXhBxUsvMnotTY8Q.png" /></figure><p>في هذه المعادلة يمكنك ان ترى ان كل خاصية في المنزل مخصص لها وزن محدد و ان تكلفة المنزل هي محصلة ضرب كل وزن في الخاصية المحدد لها، وطبعا لن يمكننا حساب هذه الاوزان عن طريق معادلة واحدة، وانما عدد m من المعادلات، و الذي هو عدد المنازل كما تذكر</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*TdUSDlZKRPeOjxU7yLvL2A.png" /></figure><p>الآن كيف نقوم بحساب هذه المتغيرات؟، بالطبع يمكننا حسابه بنفس الطريقة التي قمنا بها بالاعلى، إلا ان هذه الطريقة سوف تكون مكلفة حسابيا بشكل كبير و ربما نتعرض في مقال اخر لمدى تعقيدها، ولكن لحسن الحظ هناك طريقة اخرى اكثر فعالية و اسرع في حسابها و هي النزول التدريجي او (gradient descent)</p><p>لنفهم هذه الطريقة دعنا نقوم بتعريف المشكلة بشكل اخر.</p><h3>النزول التدريجي (gradient descent)</h3><h3>توصيف المشكلة</h3><p>دعنا الان نعبر عن المشكلة بشكل افضل، كما هو موضح بالشكل ادناه.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RvP3Uz_1XRUjdo6xxqTtUg.png" /></figure><p>سنتبع طريقة لذيذة هنا، دعنا نخمن ما هي افضل قيمة للاوزان و لنقل مثلا صفر و نرى كيف سنتكون النتيجة؟</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J9PpCyyhLMA8bzPNuxf6bg.png" /></figure><p>كما يمكنك ان ترى، جميع المنازل الان صار سعرها صفر لان ببساطة كل منزل يتم حساب سعره كما يلي</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*YHwX7Ae5UaBVvk9DEiWIiQ.png" /></figure><blockquote>الرمز Y^ يعبر عن التوقعات</blockquote><p>اذا صفر ليس القيمة الصحيحة للاوزان و نحتاج الى تغيرها، اذا ما الرقم الذي نحتاجه؟ و ما هو الرقم الافضل لكل متغير؟</p><p>في البداية دعنا نرى مدى الخطأ الذي ادى اليه الصفر ثم ننظر كيف يمكننا ان نقلل هذا الخطأ تدريجيا اذا، ولحساب هذا الخطأ سوف نستخدم الفرق بين توقعنا والسعر الصحيح ولاننا يمكن في مرحلة ما ان يصبح لدينا قيم سالبة سوف نرفع القيمة للأس الثاني كما هو موضح بالمعادلة ادناه</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*CaHzR7Fqh6scSSdn94AKwA.png" /></figure><p>هذه هي معادلة الخطأ لنقطة واحدة، فمثلا في حالتنا هذه يصبح الخطأ في أول مثال قيمته كالتالي</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*ALalEYb5UNMxvGVnpKK0gQ.png" /></figure><p>و هكذا نحتاج لمعرفة الخطا على مستوى جميع المنازل التي لدينا والتي عددها m كما قلنا من قبل، لذلك سوف نقوم بحساب حاصل جمع كل الاخطاء على مستوى المنازل كلها و كما ترى لان الرقم كبير نسبيا سوف نقوم بأخذ المتوسط لهذه المحصلة ليصبح الرقم اقل قليلا ولكن مازال معبرا عن الخطأ فقط ابسط في الحسابات</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*uqU51KfWZoN-zoPt_T-2_g.png" /></figure><p>الان اصبح لديك معادلة تعبر عن مدى الخطأ في توقعاتنا ومدى بعد توقعاتنا عن الصواب بالتالي كلما قلت هذه المعادلة كقيمة كلما كانت توقعاتنا صحيحة لان عندما تكون التوقعات سليمة يصبح</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/188/1*8l31rnqaflqd4-sBcKsWzQ.png" /></figure><p>و بالتالي سيصبح الخطأ الكلي صفر</p><p>اذا هدفنا الان هو ان نصل لطريقة تمكننا من تقليل قيمة هذه المعادلة وهنا يأتي دور التفاضل اذا كنت تذكره، ان لم تكن تذكره فسوف نتذكره سويا في الفقرة التالية</p><h3>تطبيق التفاضل في تعلم الآلة</h3><p>تفاضل دالة ما هو معدل تغير قيمتها بالنسبة لمتغير من متغيراتها فعلى سبيل المثال في الدالة الآتية عندما نقوم بحساب معدل تغير Y بالنسبة ل X نحن نقوم بطرح سؤال و هو اذا قمنا بتغيير قيمة X كم ستتأثر Y و ايضا يمكننا طرح سؤال اخر و هو اين اتجاه زيادة قيمة Y بالنسبة ل X بمعنى، هل نحتاج ان نرفع قيمة X ام نخفضها حتى تزيد قيمة Y</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*kzdZsnarAUWWJ6u1fFoXQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/149/1*dTxEKIy608JCWOo7sB5YBA.png" /></figure><p>اذا كنت تتذكر قواعد التفاضل فانك ستتذكر ان تفاضل هذه الدالة هو 2x</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/152/1*vjjzYAinfrYyFFdO6dzntg.png" /></figure><p>و قد تلاحظ هنا ان التفاضل يحتوي على متغير، اي ان قيمة التفاضل تختلف بختلاف مكانك في الدالة و اذا قمنا باختبار ذلك في موضعين مختلفين في الدالة على سبيل المثال سنجد ان قيمة التفاضل بالفعل تختلف لنرى كيف</p><p>التفاضل يمكن حسابه عن طريق الميل او ال (slope) بين نقطتين في الدالة و سوف نقوم بحساب التغيير بناءا على ذلك اولا بين نقطتين هما</p><p>(7, 49), (8, 64)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*DRx5nHPbMARgYorIQhHOJQ.png" /></figure><p>اذا معدل التغيير هنا هو 15 و ايضا كما تلاحظ 2x حيث x = 7.5</p><p>و الان لنرى قيمة التفاضل بين نقطتين اخرتيين</p><p>(1, 1), (2, 4)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*IvcGDnhQzn3hmKT_-gxhdw.png" /></figure><p>سنجد ان معدل التغير اختلف عن المكان السابق و قيمته هنا 3</p><p>نسنتنج مما سبق ان معدل التغير في الدالة يختلف من مكان لاخر بها و لذلك يوجد متغير x في معادلة التفاضل و ايضا نستطيع ان نرى مما سبق ان التفاضل عند النقتطين كان قيمته موجبة اي ان مع زيادة X سوف تزداد قيمة Y على عكس اذا ما حسبنا التفاضل بين نقطتين سالبتين مثلا</p><p>(-2, -4) (-1, -1)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*qwC63eTwPPznX7B11nKx-Q.png" /></figure><p>نجد في الجزء السالب من هذه الدالة ان زيادة X سوف تقلل من قيمة Y ولهذا يظهر التفاضل بقيمة سالبة</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u3GhzpjJd48lo0EihJncnw.png" /></figure><p>اذا التفاضل يمكنه اخبارنا اين هو اتجاه زيادة الدالة بالنسبة لمتغير معين وبالتالي فإن عكس هذا الاتجاه سيكون هو اتجاه النقصان، اذا عند اي نقطة في الدالة اذا فاضلناها سنعلم اي اتجاه نحتاج ان نسير اليه لتقليل قيمة هذه الدالة وهذا ايضا ليس لمتغير واحد وانما لاكثر متغير اذ انه يمكنك ان تفاضل الدالة لاكثر من متغير و سوف تحصل على اتجاه الزيادة لكل متغير، اذا كنت تتساءل عن شكل الدالة في حالة ان بها اكثر من متغيرين فهي كالشكل الآتي</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*Ybsk_icu7uIoh5lWl-PG2A.png" /><figcaption><a href="https://users.cs.duke.edu/~rongge/images/nonconvex.PNG">مصدر الصورة</a></figcaption></figure><p>في هذه الحالة نقوم بحساب التفاضل بالنسبة لكل متغير على حدى و نرى لكل متغير على حدى ما علاقته بالدالة بشكل عام وما التغيير الذي نحتاج ان نقوم به حتى تزداد الدالة بشكل عام فبالتالي نستطيع ان نوجد اتجاه نقصانها</p><h3>كيفية استخدام التفاضل في تحسين توقعاتنا</h3><p>الآن لدينا مجموعة من الاوزان (weights) التي خصصناها لمجموعة من ال (features) او الخصائص التي من المفترض ان من خلالها سنستطيع ان نستنتج سعر اي منزل جديد، ولدينا ايضا معادلة الخطا التي تقيم مدى قربنا او بعدنا عن الصواب و الذي هو بدوره تقييم للاوزان نفسها كما رأينا في مثال الصفر بالأعلى</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*haoY0xBxRysKHWJq9pzNrg.png" /></figure><p>وبالنظر إلى المعادلة التي استنتجنا منها Y^ سنجد انها معادلة في الاوزان بالاساس</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*EyROBg-DkEAIxALGKVYOyA.png" /></figure><p>واذا عبرنا عن الاوزان كلها ب W و الخصائص كلها ب X يمكننا التعبير عن نوذجنا كالتالي</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/1*NcMp7bvRdBSVxs76Y3kOFQ.png" /></figure><p>بالتالي معادلة الخطأ تصبح</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*Wxa3tvSE2ua4ZgR24WSJzg.png" /></figure><p>الان يمكننا استخدام التفاضل لنوجد اتجاه الزيادة لهذه المعادلة و بالتالي عكسه سوف يكون اتجاه النقصان و بالتالي يمكننا ان نعدل كل وزن ليسير في اتجاه النقصان الخاص بالدالة.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*-P92aOQe8JAFgv75Jm0JSg.png" /></figure><p>تعال معي نستوضح الموضوع بشكل ابسط</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TsLjkEXZ6YgeHqK0byq5PQ.png" /></figure><p>في هذا الرسم نوضح العلاقة بين الخطأ و احد الاوزان ونرى هنا ان عند تغيير الوزن نحصل على قيم مختلفة للخطأ و كذلك يوجد لكل وزن المستوى الخاص به و اذا جمعنا الاوزان كلها سوف ننتهي برسم اشبه بالشكل الآتي ولكن في ابعاد اكثر لا يمكن رسمها</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*kvUR13rIg4EFqdL7tTzPdg.png" /><figcaption><a href="https://miro.medium.com/max/1000/0*1DCc3JBWmSMlt-0r.png">مصدر الصورة</a></figcaption></figure><p>الان وبفضل التفاضل يمكننا ان نحدث قيمة الوزن في الاتجاه الذي ينقص الدالة الكلية و هو الاتجاه المعاكس للتفاضل الذي حسبناه بالاعلى وبالتالي يمكننا بعد حساب الخطا ان نحدث قيمة الوزن كما يلي</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*8HXs9o_GhYYGJK1zoBJcqA.png" /></figure><p>هنا يمكنك ان ترى اننا نحدث قيمة الوزن الجديد بان يصبح الوزن القديم طرح التفاضل مضروب بمعامل η و هو يعبر عن مستوى التعلم او (learning rate) و سوف نتعرض له في مقال اخر بإذن الله</p><p>وهكذا تتغير قيمة الاوزان لتصبح قيمة جديدة تتسبب في انخفاض الخطأ بشكل عام.</p><h3>الشكل الكلي</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MT-OiLWPb8S5huCMf4phDw.png" /></figure><p>اذا هذا هو تسلسل خطوات النوذج الذي قمنا ببنائه للتو</p><ul><li>تخصيص وزن لكل خاصية</li><li>ابتداء قيمة هذه الاوزان بصفر او الافضل ان نبدأهم بقيم عشوائية</li><li>حساب التوقات بناءا على هذه الاوزان</li><li>حساب الخطأ من هذه التوقعات</li><li>حساب التفاضل بالنسبة لكل وزن وايجاد اتجاه النقصان لكل منهم</li><li>تحديث الاوزان و الرجوع للنقطة الثالثة</li></ul><p>يمكنم ان ترى ان هذه السلسلة قد تستمر للأبد، ولكن يتم وضع شروط للتوقف مثل ان تمر بهذه العملية عدد معين من المرات او ان يكون التغيير في معادلة الخطأ اقل من قيمة معينة.</p><p>تسمى هذه العملية بالتدريب او التعلم (training/learning) و بعد انتهاء هذه العملية يصبح لدينا اوزان للمتغيرات التي لدينا و يمكننا بناءا عليها ان نتوقع سعر اي منزل قادم بأن نقوم بإدخال متغيرات المنزل في معادلتنا الاساسية بعد حساب الاوزان</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*15BTZJA_pI5dEgi67T2UKQ.png" /></figure><h3>اشكال اخرى لتعلم الآلة</h3><p>ما قمنا بتغطيته للتو هو نوع من انواع تعلم الآلة حيث يكون ما نحاول توقعه قيمة مستمرة يمكن ان تكون اي رقم من سالب مالانهاية إلى مالانهاية و يسمى هذا النوع من النماذج بإسم (regression models) و لكن هذا ليس النوع الوحيد يوجد انواع اخرى تقع جميعها تحت مسمى التعلم تحت الاشراف (suprevised learning)، و هو باختصار وجود بيانات صحيحة نحاول التعلم منها.</p><p>وهنا بعض انواع نماذج تعلم الآلة</p><p>التعلم بإشراف (suprevised learning) حيث يتواجد امثلة و يتواجد ايضا التوقع الصحيح لها</p><ul><li>Regression حيث التوقعات يمكن ان تكون قيم مستمرة</li><li>Classification حيث التوقعات يمكن انت تكون بين قيم محددة مثل قط او كلب</li></ul><p>التعلم بدون اشراف (unsuprevised learning) حيث يتواجد امثلة ولكن لا يوجد توقع صحيح لها</p><ul><li>Clustering حيث نقوم بإيجاد مجموعات متشابهة داخل البيانات</li></ul><h3>الاستنتاج</h3><p>في هذا المقال تعرضنا بشكل بسيط لماهية تعلم الآلة وكيف يمكن للآلة ان تتعلم من البيانات بشكل مبسط وبتغطية مايوجد خلف مصطلح تعلم الآلة</p><blockquote>في هذا المقال حاولت تبسيط بعض المصطلحات للغتنا العربية من اجل تسهيل عملية الشرح ولتبسيط المعلومة، في حالة اي خطأ املائي او اقتراح افضل للترجمة فأنا ارحب جدا بذلك يمكنك التعليق على المقال او مراسلتي لتعديل و تحسين المحتوى، ووفقنا الله وإياكم لما يحب ويرضى.</blockquote><p>إذا اعجبك المقال يمكنك الإطلاع على مدونتي حيث المقال الاصلي</p><p><a href="https://aliabdelaal.github.io/blog/intro-to-ml/">https://aliabdelaal.github.io/blog/intro-to-ml/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94358cba8ec6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Telegram bot tutorial using python and flask]]></title>
            <link>https://aliabdelaal.medium.com/telegram-bot-tutorial-using-python-and-flask-1fc634da9522?source=rss-2248ca8a8eb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fc634da9522</guid>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[webhooks]]></category>
            <category><![CDATA[telegram]]></category>
            <category><![CDATA[flask]]></category>
            <dc:creator><![CDATA[Ali Abdelaal]]></dc:creator>
            <pubDate>Sat, 18 May 2019 16:19:13 GMT</pubDate>
            <atom:updated>2019-05-18T16:19:13.746Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*TcoMKnacm1JPXLN87mB4HQ.png" /><figcaption>image <a href="https://www.wikitechy.com/technology/wp-content/uploads/2017/05/Telegram-Bots.png">source</a></figcaption></figure><p>in this tutorial you will learn how to make a telegram bot and deploy it on a Heroku server, the bot will be up 24–7, and you can inject your own brain and responses into it.</p><h3>Before we start</h3><p>you will need to have the following</p><ul><li>a <a href="https://signup.heroku.com/">heroku</a> free account</li><li>a <a href="https://telegram.org/">telegram</a> account of course</li></ul><h3>Create the bot on telegram first</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*JgGRY2JCwxCZ8VmktsdQiQ.png" /></figure><p>before we dive into coding, let’s finish the easy stuff, we need to ask telegram to create a new bot on the platform, it’s a fairly simple process, you can do so in your telegram app(on <a href="https://telegram.org/apps">windows/linux/android/ios/web</a>) you need to go to <a href="https://telegram.me/botfather">botfather</a> which is basically a bot himself that automate the process of creating your bot.</p><p>you will need to ask him using the / prefix to start a command, once you start typing it will autocomplete itself, the command you need is /newbot, which will take you to the flow of creating your bot, the bot will prompt you for a name and username for the bot (the username has to be unique), then it will respone with a message like so</p><pre>Done! Congratulations on your new bot. You will find it at t.me/{bot-username}. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you&#39;ve finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this.</pre><pre>Use this token to access the HTTP API:<br>{the-bot-token-which-we-will-use-later}<br>Keep your token secure and store it safely, it can be used by anyone to control your bot.</pre><pre>For a description of the Bot API, see this page: <a href="https://core.telegram.org/bots/api">https://core.telegram.org/bots/api</a></pre><p>congratulations you now have your bot on the platform!</p><h3>Coding the bot engine</h3><p>before we start please note the following</p><ul><li>i assume you use Python3</li><li>also my environment is Ubuntu 18, it’s unlikely that this will affect your project thought.</li></ul><p>now let’s dive into some code, let’s start of by creating a <a href="https://docs.python.org/3/library/venv.html">virtualenv</a> for our project, in your terminal type</p><pre>$ python -m venv venv/</pre><p>now you will have a venv/ directory which will have all the python libraries we will be using, go ahead and activate the virtualenv using the following command</p><pre>$ source venv/bin/activate</pre><p>now let’s have some libs installed</p><pre>(venv) $ pip install flask<br>(venv) $ pip install python-telegram-bot<br>(venv) $ pip install requests</pre><p>that’s all we need for now, let’s structure our project in a neat way before we start the real coding</p><pre>.<br>├── app.py<br>├── telebot<br>│   ├── credentials.py<br>│   ├── mastermind.py<br>│   |   .<br>│   |   you can build your engine here<br>│   |   .<br>│   └── __init__.py<br>└── venv</pre><p>in the credentials.py file we will need three variables</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e81d8d9e3b4a8c88715afed2772d6b91/href">https://medium.com/media/e81d8d9e3b4a8c88715afed2772d6b91/href</a></iframe><p>in mastermind.py you could use your super AI to generate response</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afaeb591011b291812701c816cf0225a/href">https://medium.com/media/afaeb591011b291812701c816cf0225a/href</a></iframe><p>now let’s go back to our app.py and go throw the code step by step</p><pre># import everything<br>from flask import Flask, request<br>import telegram<br>from telebot.credentials import bot_token, bot_user_name,URL<br>from telebot.mastermind import get_response</pre><p>now let’s create global objects for the bot and the token</p><pre>global bot<br>global TOKEN<br>TOKEN = bot_token<br>bot = telegram.Bot(token=TOKEN)</pre><p>at this point we have the bot object which is connected to your actual bot using the token you have copied from the botfather message we saw earlier.</p><pre># start the flask app<br>app = Flask(__name__)</pre><p>now we need to bind functions to specific routes, in other words, we need to tell flask what to do when a specific address is called, more info about flask and route can be found <a href="http://flask.pocoo.org/docs/1.0/quickstart/">here</a></p><p>here the route function respond to a url which is basically /{token} which is the url telegram will call to get responses for the messages sent to him.</p><pre>@app.route(&#39;/{}&#39;.format(TOKEN), methods=[&#39;POST&#39;])<br>def respond():<br>    # retrieve the message in JSON and then transform it to Telegram object<br>    update = telegram.Update.de_json(request.get_json(force=True), bot)</pre><pre># get the chat_id to be able to respond to the same user<br>    chat_id = update.message.chat.id<br>    # get the message id to be able to reply to this specific message<br>    msg_id = update.message.message_id</pre><pre># Telegram understands UTF-8, so encode text for unicode compatibility<br>    text = update.message.text.encode(&#39;utf-8&#39;).decode()<br>    print(&quot;got text message :&quot;, text)</pre><pre># here we call our super AI<br>    response = get_response(text)</pre><pre># now just send the message back<br>    # notice how we specify the chat and the msg we reply to<br>    bot.sendMessage(chat_id=chat_id, text=response, reply_to_message_id=msg_id)</pre><pre>return &#39;ok&#39;</pre><p>that’s great but we need to tell telegram to call our app (the one we will create in a minute) so that our function can be invoked, for this we will use <a href="https://www.wikiwand.com/en/Webhook">Webhook</a> which is in a very basic words, a way to let the bot call our server whenever a message is called, so that we don’t need to make our server suffer in a while loop waiting for a message to come.</p><p>the route here can be anything, you the one who will call it</p><pre>@app.route(&#39;/setwebhook&#39;, methods=[&#39;GET&#39;, &#39;POST&#39;])<br>def set_webhook():<br>    # we use the bot object to link the bot to our app which live<br>    # in the link provided by URL<br>    s = bot.setWebhook(&#39;{URL}{HOOK}&#39;.format(URL=URL, HOOK=TOKEN))<br>    # something to let us know things work<br>    if s:<br>        return &quot;webhook setup ok&quot;<br>    else:<br>        return &quot;webhook setup failed&quot;</pre><p>now everything is set, let’s just make a fancy home page so that we know the engine is up</p><pre>@app.route(&#39;/&#39;)<br>def index():<br>    return &#39;.&#39;</pre><p>an app can’t run without a main right</p><pre>if __name__ == &#39;__main__&#39;:<br>    # note the threaded arg which allow<br>    # your app to have more than one thread<br>    app.run(threaded=True)</pre><p>let’s take a look at the full version of the app.py</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/923cf9830f33190f11bc2ec587cb565e/href">https://medium.com/media/923cf9830f33190f11bc2ec587cb565e/href</a></iframe><p>that’s the last code you will write today, now to the last step, launching our app on Heroku.</p><h3>Launch our app on Heroku</h3><p>we need a couple of things before we make our app.</p><ul><li>Heroku can’t know what libraries your project uses, so we have to tell him using the requirements.txt file (a common problem is that you misspell requirements so be careful :D), to generate the requirements file use pip</li></ul><pre>pip freeze &gt; requirements.txt</pre><p>now you have your requirements file ready to go</p><ul><li>second you need the Procfile which tells heroku where our app starts, so create a Procfile file and in it type the following</li></ul><pre>web: gunicorn app:app</pre><ul><li><strong>A bounce step</strong>: you can add <a href="https://github.com/github/gitignore/blob/master/Python.gitignore">.gitignore</a> file to your project so that no-use files don’t get uploaded to the repository.</li><li>from your <a href="https://dashboard.heroku.com/apps">dashboard</a> on Heroku create a new app, once you create an app it will direct you to the deploy page, open the settings tab in new window and copy the domain of the app which will be something like https://appname.herokuapp.com/ and paste it in the URL variable inside our credentials.py</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZQRuo5ovH3o42AJJsphSug.png" /></figure><p>now go back to the deploy tab and proceed with the steps:</p><ul><li>login to heroku</li></ul><pre>$ heruko login</pre><p>note that sometimes this method get stuck in waiting for login, if this is the case with you, you can login using</p><pre>$ heruko login -i</pre><ul><li>Initialize a git repository in our directory</li></ul><pre>$ git init<br>$ heroku git:remote -a {heroku-project-name}</pre><ul><li>Deploy the app</li></ul><pre>$ git add .<br>$ git commit -m &quot;first commit&quot;<br>$ git push heroku master</pre><p>at this point you will see the building progress in your terminal, if everything went okay you will see something like so</p><pre>remote: -----&gt; Launching...<br>remote:        Released v6<br>remote:        <a href="https://project-name.herokuapp.com/">https://project-name.herokuapp.com/</a> deployed to Heroku<br>remote:<br>remote: Verifying deploy... done.</pre><ul><li>Now go to the app page (the link of the domain you copied before) and add to the end of the link /setwebhook so that the address will be something like https://appname.herokuapp.com/setwebhook, if you see webhook setup ok then you are ready to go!</li></ul><h3>Now go talk to your bot</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*WhVfBMzKqPOKbTmLLoMqdA.gif" /><figcaption>a live version of the bot</figcaption></figure><h3>That’s it</h3><p>now you have your telegram bot up and running, you can add whatever logic you want to it, you can even rename it, add profile image or even a description via the botfather channel on your telegram account.</p><p>the complete code can be found in <a href="https://github.com/AliAbdelaal/telegram-bot-tutorial">this repository</a>.</p><p>Hope you had fun building your bot.</p><h3>Additional resources</h3><ul><li><a href="https://www.codementor.io/garethdwyer/building-a-telegram-bot-using-python-part-1-goi5fncay">Building a Chatbot using Telegram and Python</a></li><li><a href="https://medium.com/@xabaras/setting-your-telegram-bot-webhook-the-easy-way-c7577b2d6f72">Setting your Telegram Bot WebHook the easy way</a></li><li><a href="https://github.com/python-telegram-bot/python-telegram-bot">python-telegram-bot Repository</a></li><li><a href="https://devcenter.heroku.com/articles/git">Deploying with Git on Heruko</a></li><li><a href="https://python-telegram-bot.readthedocs.io/en/stable/index.html">Python Telegram Bot’s documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fc634da9522" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>