{ "cells": [ { "cell_type": "code", "execution_count": 3, "id": "478d9ad3-eb52-4622-bea7-ac89984fae21", "metadata": { "id": "478d9ad3-eb52-4622-bea7-ac89984fae21" }, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 4, "id": "887779ca-c01e-48c5-b165-75d6544dcd26", "metadata": { "id": "887779ca-c01e-48c5-b165-75d6544dcd26" }, "outputs": [], "source": [ "df=pd.read_csv(\"/content/CompanyReviews.csv\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "ad94225b-f7da-4f14-ae6d-071c10e2e1b2", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 424 }, "id": "ad94225b-f7da-4f14-ae6d-071c10e2e1b2", "outputId": "cc1ba966-13e5-4eb5-9fa1-e56d6c730aea" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " Unnamed: 0 review_description rating \\\n", "0 0 رائع 1 \n", "1 1 برنامج رائع جدا يساعد على تلبيه الاحتياجات بشك... 1 \n", "2 2 التطبيق لا يغتح دائما بيعطيني لا يوجد اتصال با... -1 \n", "3 3 لماذا لا يمكننا طلب من ماكدونالدز؟ -1 \n", "4 4 البرنامج بيظهر كل المطاعم و مغلقه مع انها بتكو... -1 \n", "... ... ... ... \n", "40041 128 تجربه جيده بس ينقصها عدم اهتمام خدمة العملاء ب... 0 \n", "40042 129 انا ساكنة بمنطقة الكينج ولا توجد عربيات قبل ال... -1 \n", "40043 130 جيد ولكن لماذا لا توجد خطوط كثيره من المريوطيه... 0 \n", "40044 131 جيدا جدا ...ولكن الاسعار عاليه جدا\\n 0 \n", "40045 132 التطبيق حلو جدا والخدمه ممتازه ولكن الاسعار عا... 0 \n", "\n", " company \n", "0 talbat \n", "1 talbat \n", "2 talbat \n", "3 talbat \n", "4 talbat \n", "... ... \n", "40041 swvl \n", "40042 swvl \n", "40043 swvl \n", "40044 swvl \n", "40045 swvl \n", "\n", "[40046 rows x 4 columns]" ], "text/html": [ "\n", "
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0review_descriptionratingcompany
00رائع1talbat
11برنامج رائع جدا يساعد على تلبيه الاحتياجات بشك...1talbat
22التطبيق لا يغتح دائما بيعطيني لا يوجد اتصال با...-1talbat
33لماذا لا يمكننا طلب من ماكدونالدز؟-1talbat
44البرنامج بيظهر كل المطاعم و مغلقه مع انها بتكو...-1talbat
...............
40041128تجربه جيده بس ينقصها عدم اهتمام خدمة العملاء ب...0swvl
40042129انا ساكنة بمنطقة الكينج ولا توجد عربيات قبل ال...-1swvl
40043130جيد ولكن لماذا لا توجد خطوط كثيره من المريوطيه...0swvl
40044131جيدا جدا ...ولكن الاسعار عاليه جدا\\n0swvl
40045132التطبيق حلو جدا والخدمه ممتازه ولكن الاسعار عا...0swvl
\n", "

40046 rows × 4 columns

\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "variable_name": "df", "summary": "{\n \"name\": \"df\",\n \"rows\": 40046,\n \"fields\": [\n {\n \"column\": \"Unnamed: 0\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 11553,\n \"min\": 0,\n \"max\": 39540,\n \"num_unique_values\": 39541,\n \"samples\": [\n 36701,\n 36873,\n 10182\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"review_description\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 39003,\n \"samples\": [\n \"\\u0644\\u064a\\u0647 \\u0645\\u0627 \\u0641\\u064a\\u0634 \\u062a\\u0648\\u0635\\u064a\\u0644 \\u0641\\u064a \\u0628\\u0648\\u0644\\u0627\\u0642 \\u0627\\u0644\\u062f\\u0643\\u0631\\u0648\\u0631 \\u0644\\u0645\\u0637\\u0627\\u0639\\u0645 \\u0643\\u062b\\u064a\\u0631\",\n \"\\u0633\\u0631\\u0639\\u0629 \\u0627\\u0644\\u062a\\u0648\\u0635\\u064a\\u0644 \\u0645\\u0645\\u062a\\u0627\\u0632\\u0629\",\n \"\\u062a\\u0637\\u0628\\u064a\\u0642 \\u0645\\u0645\\u062a\\u0627\\u0632 \\u0648\\u0633\\u0647\\u0644 \\u0634\\u0643\\u0631\\u0627\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"rating\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": -1,\n \"max\": 1,\n \"num_unique_values\": 3,\n \"samples\": [\n 1,\n -1,\n 0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"company\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 12,\n \"samples\": [\n \"TMG\",\n \"capiter\",\n \"talbat\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" } }, "metadata": {}, "execution_count": 5 } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 6, "id": "9e667bc0-7cbb-4d84-a268-988dcb73e833", "metadata": { "id": "9e667bc0-7cbb-4d84-a268-988dcb73e833" }, "outputs": [], "source": [ "df = df[[\"review_description\", \"rating\"]].copy()" ] }, { "cell_type": "code", "execution_count": 7, "id": "c991e6ed-6102-4827-89f7-912dd97906d1", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 424 }, "id": "c991e6ed-6102-4827-89f7-912dd97906d1", "outputId": "4eb5f935-433f-4b75-ff01-83b1223a4e39" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " review_description rating\n", "0 رائع 1\n", "1 برنامج رائع جدا يساعد على تلبيه الاحتياجات بشك... 1\n", "2 التطبيق لا يغتح دائما بيعطيني لا يوجد اتصال با... -1\n", "3 لماذا لا يمكننا طلب من ماكدونالدز؟ -1\n", "4 البرنامج بيظهر كل المطاعم و مغلقه مع انها بتكو... -1\n", "... ... ...\n", "40041 تجربه جيده بس ينقصها عدم اهتمام خدمة العملاء ب... 0\n", "40042 انا ساكنة بمنطقة الكينج ولا توجد عربيات قبل ال... -1\n", "40043 جيد ولكن لماذا لا توجد خطوط كثيره من المريوطيه... 0\n", "40044 جيدا جدا ...ولكن الاسعار عاليه جدا\\n 0\n", "40045 التطبيق حلو جدا والخدمه ممتازه ولكن الاسعار عا... 0\n", "\n", "[40046 rows x 2 columns]" ], "text/html": [ "\n", "
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
review_descriptionrating
0رائع1
1برنامج رائع جدا يساعد على تلبيه الاحتياجات بشك...1
2التطبيق لا يغتح دائما بيعطيني لا يوجد اتصال با...-1
3لماذا لا يمكننا طلب من ماكدونالدز؟-1
4البرنامج بيظهر كل المطاعم و مغلقه مع انها بتكو...-1
.........
40041تجربه جيده بس ينقصها عدم اهتمام خدمة العملاء ب...0
40042انا ساكنة بمنطقة الكينج ولا توجد عربيات قبل ال...-1
40043جيد ولكن لماذا لا توجد خطوط كثيره من المريوطيه...0
40044جيدا جدا ...ولكن الاسعار عاليه جدا\\n0
40045التطبيق حلو جدا والخدمه ممتازه ولكن الاسعار عا...0
\n", "

40046 rows × 2 columns

\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "variable_name": "df", "summary": "{\n \"name\": \"df\",\n \"rows\": 40046,\n \"fields\": [\n {\n \"column\": \"review_description\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 39003,\n \"samples\": [\n \"\\u0644\\u064a\\u0647 \\u0645\\u0627 \\u0641\\u064a\\u0634 \\u062a\\u0648\\u0635\\u064a\\u0644 \\u0641\\u064a \\u0628\\u0648\\u0644\\u0627\\u0642 \\u0627\\u0644\\u062f\\u0643\\u0631\\u0648\\u0631 \\u0644\\u0645\\u0637\\u0627\\u0639\\u0645 \\u0643\\u062b\\u064a\\u0631\",\n \"\\u0633\\u0631\\u0639\\u0629 \\u0627\\u0644\\u062a\\u0648\\u0635\\u064a\\u0644 \\u0645\\u0645\\u062a\\u0627\\u0632\\u0629\",\n \"\\u062a\\u0637\\u0628\\u064a\\u0642 \\u0645\\u0645\\u062a\\u0627\\u0632 \\u0648\\u0633\\u0647\\u0644 \\u0634\\u0643\\u0631\\u0627\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"rating\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": -1,\n \"max\": 1,\n \"num_unique_values\": 3,\n \"samples\": [\n 1,\n -1,\n 0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" } }, "metadata": {}, "execution_count": 7 } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 8, "id": "83df5c97-b49b-4431-8b0a-7a0f73219259", "metadata": { "id": "83df5c97-b49b-4431-8b0a-7a0f73219259" }, "outputs": [], "source": [ "df[\"rating\"] = df[\"rating\"].replace({1: \"إيجابي\",-1: \"سلبي\",0: \"محايد\"})\n" ] }, { "cell_type": "code", "execution_count": 9, "id": "d4011ad3-17b0-401b-8f6b-03d5e6c8bb9c", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 363 }, "id": "d4011ad3-17b0-401b-8f6b-03d5e6c8bb9c", "outputId": "8c401798-fd32-4d7c-f556-bcf6c3fa95eb" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " review_description rating\n", "0 رائع إيجابي\n", "1 برنامج رائع جدا يساعد على تلبيه الاحتياجات بشك... إيجابي\n", "2 التطبيق لا يغتح دائما بيعطيني لا يوجد اتصال با... سلبي\n", "3 لماذا لا يمكننا طلب من ماكدونالدز؟ سلبي\n", "4 البرنامج بيظهر كل المطاعم و مغلقه مع انها بتكو... سلبي\n", "5 أصبح غالي جداً سلبي\n", "6 جميل جدا رائع. . . إيجابي\n", "7 للأسف الواحد ينصدم بعد زيادة الاسعار و للاسف ب... سلبي\n", "8 برنامج توترز توصيل احلى من برنامجكم فاشل سلبي\n", "9 كتير في تحسن خدمة العملاء لطفين في بعض الاخطاء... إيجابي" ], "text/html": [ "\n", "
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
review_descriptionrating
0رائعإيجابي
1برنامج رائع جدا يساعد على تلبيه الاحتياجات بشك...إيجابي
2التطبيق لا يغتح دائما بيعطيني لا يوجد اتصال با...سلبي
3لماذا لا يمكننا طلب من ماكدونالدز؟سلبي
4البرنامج بيظهر كل المطاعم و مغلقه مع انها بتكو...سلبي
5أصبح غالي جداًسلبي
6جميل جدا رائع. . .إيجابي
7للأسف الواحد ينصدم بعد زيادة الاسعار و للاسف ب...سلبي
8برنامج توترز توصيل احلى من برنامجكم فاشلسلبي
9كتير في تحسن خدمة العملاء لطفين في بعض الاخطاء...إيجابي
\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "variable_name": "df", "summary": "{\n \"name\": \"df\",\n \"rows\": 40046,\n \"fields\": [\n {\n \"column\": \"review_description\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 39003,\n \"samples\": [\n \"\\u0644\\u064a\\u0647 \\u0645\\u0627 \\u0641\\u064a\\u0634 \\u062a\\u0648\\u0635\\u064a\\u0644 \\u0641\\u064a \\u0628\\u0648\\u0644\\u0627\\u0642 \\u0627\\u0644\\u062f\\u0643\\u0631\\u0648\\u0631 \\u0644\\u0645\\u0637\\u0627\\u0639\\u0645 \\u0643\\u062b\\u064a\\u0631\",\n \"\\u0633\\u0631\\u0639\\u0629 \\u0627\\u0644\\u062a\\u0648\\u0635\\u064a\\u0644 \\u0645\\u0645\\u062a\\u0627\\u0632\\u0629\",\n \"\\u062a\\u0637\\u0628\\u064a\\u0642 \\u0645\\u0645\\u062a\\u0627\\u0632 \\u0648\\u0633\\u0647\\u0644 \\u0634\\u0643\\u0631\\u0627\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"rating\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 3,\n \"samples\": [\n \"\\u0625\\u064a\\u062c\\u0627\\u0628\\u064a\",\n \"\\u0633\\u0644\\u0628\\u064a\",\n \"\\u0645\\u062d\\u0627\\u064a\\u062f\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" } }, "metadata": {}, "execution_count": 9 } ], "source": [ "df.head(10)" ] }, { "cell_type": "code", "execution_count": 10, "id": "b443e76d-5d83-4369-93d1-d38441fdc5a5", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "id": "b443e76d-5d83-4369-93d1-d38441fdc5a5", "outputId": "0046ad83-32a0-496a-f745-b76047f5a654" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "'مافيش إشارة برسالة الطيار ياريت وده شيء سيئ جدًا 👎'" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 10 } ], "source": [ "df[\"review_description\"][100]" ] }, { "cell_type": "code", "execution_count": 11, "id": "c742d9de-5fa3-41f5-9f80-9de2e310482a", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "id": "c742d9de-5fa3-41f5-9f80-9de2e310482a", "outputId": "6cfa8717-012a-4a7c-a9f8-e49510164a56" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "'نننقمىنررنركرململنيمرزرتبملنلدملنلللنااظاظلظل'" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 11 } ], "source": [ "df[\"review_description\"][500]" ] }, { "cell_type": "code", "execution_count": 12, "id": "6e4c3bb7-39e0-4ca7-8483-0d714a87ea3d", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 147 }, "id": "6e4c3bb7-39e0-4ca7-8483-0d714a87ea3d", "outputId": "ad2145b8-ac7f-4d0e-d7ae-22c18bcc3f65" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "review_description 1\n", "rating 0\n", "dtype: int64" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0
review_description1
rating0
\n", "

" ] }, "metadata": {}, "execution_count": 12 } ], "source": [ "df.isna().sum()" ] }, { "cell_type": "code", "execution_count": 13, "id": "416ce6ec-e545-4af4-af89-429a35ccc9ab", "metadata": { "id": "416ce6ec-e545-4af4-af89-429a35ccc9ab" }, "outputs": [], "source": [ "df = df.dropna()" ] }, { "cell_type": "code", "execution_count": 14, "id": "eb41f4e7-9371-4f8f-b6d7-9f48464965a6", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "eb41f4e7-9371-4f8f-b6d7-9f48464965a6", "outputId": "1b08f2df-8e44-418a-f1e1-4553a768e38a" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "np.int64(941)" ] }, "metadata": {}, "execution_count": 14 } ], "source": [ "df.duplicated().sum()" ] }, { "cell_type": "code", "execution_count": 15, "id": "cc590346-8f67-418a-b490-c56313272006", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 175 }, "id": "cc590346-8f67-418a-b490-c56313272006", "outputId": "1c63967d-e512-441d-edd5-a46562d30538" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " review_description rating\n", "count 40045 40045\n", "unique 39003 3\n", "top ممتاز إيجابي\n", "freq 16 23921" ], "text/html": [ "\n", "
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
review_descriptionrating
count4004540045
unique390033
topممتازإيجابي
freq1623921
\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "summary": "{\n \"name\": \"df\",\n \"rows\": 4,\n \"fields\": [\n {\n \"column\": \"review_description\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 4,\n \"samples\": [\n 39003,\n \"16\",\n \"40045\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"rating\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 4,\n \"samples\": [\n 3,\n \"23921\",\n \"40045\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" } }, "metadata": {}, "execution_count": 15 } ], "source": [ "df.describe()" ] }, { "cell_type": "code", "execution_count": 16, "id": "c674b4a5-0a94-497f-b493-32a699a8ddec", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 210 }, "id": "c674b4a5-0a94-497f-b493-32a699a8ddec", "outputId": "39a38e34-bb16-44d1-ed82-cdeea2b90166" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "rating\n", "إيجابي 23921\n", "سلبي 14199\n", "محايد 1925\n", "Name: count, dtype: int64" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
count
rating
إيجابي23921
سلبي14199
محايد1925
\n", "

" ] }, "metadata": {}, "execution_count": 16 } ], "source": [ "df[\"rating\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 17, "id": "2969cae4-97e7-4099-a26e-ab4e7aaabfce", "metadata": { "id": "2969cae4-97e7-4099-a26e-ab4e7aaabfce" }, "outputs": [], "source": [ "df = df.drop_duplicates(subset=[\"review_description\"])" ] }, { "cell_type": "code", "execution_count": 18, "id": "d6ad9068-38ca-4f0c-9cdf-fd6676487095", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "d6ad9068-38ca-4f0c-9cdf-fd6676487095", "outputId": "44841b15-c990-4999-ac37-d9c749a5f8b7" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "np.int64(0)" ] }, "metadata": {}, "execution_count": 18 } ], "source": [ "df.duplicated().sum()" ] }, { "cell_type": "code", "execution_count": 19, "id": "bea25222-18ad-4f46-954c-29755ebd9e9d", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 490 }, "id": "bea25222-18ad-4f46-954c-29755ebd9e9d", "outputId": "85f6ac07-1be0-48a0-a98c-ea22799333ea" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "review_description\n", "من 6890\n", "جدا 5879\n", "في 5579\n", "و 4181\n", "تطبيق 3766\n", " ... \n", "وارجعوا 1\n", "السبب؟؟؟ 1\n", "اعتراض 1\n", "نقدم 1\n", "تنتشر 1\n", "Name: count, Length: 55351, dtype: int64" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
count
review_description
من6890
جدا5879
في5579
و4181
تطبيق3766
......
وارجعوا1
السبب؟؟؟1
اعتراض1
نقدم1
تنتشر1
\n", "

55351 rows × 1 columns

\n", "

" ] }, "metadata": {}, "execution_count": 19 } ], "source": [ "df[\"review_description\"].str.split().explode().value_counts()" ] }, { "cell_type": "code", "execution_count": 20, "id": "22c539c5-fd44-4cba-b426-699f9b0e3d37", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "22c539c5-fd44-4cba-b426-699f9b0e3d37", "outputId": "1685bca5-4b38-4eda-b0bb-a6e2360648b0" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Collecting camel-tools\n", " Downloading camel_tools-1.6.0-py3-none-any.whl.metadata (10 kB)\n", "Requirement already satisfied: cachetools>=6.0.0 in /usr/local/lib/python3.13/dist-packages (from camel-tools) (6.2.6)\n", "Collecting camel-kenlm>=2026.02.07 (from camel-tools)\n", " Downloading camel_kenlm-2026.2.7-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.metadata (250 bytes)\n", "Requirement already satisfied: dill>=0.4.0 in /usr/local/lib/python3.13/dist-packages (from camel-tools) (0.4.1)\n", "Collecting docopt (from camel-tools)\n", " Downloading docopt-0.6.2.tar.gz (25 kB)\n", " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", "Requirement already satisfied: editdistance in /usr/local/lib/python3.13/dist-packages (from camel-tools) (0.8.1)\n", "Collecting emoji (from camel-tools)\n", " Downloading emoji-2.16.0-py3-none-any.whl.metadata (5.7 kB)\n", "Requirement already satisfied: future in /usr/local/lib/python3.13/dist-packages (from camel-tools) (1.0.0)\n", "Collecting muddler (from camel-tools)\n", " Downloading muddler-0.1.3-py3-none-any.whl.metadata (7.5 kB)\n", "Requirement already satisfied: numpy>=2.0.0 in /usr/local/lib/python3.13/dist-packages (from camel-tools) (2.4.6)\n", "Requirement already satisfied: pandas in /usr/local/lib/python3.13/dist-packages (from camel-tools) (2.2.3)\n", "Collecting pyrsistent (from camel-tools)\n", " Downloading pyrsistent-0.20.0-py3-none-any.whl.metadata (27 kB)\n", "Requirement already satisfied: regex in /usr/local/lib/python3.13/dist-packages (from camel-tools) (2025.11.3)\n", "Requirement already satisfied: requests in /usr/local/lib/python3.13/dist-packages (from camel-tools) (2.32.4)\n", "Collecting scikit-learn>=1.8.0 (from camel-tools)\n", " Downloading scikit_learn-1.9.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.metadata (9.3 kB)\n", "Requirement already satisfied: scipy in /usr/local/lib/python3.13/dist-packages (from camel-tools) (1.16.3)\n", "Requirement already satisfied: six in /usr/local/lib/python3.13/dist-packages (from camel-tools) (1.17.0)\n", "Requirement already satisfied: tabulate in /usr/local/lib/python3.13/dist-packages (from camel-tools) (0.9.0)\n", "Requirement already satisfied: torch>=2.0 in /usr/local/lib/python3.13/dist-packages (from camel-tools) (2.14.1+cpu)\n", "Requirement already satisfied: tqdm in /usr/local/lib/python3.13/dist-packages (from camel-tools) (4.67.3)\n", "Requirement already satisfied: transformers>=4.44.0 in /usr/local/lib/python3.13/dist-packages (from camel-tools) (5.22.1)\n", "Requirement already satisfied: joblib>=1.4.0 in /usr/local/lib/python3.13/dist-packages (from scikit-learn>=1.8.0->camel-tools) (1.6.0)\n", "Requirement already satisfied: narwhals>=2.0.1 in /usr/local/lib/python3.13/dist-packages (from scikit-learn>=1.8.0->camel-tools) (2.28.0)\n", "Requirement already satisfied: threadpoolctl>=3.5.0 in /usr/local/lib/python3.13/dist-packages (from scikit-learn>=1.8.0->camel-tools) (3.7.0)\n", "Requirement already satisfied: cloudpickle>=3.0 in /usr/local/lib/python3.13/dist-packages (from joblib>=1.4.0->scikit-learn>=1.8.0->camel-tools) (3.1.2)\n", "Requirement already satisfied: filelock in /usr/local/lib/python3.13/dist-packages (from torch>=2.0->camel-tools) (4.2.7)\n", "Requirement already satisfied: typing-extensions>=4.10.0 in /usr/local/lib/python3.13/dist-packages (from torch>=2.0->camel-tools) (4.16.0)\n", "Requirement already satisfied: setuptools>=77.0.3 in /usr/local/lib/python3.13/dist-packages (from torch>=2.0->camel-tools) (80.10.2)\n", "Requirement already satisfied: sympy>=1.13.3 in /usr/local/lib/python3.13/dist-packages (from torch>=2.0->camel-tools) (1.14.0)\n", "Requirement already satisfied: networkx>=2.5.1 in /usr/local/lib/python3.13/dist-packages (from torch>=2.0->camel-tools) (3.7)\n", "Requirement already satisfied: jinja2 in /usr/local/lib/python3.13/dist-packages (from torch>=2.0->camel-tools) (3.1.6)\n", "Requirement already satisfied: fsspec>=0.8.5 in /usr/local/lib/python3.13/dist-packages (from torch>=2.0->camel-tools) (2025.12.0)\n", "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.13/dist-packages (from sympy>=1.13.3->torch>=2.0->camel-tools) (1.3.0)\n", "Requirement already satisfied: huggingface-hub<3.0,>=1.31.0 in /usr/local/lib/python3.13/dist-packages (from transformers>=4.44.0->camel-tools) (1.33.0)\n", "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.13/dist-packages (from transformers>=4.44.0->camel-tools) (26.3)\n", "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.13/dist-packages (from transformers>=4.44.0->camel-tools) (6.0.3)\n", "Requirement already satisfied: tokenizers<0.24.0,>=0.23.1 in /usr/local/lib/python3.13/dist-packages (from transformers>=4.44.0->camel-tools) (0.23.3)\n", "Requirement already satisfied: typer in /usr/local/lib/python3.13/dist-packages (from transformers>=4.44.0->camel-tools) (0.27.3)\n", "Requirement already satisfied: safetensors>=0.8.0 in /usr/local/lib/python3.13/dist-packages (from transformers>=4.44.0->camel-tools) (0.8.0)\n", "Requirement already satisfied: click<9.0.0,>=8.4.2 in /usr/local/lib/python3.13/dist-packages (from huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (8.5.0)\n", "Requirement already satisfied: hf-xet<2.0.0,>=1.6.0 in /usr/local/lib/python3.13/dist-packages (from huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (1.8.0)\n", "Requirement already satisfied: httpx<1,>=0.23.0 in /usr/local/lib/python3.13/dist-packages (from huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (0.28.1)\n", "Requirement already satisfied: anyio in /usr/local/lib/python3.13/dist-packages (from httpx<1,>=0.23.0->huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (4.16.0)\n", "Requirement already satisfied: certifi in /usr/local/lib/python3.13/dist-packages (from httpx<1,>=0.23.0->huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (2026.10.23)\n", "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.13/dist-packages (from httpx<1,>=0.23.0->huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (1.0.9)\n", "Requirement already satisfied: idna in /usr/local/lib/python3.13/dist-packages (from httpx<1,>=0.23.0->huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (3.20)\n", "Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.13/dist-packages (from httpcore==1.*->httpx<1,>=0.23.0->huggingface-hub<3.0,>=1.31.0->transformers>=4.44.0->camel-tools) (0.16.0)\n", "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.13/dist-packages (from jinja2->torch>=2.0->camel-tools) (3.0.4)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.13/dist-packages (from pandas->camel-tools) (2.9.0.post0)\n", "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.13/dist-packages (from pandas->camel-tools) (2025.2)\n", "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.13/dist-packages (from pandas->camel-tools) (2026.6)\n", "Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.13/dist-packages (from requests->camel-tools) (3.4.9)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.13/dist-packages (from requests->camel-tools) (2.5.0)\n", "Requirement already satisfied: shellingham>=1.3.0 in /usr/local/lib/python3.13/dist-packages (from typer->transformers>=4.44.0->camel-tools) (1.5.4)\n", "Requirement already satisfied: rich>=13.8.0 in /usr/local/lib/python3.13/dist-packages (from typer->transformers>=4.44.0->camel-tools) (13.9.4)\n", "Requirement already satisfied: annotated-doc>=0.0.2 in /usr/local/lib/python3.13/dist-packages (from typer->transformers>=4.44.0->camel-tools) (0.0.5)\n", "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.13/dist-packages (from rich>=13.8.0->typer->transformers>=4.44.0->camel-tools) (4.2.0)\n", "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.13/dist-packages (from rich>=13.8.0->typer->transformers>=4.44.0->camel-tools) (2.21.0)\n", "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.13/dist-packages (from markdown-it-py>=2.2.0->rich>=13.8.0->typer->transformers>=4.44.0->camel-tools) (0.1.2)\n", "Downloading camel_tools-1.6.0-py3-none-any.whl (125 kB)\n", "Downloading camel_kenlm-2026.2.7-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (3.3 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m21.9 MB/s\u001b[0m \u001b[33m0:00:00\u001b[0m\n", "\u001b[?25hDownloading scikit_learn-1.9.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (9.1 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m9.1/9.1 MB\u001b[0m \u001b[31m69.0 MB/s\u001b[0m \u001b[33m0:00:00\u001b[0m\n", "\u001b[?25hDownloading emoji-2.16.0-py3-none-any.whl (610 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m610.9/610.9 kB\u001b[0m \u001b[31m21.6 MB/s\u001b[0m \u001b[33m0:00:00\u001b[0m\n", "\u001b[?25hDownloading muddler-0.1.3-py3-none-any.whl (16 kB)\n", "Downloading pyrsistent-0.20.0-py3-none-any.whl (58 kB)\n", "Building wheels for collected packages: docopt\n", " Building wheel for docopt (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", " Created wheel for docopt: filename=docopt-0.6.2-py2.py3-none-any.whl size=13781 sha256=5c866cbd1d70a1ac75fce9f6db76329aaec288ffb37b5c44aa9e591582d0e744\n", " Stored in directory: /root/.cache/pip/wheels/0b/1d/03/175286677fb5a1341cc3e4755bf8ec0ed08f3329afd67446b0\n", "Successfully built docopt\n", "Installing collected packages: docopt, camel-kenlm, pyrsistent, muddler, emoji, scikit-learn, camel-tools\n", "\u001b[2K Attempting uninstall: scikit-learn\n", "\u001b[2K Found existing installation: scikit-learn 1.6.1\n", "\u001b[2K Uninstalling scikit-learn-1.6.1:\n", "\u001b[2K Successfully uninstalled scikit-learn-1.6.1\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7/7\u001b[0m [camel-tools]\n", "\u001b[1A\u001b[2KSuccessfully installed camel-kenlm-2026.2.7 camel-tools-1.6.0 docopt-0.6.2 emoji-2.16.0 muddler-0.1.3 pyrsistent-0.20.0 scikit-learn-1.9.1\n" ] } ], "source": [ "pip install camel-tools" ] }, { "cell_type": "code", "execution_count": 21, "id": "98d4b7a5-e664-4026-8589-c9002d1c9853", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "98d4b7a5-e664-4026-8589-c9002d1c9853", "outputId": "9ecc3a2f-3d8e-4fb7-9bf3-111af6c02e47" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Collecting pyspellchecker\n", " Downloading pyspellchecker-0.9.1-py3-none-any.whl.metadata (9.3 kB)\n", "Downloading pyspellchecker-0.9.1-py3-none-any.whl (7.2 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7.2/7.2 MB\u001b[0m \u001b[31m14.6 MB/s\u001b[0m \u001b[33m0:00:00\u001b[0m\n", "\u001b[?25hInstalling collected packages: pyspellchecker\n", "Successfully installed pyspellchecker-0.9.1\n" ] } ], "source": [ "%pip install pyspellchecker" ] }, { "cell_type": "code", "execution_count": 22, "id": "c18208c2-8915-44ba-9519-fb6659539822", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "c18208c2-8915-44ba-9519-fb6659539822", "outputId": "39b6bb00-74a4-4be9-b5bd-89057bcd6382" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "The following packages will be installed: 'morphology-db-msa-r13'\n" ] }, { "output_type": "stream", "name": "stderr", "text": [ "Downloading package 'morphology-db-msa-r13': 100%|\u001b[32m██████████\u001b[0m| 40.5M/40.5M [00:01<00:00, 32.2MB/s]\n", "Extracting package 'morphology-db-msa-r13': 100%|\u001b[32m██████████\u001b[0m| 40.5M/40.5M [00:00<00:00, 525MB/s]\n" ] }, { "output_type": "stream", "name": "stdout", "text": [ "The following packages will be installed: 'disambig-mle-calima-msa-r13', 'morphology-db-msa-r13'\n" ] }, { "output_type": "stream", "name": "stderr", "text": [ "Downloading package 'disambig-mle-calima-msa-r13': 100%|\u001b[32m██████████\u001b[0m| 88.7M/88.7M [00:02<00:00, 35.6MB/s]\n", "Extracting package 'disambig-mle-calima-msa-r13': 100%|\u001b[32m██████████\u001b[0m| 88.7M/88.7M [00:00<00:00, 751MB/s]\n", "Downloading package 'morphology-db-msa-r13': 100%|\u001b[32m██████████\u001b[0m| 40.5M/40.5M [00:00<00:00, 83.7MB/s]\n", "Extracting package 'morphology-db-msa-r13': 100%|\u001b[32m██████████\u001b[0m| 40.5M/40.5M [00:00<00:00, 518MB/s]" ] }, { "output_type": "stream", "name": "stdout", "text": [ "اكتمل تنزيل البيانات\n" ] }, { "output_type": "stream", "name": "stderr", "text": [ "\n" ] } ], "source": [ "from camel_tools.data import CATALOGUE\n", "\n", "CATALOGUE.download_package(\n", " \"morphology-db-msa-r13\",\n", " force=True,\n", " print_status=True\n", ")\n", "\n", "CATALOGUE.download_package(\n", " \"disambig-mle-calima-msa-r13\",\n", " force=True,\n", " print_status=True\n", ")\n", "\n", "print(\"اكتمل تنزيل البيانات\")\n" ] }, { "cell_type": "code", "execution_count": 23, "id": "56d6a65f-705a-4108-a016-85967e98a83a", "metadata": { "id": "56d6a65f-705a-4108-a016-85967e98a83a" }, "outputs": [], "source": [ "import re\n", "import html\n", "import unicodedata\n", "import emoji\n", "import nltk\n", "\n", "from nltk.corpus import stopwords\n", "from spellchecker import SpellChecker\n", "\n", "from camel_tools.utils.normalize import (\n", " normalize_unicode,\n", " normalize_alef_ar,\n", " normalize_alef_maksura_ar,\n", " normalize_teh_marbuta_ar,\n", ")\n", "from camel_tools.utils.dediac import dediac_ar\n", "from camel_tools.tokenizers.word import simple_word_tokenize\n", "from camel_tools.disambig.mle import MLEDisambiguator\n", "\n", "\n", "# تحميل الكلمات الشائعة\n", "nltk.download(\"stopwords\", quiet=True)\n", "ARABIC_STOPWORDS = set(stopwords.words(\"arabic\"))\n", "\n", "# تحميل نموذج التحليل الصرفي\n", "mle = MLEDisambiguator.pretrained()\n", "\n", "# تحميل قاموس التصحيح الإملائي العربي\n", "spell = SpellChecker(language=\"ar\", distance=1)" ] }, { "cell_type": "code", "execution_count": 24, "id": "6659902b-b092-4269-9124-f6e2722ff1c7", "metadata": { "id": "6659902b-b092-4269-9124-f6e2722ff1c7" }, "outputs": [], "source": [ "def clean_review(text, morphology=\"lemma\", correct_spelling=True):\n", " \"\"\"\n", " morphology:\n", " \"lemma\" : الصيغة المعجمية الأساسية\n", " \"stem\" : الساق الصرفية\n", " \"root\" : الجذر عند توفره\n", " None : دون معالجة صرفية\n", "\n", " correct_spelling:\n", " True : تفعيل التصحيح الإملائي\n", " False : تعطيله\n", " \"\"\"\n", "\n", " if morphology not in (\"lemma\", \"stem\", \"root\", None):\n", " raise ValueError(\"morphology يجب أن تكون lemma أو stem أو root أو None\")\n", "\n", "\n", " # 2. Unicode توحيد وتحويل المدخل إلى نص\n", " text = normalize_unicode(str(text))\n", "\n", " # 3. فك رموز HTML وحذف الوسوم\n", " text = html.unescape(text)\n", " text = re.sub(r\"<[^>]+>\", \" \", text)\n", "\n", " # 4. حذف الروابط قبل حذف الحروف الإنجليزية\n", " text = re.sub(r\"(?:https?://|www\\.)\\S+\",\" \",text,flags=re.IGNORECASE,)\n", "\n", " # 5. حذف البريد الإلكتروني\n", " text = re.sub(r\"[\\w.+-]+@[\\w.-]+\\.[^\\W\\d_]{2,}\",\" \",text,)\n", "\n", " # 6. تحويل الإيموجي إلى أوصاف عربية\n", " text = emoji.demojize(text,language=\"ar\",delimiters=(\" \", \" \"),).replace(\"_\", \" \")\n", "\n", " # 7. تحويل الأسطر والتبويبات إلى مسافات\n", " text = re.sub(r\"\\s+\", \" \", text)\n", "\n", " # 8. حذف المحارف المخفية ومحارف التحكم\n", " text = \"\".join(\n", " char\n", " for char in text\n", " if unicodedata.category(char) not in {\"Cf\", \"Cc\", \"Cs\"}\n", " )\n", "\n", " # 9. حذف التشكيل\n", " text = dediac_ar(text)\n", "\n", " # 10. حذف التطويل\n", " text = text.replace(\"ـ\", \"\")\n", "\n", " # 11. توحيد الكاف والياء الفارسيتين في جميع المواضع\n", " text = text.translate(str.maketrans({\n", " \"ک\": \"ك\",\n", " \"ی\": \"ي\",\n", " \"ے\": \"ي\",}))\n", "\n", " # 12. تحويل الإنجليزية إلى حروف صغيرة\n", " text = text.lower()\n", "\n", " # توحيد الفاصلة العليا لتسهيل مطابقة العبارات الإنجليزية\n", " text = text.replace(\"’\", \"'\").replace(\"‘\", \"'\")\n", "\n", " # 13. ترجمة الكلمات والعبارات الموجودة في القاموس\n", " translations = {\n", " \"doesn't work\": \"لا يعمل\",\n", " \"does not work\": \"لا يعمل\",\n", " \"not good\": \"ليس جيد\",\n", " \"not bad\": \"ليس سيئ\",\n", " \"very good\": \"جيد جدا\",\n", " \"thank you\": \"شكرا لك\",\n", " \"don't\": \"لا\",\n", " \"excellent\": \"ممتاز\",\n", " \"amazing\": \"رائع\",\n", " \"great\": \"رائع\",\n", " \"terrible\": \"فظيع\",\n", " \"awful\": \"سيئ جدا\",\n", " \"good\": \"جيد\",\n", " \"bad\": \"سيئ\",\n", " \"slow\": \"بطيء\",\n", " \"fast\": \"سريع\",\n", " \"expensive\": \"غالي\",\n", " \"cheap\": \"رخيص\",\n", " \"thanks\": \"شكرا\",\n", " \"application\": \"تطبيق\",\n", " \"app\": \"تطبيق\",\n", " \"service\": \"خدمة\",\n", " \"delivery\": \"توصيل\",\n", " \"uninstall\": \"الغاء التثبيت\",\n", " \"not\": \"ليس\",\n", " \"no\": \"لا\",\n", " }\n", "\n", " pattern = (r\"(?\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
review_descriptionrating
0رائعإيجابي
1برنامج رائع جد ساعد تنبيه احتياج شكل اسرعإيجابي
2تطبيق لا فتح دائم اعطي لا وجد اتصال شبكه الان ...سلبي
3لماذا لا امكن طلب ماكدونالدسلبي
4برنامج اظهر مطعم مغلق ان كان فتح بقال كد اكتري...سلبي
.........
37996تجربه جيد نقص عدم اهتمام خدمه عميل عميل تواصل ...محايد
37997كان منطقه الكينج وجد عربه ساعه نصف وجه ابتسامه...سلبي
37998جيد لماذا لا وجد خط كثير المريوطيه فيصل نادي ر...محايد
37999جيد جد سعر عالي جدمحايد
38000تطبيق حلو جد خدمه ممتاز سعر عالي شويمحايد
\n", "

38001 rows × 2 columns

\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " \n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "variable_name": "df", "summary": "{\n \"name\": \"df\",\n \"rows\": 38001,\n \"fields\": [\n {\n \"column\": \"review_description\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 33643,\n \"samples\": [\n \"\\u0627\\u0633\\u0641 \\u0633\\u0639\\u0631 \\u0627\\u063a\\u0644\\u064a \\u0645\\u062d\\u0644 \\u062a\\u062e\\u0641\\u064a\\u0636 \\u0645\\u0632\\u064a\\u0641 \\u0633\\u0639\\u0631\",\n \"\\u0631\\u062c\\u0627\\u0621 \\u062a\\u0633\\u0631\\u064a\\u0639 \\u0637\\u0644\\u0628\",\n \"\\u0646\\u0635\\u062d \\u0627\\u0646 \\u0648\\u0635\\u0644 \\u0627\\u0631\\u062f\\u0646\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"rating\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 3,\n \"samples\": [\n \"\\u0625\\u064a\\u062c\\u0627\\u0628\\u064a\",\n \"\\u0633\\u0644\\u0628\\u064a\",\n \"\\u0645\\u062d\\u0627\\u064a\\u062f\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" } }, "metadata": {}, "execution_count": 29 } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 30, "id": "945bc036-bab6-4296-84d6-fb277c36a19a", "metadata": { "id": "945bc036-bab6-4296-84d6-fb277c36a19a" }, "outputs": [], "source": [ "from sklearn.model_selection import train_test_split\n", "from sklearn.feature_extraction.text import TfidfVectorizer\n", "from sklearn.feature_extraction.text import CountVectorizer\n", "from sklearn.pipeline import Pipeline\n", "from sklearn.naive_bayes import MultinomialNB\n", "from sklearn.metrics import accuracy_score, classification_report" ] }, { "cell_type": "code", "execution_count": 31, "id": "b751ec45-598a-4fee-bf4b-0e6ceb56aece", "metadata": { "id": "b751ec45-598a-4fee-bf4b-0e6ceb56aece" }, "outputs": [], "source": [ "x = df[\"review_description\"]\n", "y = df[\"rating\"]" ] }, { "cell_type": "code", "execution_count": 32, "id": "80efeaa3-59ac-49c1-8bb6-9644d4a8cd59", "metadata": { "id": "80efeaa3-59ac-49c1-8bb6-9644d4a8cd59" }, "outputs": [], "source": [ "x_train, x_test, y_train, y_test = train_test_split(x,y,test_size=0.2,random_state=42,stratify=y)" ] }, { "cell_type": "code", "execution_count": 33, "id": "019badbe-896a-432a-8cca-b30572291c1f", "metadata": { "id": "019badbe-896a-432a-8cca-b30572291c1f" }, "outputs": [], "source": [ "TFIDF_model = Pipeline([(\"TFIDF\", TfidfVectorizer()), (\"Model\", MultinomialNB())])" ] }, { "cell_type": "code", "execution_count": 34, "id": "853d1018-e1c0-44ca-87ff-aa1355ff195c", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 188 }, "id": "853d1018-e1c0-44ca-87ff-aa1355ff195c", "outputId": "88418914-7330-4592-a1e6-9ef65d59c6f8" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "Pipeline(steps=[('TFIDF', TfidfVectorizer()), ('Model', MultinomialNB())])" ], "text/html": [ "
Pipeline(steps=[('TFIDF', TfidfVectorizer()), ('Model', MultinomialNB())])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ] }, "metadata": {}, "execution_count": 34 } ], "source": [ "TFIDF_model.fit(x_train, y_train)" ] }, { "cell_type": "code", "execution_count": 35, "id": "749f8da0-7452-44d3-95e0-04e15100403f", "metadata": { "id": "749f8da0-7452-44d3-95e0-04e15100403f" }, "outputs": [], "source": [ "y_pred = TFIDF_model.predict(x_test)" ] }, { "cell_type": "code", "execution_count": 36, "id": "15db3d40-0180-4822-b5b7-f12c5005dda0", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "15db3d40-0180-4822-b5b7-f12c5005dda0", "outputId": "d21f8a4f-1061-46db-e1ac-13eab5ff47ce" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "0.8231811603736351" ] }, "metadata": {}, "execution_count": 36 } ], "source": [ "accuracy = accuracy_score(y_test, y_pred)\n", "accuracy" ] }, { "cell_type": "code", "execution_count": 37, "id": "64494e9f-35cc-422d-b3c8-92af3c33ca01", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "64494e9f-35cc-422d-b3c8-92af3c33ca01", "outputId": "996a1163-d6a5-4d68-a0a1-740372fd0e53" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ " precision recall f1-score support\n", "\n", " إيجابي 0.85 0.89 0.87 4481\n", " سلبي 0.78 0.82 0.80 2749\n", " محايد 0.00 0.00 0.00 371\n", "\n", " accuracy 0.82 7601\n", " macro avg 0.54 0.57 0.56 7601\n", "weighted avg 0.78 0.82 0.80 7601\n", "\n" ] } ], "source": [ "print(classification_report(y_test, y_pred, zero_division=0))" ] }, { "cell_type": "code", "execution_count": 38, "id": "4a142caf-5524-4090-b0e1-e07aba24d7a5", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "4a142caf-5524-4090-b0e1-e07aba24d7a5", "outputId": "9e4948f9-657d-4d31-85d3-f2221c4a1f2b" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "التعليق: التطبيق ممتاز وسهل الاستخدام\n", "التصنيف المتوقع: إيجابي\n", "----------------------------------------\n", "التعليق: الخدمة ليست ج ولا انصح بها\n", "التصنيف المتوقع: إيجابي\n", "----------------------------------------\n", "التعليق: التطبيق عادي\n", "التصنيف المتوقع: سلبي\n", "----------------------------------------\n" ] } ], "source": [ "reviews = [\n", " \"التطبيق ممتاز وسهل الاستخدام\",\n", " \"الخدمة ليست ج ولا انصح بها\",\n", " \"التطبيق عادي\",\n", "]\n", "\n", "cleaned_reviews = [clean_review(review) for review in reviews]\n", "\n", "predictions = TFIDF_model.predict(cleaned_reviews)\n", "\n", "for review, prediction in zip(reviews, predictions):\n", " print(f\"التعليق: {review}\")\n", " print(f\"التصنيف المتوقع: {prediction}\")\n", " print(\"-\" * 40)" ] }, { "cell_type": "code", "execution_count": 39, "id": "174115ef-f1ab-484f-aadf-aff5e1ac2704", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "174115ef-f1ab-484f-aadf-aff5e1ac2704", "outputId": "71cc54c2-41e6-4238-d67f-cf308b7239a0" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "تم حفظ النموذج بنجاح\n" ] } ], "source": [ "import joblib\n", "\n", "joblib.dump(\n", " TFIDF_model,\n", " \"Arabic_Sentiment_Model.joblib\"\n", ")\n", "\n", "print(\"تم حفظ النموذج بنجاح\")" ] }, { "cell_type": "code", "execution_count": 40, "id": "31e68346-9d7b-49c5-bd59-25b9baafb65f", "metadata": { "id": "31e68346-9d7b-49c5-bd59-25b9baafb65f" }, "outputs": [], "source": [ "!pip install -q gradio" ] }, { "cell_type": "code", "execution_count": 41, "id": "2b28e895-eb11-48fd-90db-481ebcf0685f", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 646 }, "id": "2b28e895-eb11-48fd-90db-481ebcf0685f", "outputId": "49930884-2962-4e84-a2fc-2abcf5164be4" }, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.13/dist-packages/gradio/interface.py:171: UserWarning: The parameters have been moved from the Blocks constructor to the launch() method in Gradio 6.0: theme. Please pass these parameters to launch() instead.\n", " super().__init__(\n" ] }, { "output_type": "stream", "name": "stdout", "text": [ "Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n", "* Running on public URL: https://f5bad346c7dd4215df.gradio.live\n", "\n", "This share link is temporary and will last for up to 1 week (best effort). For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "" ], "text/html": [ "
" ] }, "metadata": {} }, { "output_type": "execute_result", "data": { "text/plain": [] }, "metadata": {}, "execution_count": 41 } ], "source": [ "import gradio as gr\n", "\n", "def classify_text(text):\n", " cleaned_text = clean_review(text)\n", "\n", " if not cleaned_text.strip():\n", " return \"الرجاء إدخال نص صالح للتصنيف\"\n", "\n", " prediction = TFIDF_model.predict([cleaned_text])[0]\n", "\n", " return str(prediction)\n", "\n", "app = gr.Interface(\n", " fn=classify_text,\n", " inputs=gr.Textbox(\n", " lines=5,\n", " label=\"النص العربي\",\n", " placeholder=\"اكتب النص هنا...\"\n", " ),\n", " outputs=gr.Textbox(\n", " label=\"نتيجة التصنيف\"\n", " ),\n", " title=\"Arabic Text Classification\",\n", " description=\"Arabic NLP using TF-IDF and MultinomialNB\",\n", " theme=gr.themes.Soft(),\n", " examples=[\n", " [\"التطبيق ممتاز وسهل الاستخدام\"],\n", " [\"الخدمة سيئة ولا أنصح بها\"],\n", " [\"التطبيق عادي\"]\n", " ]\n", ")\n", "\n", "app.launch(share=True)" ] }, { "cell_type": "code", "execution_count": 40, "id": "b5930345-d892-4f56-84b7-bc7ac0bbfc5e", "metadata": { "id": "b5930345-d892-4f56-84b7-bc7ac0bbfc5e" }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 40, "id": "9f16adf3-1ed5-48c1-ac34-84fa6da8502c", "metadata": { "id": "9f16adf3-1ed5-48c1-ac34-84fa6da8502c" }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.5" }, "colab": { "provenance": [] } }, "nbformat": 4, "nbformat_minor": 5 }