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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"nbformat": 4,
|
3 |
+
"nbformat_minor": 0,
|
4 |
+
"metadata": {
|
5 |
+
"colab": {
|
6 |
+
"provenance": [],
|
7 |
+
"toc_visible": true
|
8 |
+
},
|
9 |
+
"kernelspec": {
|
10 |
+
"name": "python3",
|
11 |
+
"display_name": "Python 3"
|
12 |
+
},
|
13 |
+
"language_info": {
|
14 |
+
"name": "python"
|
15 |
+
}
|
16 |
+
},
|
17 |
+
"cells": [
|
18 |
+
{
|
19 |
+
"cell_type": "markdown",
|
20 |
+
"source": [
|
21 |
+
"# Full Implementation Notebook\n",
|
22 |
+
"\n",
|
23 |
+
"This notebook contain the\n",
|
24 |
+
"complete working code where the Hugging Face text-to-text pipeline is\n",
|
25 |
+
"integrated with Gradio."
|
26 |
+
],
|
27 |
+
"metadata": {
|
28 |
+
"id": "pHjELrmOIZi8"
|
29 |
+
}
|
30 |
+
},
|
31 |
+
{
|
32 |
+
"cell_type": "markdown",
|
33 |
+
"source": [
|
34 |
+
"## Code"
|
35 |
+
],
|
36 |
+
"metadata": {
|
37 |
+
"id": "ondE_4z0IcAd"
|
38 |
+
}
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"cell_type": "markdown",
|
42 |
+
"source": [
|
43 |
+
"### Libraries\n",
|
44 |
+
"\n",
|
45 |
+
"Start by installing and importing necessary libraries"
|
46 |
+
],
|
47 |
+
"metadata": {
|
48 |
+
"id": "fwkJqEkZIlcO"
|
49 |
+
}
|
50 |
+
},
|
51 |
+
{
|
52 |
+
"cell_type": "code",
|
53 |
+
"execution_count": null,
|
54 |
+
"metadata": {
|
55 |
+
"id": "WQVTT-lNINjq"
|
56 |
+
},
|
57 |
+
"outputs": [],
|
58 |
+
"source": [
|
59 |
+
"!pip install gradio\n",
|
60 |
+
"!pip install transformers"
|
61 |
+
]
|
62 |
+
},
|
63 |
+
{
|
64 |
+
"cell_type": "code",
|
65 |
+
"source": [
|
66 |
+
"import gradio as gr # Gradio library to create an interactive interface\n",
|
67 |
+
"from transformers import pipeline # Transformers libraries which imports pipeline to use Hugging-Face models\n",
|
68 |
+
"import pandas as pd # Pandas library for data manipulation and analysis\n",
|
69 |
+
"import matplotlib.pylab as plt # Matplot library for the interactive visualizations"
|
70 |
+
],
|
71 |
+
"metadata": {
|
72 |
+
"id": "UGSX08P-InwG"
|
73 |
+
},
|
74 |
+
"execution_count": null,
|
75 |
+
"outputs": []
|
76 |
+
},
|
77 |
+
{
|
78 |
+
"cell_type": "markdown",
|
79 |
+
"source": [
|
80 |
+
"### Initialize Sentiment Analyzers and Define Function\n",
|
81 |
+
"\n",
|
82 |
+
"In this project, Two pre-trained sentiment analysis models will be used, One is for analysizng English text, and the other one if for Arabic text, Also the function that will be used by the Gradio\n"
|
83 |
+
],
|
84 |
+
"metadata": {
|
85 |
+
"id": "eui-QVCNI0CX"
|
86 |
+
}
|
87 |
+
},
|
88 |
+
{
|
89 |
+
"cell_type": "code",
|
90 |
+
"source": [
|
91 |
+
"# Initialize the analyzers\n",
|
92 |
+
"\n",
|
93 |
+
"# Loads a pretrained model for the Arabic language\n",
|
94 |
+
"arabic_analyzer = pipeline('sentiment-analysis', model='CAMeL-Lab/bert-base-arabic-camelbert-da-sentiment')\n",
|
95 |
+
"\n",
|
96 |
+
"# Loads a pretrained model for the English language\n",
|
97 |
+
"english_analyzer = pipeline('sentiment-analysis', model='distilbert-base-uncased-finetuned-sst-2-english')"
|
98 |
+
],
|
99 |
+
"metadata": {
|
100 |
+
"id": "j-A9yOTAI42S"
|
101 |
+
},
|
102 |
+
"execution_count": null,
|
103 |
+
"outputs": []
|
104 |
+
},
|
105 |
+
{
|
106 |
+
"cell_type": "code",
|
107 |
+
"source": [
|
108 |
+
"# Define function\n",
|
109 |
+
"\n",
|
110 |
+
"def sentiment_analysis(language,file):\n",
|
111 |
+
" # Select the appropriate analyzer\n",
|
112 |
+
" if language == \"Arabic\":\n",
|
113 |
+
" analyzer = arabic_analyzer\n",
|
114 |
+
" else:\n",
|
115 |
+
" analyzer = english_analyzer\n",
|
116 |
+
"\n",
|
117 |
+
" results = []\n",
|
118 |
+
"\n",
|
119 |
+
" # Read the sentences from the uploaded file\n",
|
120 |
+
" with open (file.name,'r') as fn:\n",
|
121 |
+
" sentences = fn.readlines()\n",
|
122 |
+
"\n",
|
123 |
+
" # Perform sentiment analysis on each sentence\n",
|
124 |
+
" for sentence in sentences:\n",
|
125 |
+
" result = analyzer(sentence)\n",
|
126 |
+
" result = result[0]\n",
|
127 |
+
"\n",
|
128 |
+
" results.append({\n",
|
129 |
+
" \"Sentence\": sentence,\n",
|
130 |
+
" \"Label\": result['label'],\n",
|
131 |
+
" \"Score\": f\"{result['score'] *100:.2f}%\"\n",
|
132 |
+
" })\n",
|
133 |
+
" # Convert the results into a DataFrame\n",
|
134 |
+
" df = pd.DataFrame(results)\n",
|
135 |
+
" # Ensure every label is lower, if not this will cause a logic error\n",
|
136 |
+
" # English labels are Upper but Arabic labels are lower\n",
|
137 |
+
" df['Label'] = df['Label'].str.lower()\n",
|
138 |
+
" # Take the \"Label\" column values\n",
|
139 |
+
" label_value = df['Label'].value_counts()\n",
|
140 |
+
"\n",
|
141 |
+
" # Pre-Define the plot parameters\n",
|
142 |
+
" labels = ['Positive','Neutral','Negative']\n",
|
143 |
+
" counts = [label_value.get('positive',0),\n",
|
144 |
+
" label_value.get('neutral',0),\n",
|
145 |
+
" label_value.get('negative',0)]\n",
|
146 |
+
" colors=['green','gray','red']\n",
|
147 |
+
"\n",
|
148 |
+
" # Create a bar plot\n",
|
149 |
+
" plt.bar(labels,counts,color=colors)\n",
|
150 |
+
" plt.title('Sentiment-Analysis')\n",
|
151 |
+
" plt.xlabel(\"Labels\")\n",
|
152 |
+
" plt.ylabel(\"No. of sentences\")\n",
|
153 |
+
"\n",
|
154 |
+
"\n",
|
155 |
+
" return df,plt"
|
156 |
+
],
|
157 |
+
"metadata": {
|
158 |
+
"id": "1eTYcvvDJagw"
|
159 |
+
},
|
160 |
+
"execution_count": 62,
|
161 |
+
"outputs": []
|
162 |
+
},
|
163 |
+
{
|
164 |
+
"cell_type": "markdown",
|
165 |
+
"source": [
|
166 |
+
"### Build The Gradio Interface\n",
|
167 |
+
"\n",
|
168 |
+
"Here, The Gradio interface is set up using the following components:\n",
|
169 |
+
"\n",
|
170 |
+
"**A file uploader:** Allows user to upload a text file which contains the sentences to be analyzed\n",
|
171 |
+
"\n",
|
172 |
+
"**Dropdown Menu**: Allows user to choose in which language the sentences will be analyzed\n",
|
173 |
+
"\n",
|
174 |
+
"**DataFrame Output:** Displays program's output in a structured table format\n",
|
175 |
+
"\n",
|
176 |
+
"**Title and Description:** Provides clear title and description for the interface"
|
177 |
+
],
|
178 |
+
"metadata": {
|
179 |
+
"id": "d8ayqK8jO5I8"
|
180 |
+
}
|
181 |
+
},
|
182 |
+
{
|
183 |
+
"cell_type": "code",
|
184 |
+
"source": [
|
185 |
+
"# Set up the Gradio interface\n",
|
186 |
+
"\n",
|
187 |
+
"demo = gr.Interface(\n",
|
188 |
+
" fn=sentiment_analysis,\n",
|
189 |
+
" inputs=[gr.Dropdown(choices=[\"Arabic\",\"English\"],\n",
|
190 |
+
" label=\"Select a Language\",\n",
|
191 |
+
" value=\"Arabic\"),\n",
|
192 |
+
" gr.File(label=\"Upload a file\")],\n",
|
193 |
+
" outputs=[gr.DataFrame(label=\"Results\"),\n",
|
194 |
+
" gr.Plot(label=\"Bar plot\")],\n",
|
195 |
+
" title=\"Sentiment-Analysis\",\n",
|
196 |
+
" description=\"Gradio interface that allows users to Choose what language the sentences will be and upload a text file containing the sentences to be analyzed, the sentences will be classified and results will be in a formatted table along with a plot sentiment distribution\"\n",
|
197 |
+
")\n",
|
198 |
+
"\n",
|
199 |
+
"demo.launch(debug=True)"
|
200 |
+
],
|
201 |
+
"metadata": {
|
202 |
+
"colab": {
|
203 |
+
"base_uri": "https://localhost:8080/",
|
204 |
+
"height": 660
|
205 |
+
},
|
206 |
+
"id": "l3Dc5RWOO7i_",
|
207 |
+
"outputId": "4a321589-f0c0-453c-bba6-079fa79adb8d"
|
208 |
+
},
|
209 |
+
"execution_count": 65,
|
210 |
+
"outputs": [
|
211 |
+
{
|
212 |
+
"output_type": "stream",
|
213 |
+
"name": "stdout",
|
214 |
+
"text": [
|
215 |
+
"Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
|
216 |
+
"\n",
|
217 |
+
"Colab notebook detected. This cell will run indefinitely so that you can see errors and logs. To turn off, set debug=False in launch().\n",
|
218 |
+
"Running on public URL: https://487a5d21908977ea69.gradio.live\n",
|
219 |
+
"\n",
|
220 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
|
221 |
+
]
|
222 |
+
},
|
223 |
+
{
|
224 |
+
"output_type": "display_data",
|
225 |
+
"data": {
|
226 |
+
"text/plain": [
|
227 |
+
"<IPython.core.display.HTML object>"
|
228 |
+
],
|
229 |
+
"text/html": [
|
230 |
+
"<div><iframe src=\"https://487a5d21908977ea69.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
231 |
+
]
|
232 |
+
},
|
233 |
+
"metadata": {}
|
234 |
+
},
|
235 |
+
{
|
236 |
+
"output_type": "stream",
|
237 |
+
"name": "stdout",
|
238 |
+
"text": [
|
239 |
+
"Keyboard interruption in main thread... closing server.\n",
|
240 |
+
"Killing tunnel 127.0.0.1:7860 <> https://487a5d21908977ea69.gradio.live\n"
|
241 |
+
]
|
242 |
+
},
|
243 |
+
{
|
244 |
+
"output_type": "execute_result",
|
245 |
+
"data": {
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3 |
+
"nbformat_minor": 0,
|
4 |
+
"metadata": {
|
5 |
+
"colab": {
|
6 |
+
"provenance": []
|
7 |
+
},
|
8 |
+
"kernelspec": {
|
9 |
+
"name": "python3",
|
10 |
+
"display_name": "Python 3"
|
11 |
+
},
|
12 |
+
"language_info": {
|
13 |
+
"name": "python"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"cells": [
|
17 |
+
{
|
18 |
+
"cell_type": "markdown",
|
19 |
+
"source": [
|
20 |
+
"# Gradio Example Notebook"
|
21 |
+
],
|
22 |
+
"metadata": {
|
23 |
+
"id": "-Ix16ey2erLl"
|
24 |
+
}
|
25 |
+
},
|
26 |
+
{
|
27 |
+
"cell_type": "markdown",
|
28 |
+
"source": [
|
29 |
+
" A separate notebook that demonstrates various Gradio components. If needed,use hardcoded data to show the functionality of the Gradio components.\n"
|
30 |
+
],
|
31 |
+
"metadata": {
|
32 |
+
"id": "3dxNBkEhexES"
|
33 |
+
}
|
34 |
+
},
|
35 |
+
{
|
36 |
+
"cell_type": "markdown",
|
37 |
+
"source": [
|
38 |
+
"## Code"
|
39 |
+
],
|
40 |
+
"metadata": {
|
41 |
+
"id": "YlfGrVVBe16M"
|
42 |
+
}
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"cell_type": "markdown",
|
46 |
+
"source": [
|
47 |
+
"### Libraries\n",
|
48 |
+
"\n",
|
49 |
+
"Start by installing and importing necessary libraries"
|
50 |
+
],
|
51 |
+
"metadata": {
|
52 |
+
"id": "7lICoKpGe4kP"
|
53 |
+
}
|
54 |
+
},
|
55 |
+
{
|
56 |
+
"cell_type": "code",
|
57 |
+
"execution_count": null,
|
58 |
+
"metadata": {
|
59 |
+
"id": "JBJQeBn0YrwE"
|
60 |
+
},
|
61 |
+
"outputs": [],
|
62 |
+
"source": [
|
63 |
+
"!pip install gradio\n",
|
64 |
+
"!pip install wget\n",
|
65 |
+
"!pip install transformers"
|
66 |
+
]
|
67 |
+
},
|
68 |
+
{
|
69 |
+
"cell_type": "code",
|
70 |
+
"source": [
|
71 |
+
"import gradio as gr # Gradio library to create an interactive interface\n",
|
72 |
+
"from transformers import pipeline # Transformers libraries which imports pipeline to use Hugging-Face models\n",
|
73 |
+
"import pandas as pd # Pandas library for data manipulation and analysis"
|
74 |
+
],
|
75 |
+
"metadata": {
|
76 |
+
"id": "OTYay5Uge-Jw"
|
77 |
+
},
|
78 |
+
"execution_count": null,
|
79 |
+
"outputs": []
|
80 |
+
},
|
81 |
+
{
|
82 |
+
"cell_type": "markdown",
|
83 |
+
"source": [
|
84 |
+
"### Initialize Sentiment Analyzer and Define Function\n",
|
85 |
+
"\n",
|
86 |
+
"Here the sentiment-analyzer is initialized using the Hugging-Face pipeline, Also the function that will be used by the Gradio"
|
87 |
+
],
|
88 |
+
"metadata": {
|
89 |
+
"id": "Dx7kdVxhfQ0l"
|
90 |
+
}
|
91 |
+
},
|
92 |
+
{
|
93 |
+
"cell_type": "code",
|
94 |
+
"source": [
|
95 |
+
"# Initialize the analyzer\n",
|
96 |
+
"\n",
|
97 |
+
"# Loads a pretrained model for the English language\n",
|
98 |
+
"analyzer = pipeline(\"sentiment-analysis\")"
|
99 |
+
],
|
100 |
+
"metadata": {
|
101 |
+
"collapsed": true,
|
102 |
+
"id": "RwSoWhwosP3a"
|
103 |
+
},
|
104 |
+
"execution_count": null,
|
105 |
+
"outputs": []
|
106 |
+
},
|
107 |
+
{
|
108 |
+
"cell_type": "code",
|
109 |
+
"source": [
|
110 |
+
"# Define Function\n",
|
111 |
+
"\n",
|
112 |
+
"def sentiment_analysis(filename):\n",
|
113 |
+
" with open(filename, \"r\") as fn: # Open the file and read the sentences\n",
|
114 |
+
" sentences = fn.readlines()\n",
|
115 |
+
" result = analyzer(sentences) # Store the analyzer results for each sentence\n",
|
116 |
+
" df = pd.DataFrame(result) # Convert the results in a formatted table\n",
|
117 |
+
" df['sentences'] = sentences # add column for sentences\n",
|
118 |
+
" return df"
|
119 |
+
],
|
120 |
+
"metadata": {
|
121 |
+
"id": "dGn2a4A4fQGl"
|
122 |
+
},
|
123 |
+
"execution_count": null,
|
124 |
+
"outputs": []
|
125 |
+
},
|
126 |
+
{
|
127 |
+
"cell_type": "markdown",
|
128 |
+
"source": [
|
129 |
+
"### Build Gradio Interface\n",
|
130 |
+
"\n",
|
131 |
+
"\n",
|
132 |
+
"Here, The Gradio interface is set up using the following components:\n",
|
133 |
+
"\n",
|
134 |
+
"**A file uploader** allows user to upload a text file which contains the sentences to be analyzed\n",
|
135 |
+
"\n",
|
136 |
+
"**DataFrame Output** Displays program's output in a structured table format\n",
|
137 |
+
"\n",
|
138 |
+
"**Title and Description**: Provides clear title and description for the interface"
|
139 |
+
],
|
140 |
+
"metadata": {
|
141 |
+
"id": "IHHnKudGfFtI"
|
142 |
+
}
|
143 |
+
},
|
144 |
+
{
|
145 |
+
"cell_type": "code",
|
146 |
+
"source": [
|
147 |
+
"#Create the gradio interface\n",
|
148 |
+
"demo = gr.Interface(\n",
|
149 |
+
" fn=sentiment_analysis, # Function used by gradio\n",
|
150 |
+
" inputs=gr.File(label=\"Upload a file (txt)\"), # User inputs (file)\n",
|
151 |
+
" outputs=gr.Dataframe(label='Results'), # Program's output (DataFrame)\n",
|
152 |
+
" title='Sentiment-Analysis',\n",
|
153 |
+
" description=\"Gradio interface that allows users to upload a text file containing sentences to be analyzed, the sentences will be classified and results will be in a formatted table\"\n",
|
154 |
+
")\n",
|
155 |
+
"demo.launch(debug=True) # \"Debug=True\" Displays inerface errors"
|
156 |
+
],
|
157 |
+
"metadata": {
|
158 |
+
"colab": {
|
159 |
+
"base_uri": "https://localhost:8080/",
|
160 |
+
"height": 680
|
161 |
+
},
|
162 |
+
"id": "xE3M_HFgfN4L",
|
163 |
+
"outputId": "d647960b-41c8-4a7d-b67d-bb3055c77721"
|
164 |
+
},
|
165 |
+
"execution_count": 9,
|
166 |
+
"outputs": [
|
167 |
+
{
|
168 |
+
"output_type": "stream",
|
169 |
+
"name": "stdout",
|
170 |
+
"text": [
|
171 |
+
"Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
|
172 |
+
"\n",
|
173 |
+
"Colab notebook detected. This cell will run indefinitely so that you can see errors and logs. To turn off, set debug=False in launch().\n",
|
174 |
+
"Running on public URL: https://934478ea31903b3a25.gradio.live\n",
|
175 |
+
"\n",
|
176 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
|
177 |
+
]
|
178 |
+
},
|
179 |
+
{
|
180 |
+
"output_type": "display_data",
|
181 |
+
"data": {
|
182 |
+
"text/plain": [
|
183 |
+
"<IPython.core.display.HTML object>"
|
184 |
+
],
|
185 |
+
"text/html": [
|
186 |
+
"<div><iframe src=\"https://934478ea31903b3a25.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
187 |
+
]
|
188 |
+
},
|
189 |
+
"metadata": {}
|
190 |
+
},
|
191 |
+
{
|
192 |
+
"output_type": "stream",
|
193 |
+
"name": "stdout",
|
194 |
+
"text": [
|
195 |
+
"Keyboard interruption in main thread... closing server.\n",
|
196 |
+
"Killing tunnel 127.0.0.1:7860 <> https://934478ea31903b3a25.gradio.live\n"
|
197 |
+
]
|
198 |
+
},
|
199 |
+
{
|
200 |
+
"output_type": "execute_result",
|
201 |
+
"data": {
|
202 |
+
"text/plain": []
|
203 |
+
},
|
204 |
+
"metadata": {},
|
205 |
+
"execution_count": 9
|
206 |
+
}
|
207 |
+
]
|
208 |
+
}
|
209 |
+
]
|
210 |
+
}
|
Simple_Pipeline_Notebook.ipynb
ADDED
@@ -0,0 +1,1356 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"nbformat": 4,
|
3 |
+
"nbformat_minor": 0,
|
4 |
+
"metadata": {
|
5 |
+
"colab": {
|
6 |
+
"provenance": [],
|
7 |
+
"toc_visible": true
|
8 |
+
},
|
9 |
+
"kernelspec": {
|
10 |
+
"name": "python3",
|
11 |
+
"display_name": "Python 3"
|
12 |
+
},
|
13 |
+
"language_info": {
|
14 |
+
"name": "python"
|
15 |
+
}
|
16 |
+
},
|
17 |
+
"cells": [
|
18 |
+
{
|
19 |
+
"cell_type": "markdown",
|
20 |
+
"source": [
|
21 |
+
"# Simple Pipeline Notebook\n",
|
22 |
+
"\n",
|
23 |
+
"Show how the Hugging Face text-to-text\n",
|
24 |
+
"pipeline works without the Gradio interface. Demonstrate inputs and\n",
|
25 |
+
"outputs from the model."
|
26 |
+
],
|
27 |
+
"metadata": {
|
28 |
+
"id": "KLk7_yjQEI58"
|
29 |
+
}
|
30 |
+
},
|
31 |
+
{
|
32 |
+
"cell_type": "markdown",
|
33 |
+
"source": [
|
34 |
+
"## Code"
|
35 |
+
],
|
36 |
+
"metadata": {
|
37 |
+
"id": "RnRBT7SpFnQ9"
|
38 |
+
}
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"cell_type": "markdown",
|
42 |
+
"source": [
|
43 |
+
"### Libraries\n",
|
44 |
+
"\n",
|
45 |
+
"Start by installing and importing necessary libraries"
|
46 |
+
],
|
47 |
+
"metadata": {
|
48 |
+
"id": "keOW1bhbFpOr"
|
49 |
+
}
|
50 |
+
},
|
51 |
+
{
|
52 |
+
"cell_type": "code",
|
53 |
+
"execution_count": null,
|
54 |
+
"metadata": {
|
55 |
+
"id": "73cZfuWW6ofw"
|
56 |
+
},
|
57 |
+
"outputs": [],
|
58 |
+
"source": [
|
59 |
+
"!pip install transformers"
|
60 |
+
]
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"cell_type": "code",
|
64 |
+
"source": [
|
65 |
+
"from transformers import pipeline # Transformers libraries which imports pipeline to use Hugging-Face models\n",
|
66 |
+
"import pandas as pd # Pandas library for data manipulation and analysis"
|
67 |
+
],
|
68 |
+
"metadata": {
|
69 |
+
"id": "pQAlKppmF-Cb"
|
70 |
+
},
|
71 |
+
"execution_count": 2,
|
72 |
+
"outputs": []
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"cell_type": "markdown",
|
76 |
+
"source": [
|
77 |
+
"### Initialize Sentiment analyzers\n",
|
78 |
+
"\n",
|
79 |
+
"In this project, Two pre-trained sentiment analysis models will be used, One is for analysizng English text, and the other one if for Arabic text"
|
80 |
+
],
|
81 |
+
"metadata": {
|
82 |
+
"id": "ZUIn2AIhGDK3"
|
83 |
+
}
|
84 |
+
},
|
85 |
+
{
|
86 |
+
"cell_type": "code",
|
87 |
+
"source": [
|
88 |
+
"#Initialize the Analyzers\n",
|
89 |
+
"\n",
|
90 |
+
"# Loads a pretrained model for the Arabic language\n",
|
91 |
+
"arabic_analyzer = pipeline('sentiment-analysis',model=\"CAMeL-Lab/bert-base-arabic-camelbert-da-sentiment\")\n",
|
92 |
+
"\n",
|
93 |
+
"# Loads a pretrained model for the English language\n",
|
94 |
+
"english_analyzer = pipeline('sentiment-analysis')"
|
95 |
+
],
|
96 |
+
"metadata": {
|
97 |
+
"id": "2GWuZ7MMYki5"
|
98 |
+
},
|
99 |
+
"execution_count": null,
|
100 |
+
"outputs": []
|
101 |
+
},
|
102 |
+
{
|
103 |
+
"cell_type": "markdown",
|
104 |
+
"source": [
|
105 |
+
"### Create sample sentences\n",
|
106 |
+
"\n",
|
107 |
+
"Here we defined two sets of sentences, On in English and one in Arabic, it will serve as a test data for both the sentiment analysis models."
|
108 |
+
],
|
109 |
+
"metadata": {
|
110 |
+
"id": "00irs1gUdiSB"
|
111 |
+
}
|
112 |
+
},
|
113 |
+
{
|
114 |
+
"cell_type": "code",
|
115 |
+
"source": [
|
116 |
+
"# Define a List of Arabic sentences for the analyzer\n",
|
117 |
+
"arabic_sentences = [\n",
|
118 |
+
" 'أصبح غالي جدا',\n",
|
119 |
+
" 'انا بخير',\n",
|
120 |
+
" 'اختبار اليوم كان سهلا',\n",
|
121 |
+
" 'كان اليوم صعب',\n",
|
122 |
+
" 'ذهبت اليوم لزيارة زميل لي',\n",
|
123 |
+
" 'كان الطعام لذيذا'\n",
|
124 |
+
"]\n",
|
125 |
+
"\n",
|
126 |
+
"# Define a list of English sentences for the analyzer\n",
|
127 |
+
"english_sentences = [\n",
|
128 |
+
" 'What a great day!!! Looks like dream.',\n",
|
129 |
+
" 'Today first time I arrive in the boat. Its amazing journey',\n",
|
130 |
+
" 'I`m sorry.',\n",
|
131 |
+
" 'Sounds like me',\n",
|
132 |
+
" 'Im studying in psychology',\n",
|
133 |
+
" 'The movie was okay'\n",
|
134 |
+
"]"
|
135 |
+
],
|
136 |
+
"metadata": {
|
137 |
+
"id": "Spg5ALZ6a9Dp"
|
138 |
+
},
|
139 |
+
"execution_count": 17,
|
140 |
+
"outputs": []
|
141 |
+
},
|
142 |
+
{
|
143 |
+
"cell_type": "markdown",
|
144 |
+
"source": [
|
145 |
+
"### Run The Analyzers\n",
|
146 |
+
"\n",
|
147 |
+
"\n",
|
148 |
+
"Here, The models are using the sample data above, the results are formatted and displayed in a table, Showing the sentence,its predicted label and its score"
|
149 |
+
],
|
150 |
+
"metadata": {
|
151 |
+
"id": "_Hsm8755dqeB"
|
152 |
+
}
|
153 |
+
},
|
154 |
+
{
|
155 |
+
"cell_type": "code",
|
156 |
+
"source": [
|
157 |
+
"# Execute the model on the Arabic sentences\n",
|
158 |
+
"\n",
|
159 |
+
"\n",
|
160 |
+
"arabic_result = arabic_analyzer(arabic_sentences) # Store the analyzer results for each sentence\n",
|
161 |
+
"arabic_df = pd.DataFrame(arabic_result) # Convert the results in a formatted table\n",
|
162 |
+
"arabic_df['Sentences'] = arabic_sentences # add column for sentences\n",
|
163 |
+
"arabic_df"
|
164 |
+
],
|
165 |
+
"metadata": {
|
166 |
+
"colab": {
|
167 |
+
"base_uri": "https://localhost:8080/",
|
168 |
+
"height": 238
|
169 |
+
},
|
170 |
+
"id": "_RaQmJYheoyc",
|
171 |
+
"outputId": "1b8f3108-4448-462c-f297-919950045540"
|
172 |
+
},
|
173 |
+
"execution_count": 22,
|
174 |
+
"outputs": [
|
175 |
+
{
|
176 |
+
"output_type": "execute_result",
|
177 |
+
"data": {
|
178 |
+
"text/plain": [
|
179 |
+
" label score Sentences\n",
|
180 |
+
"0 positive 0.561177 أصبح غالي جدا\n",
|
181 |
+
"1 positive 0.551292 انا بخير\n",
|
182 |
+
"2 negative 0.461035 اختبار اليوم كان سهلا\n",
|
183 |
+
"3 negative 0.401242 كان اليوم صعب\n",
|
184 |
+
"4 neutral 0.585189 ذهبت اليوم لزيارة زميل لي\n",
|
185 |
+
"5 positive 0.901781 كان الطعام لذيذا"
|
186 |
+
],
|
187 |
+
"text/html": [
|
188 |
+
"\n",
|
189 |
+
" <div id=\"df-1838d0b7-e110-4056-9c73-3bb6a1b0d9cc\" class=\"colab-df-container\">\n",
|
190 |
+
" <div>\n",
|
191 |
+
"<style scoped>\n",
|
192 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
193 |
+
" vertical-align: middle;\n",
|
194 |
+
" }\n",
|
195 |
+
"\n",
|
196 |
+
" .dataframe tbody tr th {\n",
|
197 |
+
" vertical-align: top;\n",
|
198 |
+
" }\n",
|
199 |
+
"\n",
|
200 |
+
" .dataframe thead th {\n",
|
201 |
+
" text-align: right;\n",
|
202 |
+
" }\n",
|
203 |
+
"</style>\n",
|
204 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
205 |
+
" <thead>\n",
|
206 |
+
" <tr style=\"text-align: right;\">\n",
|
207 |
+
" <th></th>\n",
|
208 |
+
" <th>label</th>\n",
|
209 |
+
" <th>score</th>\n",
|
210 |
+
" <th>Sentences</th>\n",
|
211 |
+
" </tr>\n",
|
212 |
+
" </thead>\n",
|
213 |
+
" <tbody>\n",
|
214 |
+
" <tr>\n",
|
215 |
+
" <th>0</th>\n",
|
216 |
+
" <td>positive</td>\n",
|
217 |
+
" <td>0.561177</td>\n",
|
218 |
+
" <td>أصبح غالي جدا</td>\n",
|
219 |
+
" </tr>\n",
|
220 |
+
" <tr>\n",
|
221 |
+
" <th>1</th>\n",
|
222 |
+
" <td>positive</td>\n",
|
223 |
+
" <td>0.551292</td>\n",
|
224 |
+
" <td>انا بخير</td>\n",
|
225 |
+
" </tr>\n",
|
226 |
+
" <tr>\n",
|
227 |
+
" <th>2</th>\n",
|
228 |
+
" <td>negative</td>\n",
|
229 |
+
" <td>0.461035</td>\n",
|
230 |
+
" <td>اختبار اليوم كان سهلا</td>\n",
|
231 |
+
" </tr>\n",
|
232 |
+
" <tr>\n",
|
233 |
+
" <th>3</th>\n",
|
234 |
+
" <td>negative</td>\n",
|
235 |
+
" <td>0.401242</td>\n",
|
236 |
+
" <td>كان اليوم صعب</td>\n",
|
237 |
+
" </tr>\n",
|
238 |
+
" <tr>\n",
|
239 |
+
" <th>4</th>\n",
|
240 |
+
" <td>neutral</td>\n",
|
241 |
+
" <td>0.585189</td>\n",
|
242 |
+
" <td>ذهبت اليوم لزيارة زميل لي</td>\n",
|
243 |
+
" </tr>\n",
|
244 |
+
" <tr>\n",
|
245 |
+
" <th>5</th>\n",
|
246 |
+
" <td>positive</td>\n",
|
247 |
+
" <td>0.901781</td>\n",
|
248 |
+
" <td>كان الطعام لذيذا</td>\n",
|
249 |
+
" </tr>\n",
|
250 |
+
" </tbody>\n",
|
251 |
+
"</table>\n",
|
252 |
+
"</div>\n",
|
253 |
+
" <div class=\"colab-df-buttons\">\n",
|
254 |
+
"\n",
|
255 |
+
" <div class=\"colab-df-container\">\n",
|
256 |
+
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-1838d0b7-e110-4056-9c73-3bb6a1b0d9cc')\"\n",
|
257 |
+
" title=\"Convert this dataframe to an interactive table.\"\n",
|
258 |
+
" style=\"display:none;\">\n",
|
259 |
+
"\n",
|
260 |
+
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
|
261 |
+
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
|
262 |
+
" </svg>\n",
|
263 |
+
" </button>\n",
|
264 |
+
"\n",
|
265 |
+
" <style>\n",
|
266 |
+
" .colab-df-container {\n",
|
267 |
+
" display:flex;\n",
|
268 |
+
" gap: 12px;\n",
|
269 |
+
" }\n",
|
270 |
+
"\n",
|
271 |
+
" .colab-df-convert {\n",
|
272 |
+
" background-color: #E8F0FE;\n",
|
273 |
+
" border: none;\n",
|
274 |
+
" border-radius: 50%;\n",
|
275 |
+
" cursor: pointer;\n",
|
276 |
+
" display: none;\n",
|
277 |
+
" fill: #1967D2;\n",
|
278 |
+
" height: 32px;\n",
|
279 |
+
" padding: 0 0 0 0;\n",
|
280 |
+
" width: 32px;\n",
|
281 |
+
" }\n",
|
282 |
+
"\n",
|
283 |
+
" .colab-df-convert:hover {\n",
|
284 |
+
" background-color: #E2EBFA;\n",
|
285 |
+
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
|
286 |
+
" fill: #174EA6;\n",
|
287 |
+
" }\n",
|
288 |
+
"\n",
|
289 |
+
" .colab-df-buttons div {\n",
|
290 |
+
" margin-bottom: 4px;\n",
|
291 |
+
" }\n",
|
292 |
+
"\n",
|
293 |
+
" [theme=dark] .colab-df-convert {\n",
|
294 |
+
" background-color: #3B4455;\n",
|
295 |
+
" fill: #D2E3FC;\n",
|
296 |
+
" }\n",
|
297 |
+
"\n",
|
298 |
+
" [theme=dark] .colab-df-convert:hover {\n",
|
299 |
+
" background-color: #434B5C;\n",
|
300 |
+
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
|
301 |
+
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
|
302 |
+
" fill: #FFFFFF;\n",
|
303 |
+
" }\n",
|
304 |
+
" </style>\n",
|
305 |
+
"\n",
|
306 |
+
" <script>\n",
|
307 |
+
" const buttonEl =\n",
|
308 |
+
" document.querySelector('#df-1838d0b7-e110-4056-9c73-3bb6a1b0d9cc button.colab-df-convert');\n",
|
309 |
+
" buttonEl.style.display =\n",
|
310 |
+
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
|
311 |
+
"\n",
|
312 |
+
" async function convertToInteractive(key) {\n",
|
313 |
+
" const element = document.querySelector('#df-1838d0b7-e110-4056-9c73-3bb6a1b0d9cc');\n",
|
314 |
+
" const dataTable =\n",
|
315 |
+
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
|
316 |
+
" [key], {});\n",
|
317 |
+
" if (!dataTable) return;\n",
|
318 |
+
"\n",
|
319 |
+
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
|
320 |
+
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
|
321 |
+
" + ' to learn more about interactive tables.';\n",
|
322 |
+
" element.innerHTML = '';\n",
|
323 |
+
" dataTable['output_type'] = 'display_data';\n",
|
324 |
+
" await google.colab.output.renderOutput(dataTable, element);\n",
|
325 |
+
" const docLink = document.createElement('div');\n",
|
326 |
+
" docLink.innerHTML = docLinkHtml;\n",
|
327 |
+
" element.appendChild(docLink);\n",
|
328 |
+
" }\n",
|
329 |
+
" </script>\n",
|
330 |
+
" </div>\n",
|
331 |
+
"\n",
|
332 |
+
"\n",
|
333 |
+
"<div id=\"df-d8cf40de-d2d9-48e3-bd8b-875f0139ff1b\">\n",
|
334 |
+
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-d8cf40de-d2d9-48e3-bd8b-875f0139ff1b')\"\n",
|
335 |
+
" title=\"Suggest charts\"\n",
|
336 |
+
" style=\"display:none;\">\n",
|
337 |
+
"\n",
|
338 |
+
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
|
339 |
+
" width=\"24px\">\n",
|
340 |
+
" <g>\n",
|
341 |
+
" <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
|
342 |
+
" </g>\n",
|
343 |
+
"</svg>\n",
|
344 |
+
" </button>\n",
|
345 |
+
"\n",
|
346 |
+
"<style>\n",
|
347 |
+
" .colab-df-quickchart {\n",
|
348 |
+
" --bg-color: #E8F0FE;\n",
|
349 |
+
" --fill-color: #1967D2;\n",
|
350 |
+
" --hover-bg-color: #E2EBFA;\n",
|
351 |
+
" --hover-fill-color: #174EA6;\n",
|
352 |
+
" --disabled-fill-color: #AAA;\n",
|
353 |
+
" --disabled-bg-color: #DDD;\n",
|
354 |
+
" }\n",
|
355 |
+
"\n",
|
356 |
+
" [theme=dark] .colab-df-quickchart {\n",
|
357 |
+
" --bg-color: #3B4455;\n",
|
358 |
+
" --fill-color: #D2E3FC;\n",
|
359 |
+
" --hover-bg-color: #434B5C;\n",
|
360 |
+
" --hover-fill-color: #FFFFFF;\n",
|
361 |
+
" --disabled-bg-color: #3B4455;\n",
|
362 |
+
" --disabled-fill-color: #666;\n",
|
363 |
+
" }\n",
|
364 |
+
"\n",
|
365 |
+
" .colab-df-quickchart {\n",
|
366 |
+
" background-color: var(--bg-color);\n",
|
367 |
+
" border: none;\n",
|
368 |
+
" border-radius: 50%;\n",
|
369 |
+
" cursor: pointer;\n",
|
370 |
+
" display: none;\n",
|
371 |
+
" fill: var(--fill-color);\n",
|
372 |
+
" height: 32px;\n",
|
373 |
+
" padding: 0;\n",
|
374 |
+
" width: 32px;\n",
|
375 |
+
" }\n",
|
376 |
+
"\n",
|
377 |
+
" .colab-df-quickchart:hover {\n",
|
378 |
+
" background-color: var(--hover-bg-color);\n",
|
379 |
+
" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
|
380 |
+
" fill: var(--button-hover-fill-color);\n",
|
381 |
+
" }\n",
|
382 |
+
"\n",
|
383 |
+
" .colab-df-quickchart-complete:disabled,\n",
|
384 |
+
" .colab-df-quickchart-complete:disabled:hover {\n",
|
385 |
+
" background-color: var(--disabled-bg-color);\n",
|
386 |
+
" fill: var(--disabled-fill-color);\n",
|
387 |
+
" box-shadow: none;\n",
|
388 |
+
" }\n",
|
389 |
+
"\n",
|
390 |
+
" .colab-df-spinner {\n",
|
391 |
+
" border: 2px solid var(--fill-color);\n",
|
392 |
+
" border-color: transparent;\n",
|
393 |
+
" border-bottom-color: var(--fill-color);\n",
|
394 |
+
" animation:\n",
|
395 |
+
" spin 1s steps(1) infinite;\n",
|
396 |
+
" }\n",
|
397 |
+
"\n",
|
398 |
+
" @keyframes spin {\n",
|
399 |
+
" 0% {\n",
|
400 |
+
" border-color: transparent;\n",
|
401 |
+
" border-bottom-color: var(--fill-color);\n",
|
402 |
+
" border-left-color: var(--fill-color);\n",
|
403 |
+
" }\n",
|
404 |
+
" 20% {\n",
|
405 |
+
" border-color: transparent;\n",
|
406 |
+
" border-left-color: var(--fill-color);\n",
|
407 |
+
" border-top-color: var(--fill-color);\n",
|
408 |
+
" }\n",
|
409 |
+
" 30% {\n",
|
410 |
+
" border-color: transparent;\n",
|
411 |
+
" border-left-color: var(--fill-color);\n",
|
412 |
+
" border-top-color: var(--fill-color);\n",
|
413 |
+
" border-right-color: var(--fill-color);\n",
|
414 |
+
" }\n",
|
415 |
+
" 40% {\n",
|
416 |
+
" border-color: transparent;\n",
|
417 |
+
" border-right-color: var(--fill-color);\n",
|
418 |
+
" border-top-color: var(--fill-color);\n",
|
419 |
+
" }\n",
|
420 |
+
" 60% {\n",
|
421 |
+
" border-color: transparent;\n",
|
422 |
+
" border-right-color: var(--fill-color);\n",
|
423 |
+
" }\n",
|
424 |
+
" 80% {\n",
|
425 |
+
" border-color: transparent;\n",
|
426 |
+
" border-right-color: var(--fill-color);\n",
|
427 |
+
" border-bottom-color: var(--fill-color);\n",
|
428 |
+
" }\n",
|
429 |
+
" 90% {\n",
|
430 |
+
" border-color: transparent;\n",
|
431 |
+
" border-bottom-color: var(--fill-color);\n",
|
432 |
+
" }\n",
|
433 |
+
" }\n",
|
434 |
+
"</style>\n",
|
435 |
+
"\n",
|
436 |
+
" <script>\n",
|
437 |
+
" async function quickchart(key) {\n",
|
438 |
+
" const quickchartButtonEl =\n",
|
439 |
+
" document.querySelector('#' + key + ' button');\n",
|
440 |
+
" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
|
441 |
+
" quickchartButtonEl.classList.add('colab-df-spinner');\n",
|
442 |
+
" try {\n",
|
443 |
+
" const charts = await google.colab.kernel.invokeFunction(\n",
|
444 |
+
" 'suggestCharts', [key], {});\n",
|
445 |
+
" } catch (error) {\n",
|
446 |
+
" console.error('Error during call to suggestCharts:', error);\n",
|
447 |
+
" }\n",
|
448 |
+
" quickchartButtonEl.classList.remove('colab-df-spinner');\n",
|
449 |
+
" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
|
450 |
+
" }\n",
|
451 |
+
" (() => {\n",
|
452 |
+
" let quickchartButtonEl =\n",
|
453 |
+
" document.querySelector('#df-d8cf40de-d2d9-48e3-bd8b-875f0139ff1b button');\n",
|
454 |
+
" quickchartButtonEl.style.display =\n",
|
455 |
+
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
|
456 |
+
" })();\n",
|
457 |
+
" </script>\n",
|
458 |
+
"</div>\n",
|
459 |
+
"\n",
|
460 |
+
" <div id=\"id_d1e30db0-7061-41a0-a02b-848f82e990c4\">\n",
|
461 |
+
" <style>\n",
|
462 |
+
" .colab-df-generate {\n",
|
463 |
+
" background-color: #E8F0FE;\n",
|
464 |
+
" border: none;\n",
|
465 |
+
" border-radius: 50%;\n",
|
466 |
+
" cursor: pointer;\n",
|
467 |
+
" display: none;\n",
|
468 |
+
" fill: #1967D2;\n",
|
469 |
+
" height: 32px;\n",
|
470 |
+
" padding: 0 0 0 0;\n",
|
471 |
+
" width: 32px;\n",
|
472 |
+
" }\n",
|
473 |
+
"\n",
|
474 |
+
" .colab-df-generate:hover {\n",
|
475 |
+
" background-color: #E2EBFA;\n",
|
476 |
+
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
|
477 |
+
" fill: #174EA6;\n",
|
478 |
+
" }\n",
|
479 |
+
"\n",
|
480 |
+
" [theme=dark] .colab-df-generate {\n",
|
481 |
+
" background-color: #3B4455;\n",
|
482 |
+
" fill: #D2E3FC;\n",
|
483 |
+
" }\n",
|
484 |
+
"\n",
|
485 |
+
" [theme=dark] .colab-df-generate:hover {\n",
|
486 |
+
" background-color: #434B5C;\n",
|
487 |
+
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
|
488 |
+
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
|
489 |
+
" fill: #FFFFFF;\n",
|
490 |
+
" }\n",
|
491 |
+
" </style>\n",
|
492 |
+
" <button class=\"colab-df-generate\" onclick=\"generateWithVariable('arabic_df')\"\n",
|
493 |
+
" title=\"Generate code using this dataframe.\"\n",
|
494 |
+
" style=\"display:none;\">\n",
|
495 |
+
"\n",
|
496 |
+
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
|
497 |
+
" width=\"24px\">\n",
|
498 |
+
" <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n",
|
499 |
+
" </svg>\n",
|
500 |
+
" </button>\n",
|
501 |
+
" <script>\n",
|
502 |
+
" (() => {\n",
|
503 |
+
" const buttonEl =\n",
|
504 |
+
" document.querySelector('#id_d1e30db0-7061-41a0-a02b-848f82e990c4 button.colab-df-generate');\n",
|
505 |
+
" buttonEl.style.display =\n",
|
506 |
+
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
|
507 |
+
"\n",
|
508 |
+
" buttonEl.onclick = () => {\n",
|
509 |
+
" google.colab.notebook.generateWithVariable('arabic_df');\n",
|
510 |
+
" }\n",
|
511 |
+
" })();\n",
|
512 |
+
" </script>\n",
|
513 |
+
" </div>\n",
|
514 |
+
"\n",
|
515 |
+
" </div>\n",
|
516 |
+
" </div>\n"
|
517 |
+
],
|
518 |
+
"application/vnd.google.colaboratory.intrinsic+json": {
|
519 |
+
"type": "dataframe",
|
520 |
+
"variable_name": "arabic_df",
|
521 |
+
"summary": "{\n \"name\": \"arabic_df\",\n \"rows\": 6,\n \"fields\": [\n {\n \"column\": \"label\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 3,\n \"samples\": [\n \"positive\",\n \"negative\",\n \"neutral\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"score\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.1736662143596494,\n \"min\": 0.40124186873435974,\n \"max\": 0.9017810225486755,\n \"num_unique_values\": 6,\n \"samples\": [\n 0.561177134513855,\n 0.5512916445732117,\n 0.9017810225486755\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Sentences\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 6,\n \"samples\": [\n \"\\u0623\\u0635\\u0628\\u062d \\u063a\\u0627\\u0644\\u064a \\u062c\\u062f\\u0627\",\n \"\\u0627\\u0646\\u0627 \\u0628\\u062e\\u064a\\u0631\",\n \"\\u0643\\u0627\\u0646 \\u0627\\u0644\\u0637\\u0639\\u0627\\u0645 \\u0644\\u0630\\u064a\\u0630\\u0627\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
|
522 |
+
}
|
523 |
+
},
|
524 |
+
"metadata": {},
|
525 |
+
"execution_count": 22
|
526 |
+
}
|
527 |
+
]
|
528 |
+
},
|
529 |
+
{
|
530 |
+
"cell_type": "code",
|
531 |
+
"source": [
|
532 |
+
"# Execute the model on the English sentences\n",
|
533 |
+
"\n",
|
534 |
+
"\n",
|
535 |
+
"english_result = english_analyzer(english_sentences) # Store the analyzer results for each sentence\n",
|
536 |
+
"english_df = pd.DataFrame(english_result) # Convert the results in a formatted table\n",
|
537 |
+
"english_df['Sentences'] = english_sentences # add column for sentences\n",
|
538 |
+
"english_df"
|
539 |
+
],
|
540 |
+
"metadata": {
|
541 |
+
"colab": {
|
542 |
+
"base_uri": "https://localhost:8080/",
|
543 |
+
"height": 238
|
544 |
+
},
|
545 |
+
"id": "A36AXwdrdw0F",
|
546 |
+
"outputId": "2d758bf6-2453-4b44-bfd8-e4b14bed53ad"
|
547 |
+
},
|
548 |
+
"execution_count": 20,
|
549 |
+
"outputs": [
|
550 |
+
{
|
551 |
+
"output_type": "execute_result",
|
552 |
+
"data": {
|
553 |
+
"text/plain": [
|
554 |
+
" label score Sentences\n",
|
555 |
+
"0 POSITIVE 0.999849 What a great day!!! Looks like dream.\n",
|
556 |
+
"1 POSITIVE 0.999842 Today first time I arrive in the boat. Its ama...\n",
|
557 |
+
"2 NEGATIVE 0.999688 I`m sorry.\n",
|
558 |
+
"3 POSITIVE 0.998944 Sounds like me\n",
|
559 |
+
"4 POSITIVE 0.505438 Im studying in psychology\n",
|
560 |
+
"5 POSITIVE 0.999792 The movie was okay"
|
561 |
+
],
|
562 |
+
"text/html": [
|
563 |
+
"\n",
|
564 |
+
" <div id=\"df-e5befafa-1e26-48df-b39d-88b640daf8ab\" class=\"colab-df-container\">\n",
|
565 |
+
" <div>\n",
|
566 |
+
"<style scoped>\n",
|
567 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
568 |
+
" vertical-align: middle;\n",
|
569 |
+
" }\n",
|
570 |
+
"\n",
|
571 |
+
" .dataframe tbody tr th {\n",
|
572 |
+
" vertical-align: top;\n",
|
573 |
+
" }\n",
|
574 |
+
"\n",
|
575 |
+
" .dataframe thead th {\n",
|
576 |
+
" text-align: right;\n",
|
577 |
+
" }\n",
|
578 |
+
"</style>\n",
|
579 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
580 |
+
" <thead>\n",
|
581 |
+
" <tr style=\"text-align: right;\">\n",
|
582 |
+
" <th></th>\n",
|
583 |
+
" <th>label</th>\n",
|
584 |
+
" <th>score</th>\n",
|
585 |
+
" <th>Sentences</th>\n",
|
586 |
+
" </tr>\n",
|
587 |
+
" </thead>\n",
|
588 |
+
" <tbody>\n",
|
589 |
+
" <tr>\n",
|
590 |
+
" <th>0</th>\n",
|
591 |
+
" <td>POSITIVE</td>\n",
|
592 |
+
" <td>0.999849</td>\n",
|
593 |
+
" <td>What a great day!!! Looks like dream.</td>\n",
|
594 |
+
" </tr>\n",
|
595 |
+
" <tr>\n",
|
596 |
+
" <th>1</th>\n",
|
597 |
+
" <td>POSITIVE</td>\n",
|
598 |
+
" <td>0.999842</td>\n",
|
599 |
+
" <td>Today first time I arrive in the boat. Its ama...</td>\n",
|
600 |
+
" </tr>\n",
|
601 |
+
" <tr>\n",
|
602 |
+
" <th>2</th>\n",
|
603 |
+
" <td>NEGATIVE</td>\n",
|
604 |
+
" <td>0.999688</td>\n",
|
605 |
+
" <td>I`m sorry.</td>\n",
|
606 |
+
" </tr>\n",
|
607 |
+
" <tr>\n",
|
608 |
+
" <th>3</th>\n",
|
609 |
+
" <td>POSITIVE</td>\n",
|
610 |
+
" <td>0.998944</td>\n",
|
611 |
+
" <td>Sounds like me</td>\n",
|
612 |
+
" </tr>\n",
|
613 |
+
" <tr>\n",
|
614 |
+
" <th>4</th>\n",
|
615 |
+
" <td>POSITIVE</td>\n",
|
616 |
+
" <td>0.505438</td>\n",
|
617 |
+
" <td>Im studying in psychology</td>\n",
|
618 |
+
" </tr>\n",
|
619 |
+
" <tr>\n",
|
620 |
+
" <th>5</th>\n",
|
621 |
+
" <td>POSITIVE</td>\n",
|
622 |
+
" <td>0.999792</td>\n",
|
623 |
+
" <td>The movie was okay</td>\n",
|
624 |
+
" </tr>\n",
|
625 |
+
" </tbody>\n",
|
626 |
+
"</table>\n",
|
627 |
+
"</div>\n",
|
628 |
+
" <div class=\"colab-df-buttons\">\n",
|
629 |
+
"\n",
|
630 |
+
" <div class=\"colab-df-container\">\n",
|
631 |
+
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-e5befafa-1e26-48df-b39d-88b640daf8ab')\"\n",
|
632 |
+
" title=\"Convert this dataframe to an interactive table.\"\n",
|
633 |
+
" style=\"display:none;\">\n",
|
634 |
+
"\n",
|
635 |
+
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
|
636 |
+
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
|
637 |
+
" </svg>\n",
|
638 |
+
" </button>\n",
|
639 |
+
"\n",
|
640 |
+
" <style>\n",
|
641 |
+
" .colab-df-container {\n",
|
642 |
+
" display:flex;\n",
|
643 |
+
" gap: 12px;\n",
|
644 |
+
" }\n",
|
645 |
+
"\n",
|
646 |
+
" .colab-df-convert {\n",
|
647 |
+
" background-color: #E8F0FE;\n",
|
648 |
+
" border: none;\n",
|
649 |
+
" border-radius: 50%;\n",
|
650 |
+
" cursor: pointer;\n",
|
651 |
+
" display: none;\n",
|
652 |
+
" fill: #1967D2;\n",
|
653 |
+
" height: 32px;\n",
|
654 |
+
" padding: 0 0 0 0;\n",
|
655 |
+
" width: 32px;\n",
|
656 |
+
" }\n",
|
657 |
+
"\n",
|
658 |
+
" .colab-df-convert:hover {\n",
|
659 |
+
" background-color: #E2EBFA;\n",
|
660 |
+
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
|
661 |
+
" fill: #174EA6;\n",
|
662 |
+
" }\n",
|
663 |
+
"\n",
|
664 |
+
" .colab-df-buttons div {\n",
|
665 |
+
" margin-bottom: 4px;\n",
|
666 |
+
" }\n",
|
667 |
+
"\n",
|
668 |
+
" [theme=dark] .colab-df-convert {\n",
|
669 |
+
" background-color: #3B4455;\n",
|
670 |
+
" fill: #D2E3FC;\n",
|
671 |
+
" }\n",
|
672 |
+
"\n",
|
673 |
+
" [theme=dark] .colab-df-convert:hover {\n",
|
674 |
+
" background-color: #434B5C;\n",
|
675 |
+
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
|
676 |
+
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
|
677 |
+
" fill: #FFFFFF;\n",
|
678 |
+
" }\n",
|
679 |
+
" </style>\n",
|
680 |
+
"\n",
|
681 |
+
" <script>\n",
|
682 |
+
" const buttonEl =\n",
|
683 |
+
" document.querySelector('#df-e5befafa-1e26-48df-b39d-88b640daf8ab button.colab-df-convert');\n",
|
684 |
+
" buttonEl.style.display =\n",
|
685 |
+
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
|
686 |
+
"\n",
|
687 |
+
" async function convertToInteractive(key) {\n",
|
688 |
+
" const element = document.querySelector('#df-e5befafa-1e26-48df-b39d-88b640daf8ab');\n",
|
689 |
+
" const dataTable =\n",
|
690 |
+
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
|
691 |
+
" [key], {});\n",
|
692 |
+
" if (!dataTable) return;\n",
|
693 |
+
"\n",
|
694 |
+
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
|
695 |
+
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
|
696 |
+
" + ' to learn more about interactive tables.';\n",
|
697 |
+
" element.innerHTML = '';\n",
|
698 |
+
" dataTable['output_type'] = 'display_data';\n",
|
699 |
+
" await google.colab.output.renderOutput(dataTable, element);\n",
|
700 |
+
" const docLink = document.createElement('div');\n",
|
701 |
+
" docLink.innerHTML = docLinkHtml;\n",
|
702 |
+
" element.appendChild(docLink);\n",
|
703 |
+
" }\n",
|
704 |
+
" </script>\n",
|
705 |
+
" </div>\n",
|
706 |
+
"\n",
|
707 |
+
"\n",
|
708 |
+
"<div id=\"df-9c0cf789-1974-4328-9cab-15ab87144caf\">\n",
|
709 |
+
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-9c0cf789-1974-4328-9cab-15ab87144caf')\"\n",
|
710 |
+
" title=\"Suggest charts\"\n",
|
711 |
+
" style=\"display:none;\">\n",
|
712 |
+
"\n",
|
713 |
+
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
|
714 |
+
" width=\"24px\">\n",
|
715 |
+
" <g>\n",
|
716 |
+
" <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
|
717 |
+
" </g>\n",
|
718 |
+
"</svg>\n",
|
719 |
+
" </button>\n",
|
720 |
+
"\n",
|
721 |
+
"<style>\n",
|
722 |
+
" .colab-df-quickchart {\n",
|
723 |
+
" --bg-color: #E8F0FE;\n",
|
724 |
+
" --fill-color: #1967D2;\n",
|
725 |
+
" --hover-bg-color: #E2EBFA;\n",
|
726 |
+
" --hover-fill-color: #174EA6;\n",
|
727 |
+
" --disabled-fill-color: #AAA;\n",
|
728 |
+
" --disabled-bg-color: #DDD;\n",
|
729 |
+
" }\n",
|
730 |
+
"\n",
|
731 |
+
" [theme=dark] .colab-df-quickchart {\n",
|
732 |
+
" --bg-color: #3B4455;\n",
|
733 |
+
" --fill-color: #D2E3FC;\n",
|
734 |
+
" --hover-bg-color: #434B5C;\n",
|
735 |
+
" --hover-fill-color: #FFFFFF;\n",
|
736 |
+
" --disabled-bg-color: #3B4455;\n",
|
737 |
+
" --disabled-fill-color: #666;\n",
|
738 |
+
" }\n",
|
739 |
+
"\n",
|
740 |
+
" .colab-df-quickchart {\n",
|
741 |
+
" background-color: var(--bg-color);\n",
|
742 |
+
" border: none;\n",
|
743 |
+
" border-radius: 50%;\n",
|
744 |
+
" cursor: pointer;\n",
|
745 |
+
" display: none;\n",
|
746 |
+
" fill: var(--fill-color);\n",
|
747 |
+
" height: 32px;\n",
|
748 |
+
" padding: 0;\n",
|
749 |
+
" width: 32px;\n",
|
750 |
+
" }\n",
|
751 |
+
"\n",
|
752 |
+
" .colab-df-quickchart:hover {\n",
|
753 |
+
" background-color: var(--hover-bg-color);\n",
|
754 |
+
" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
|
755 |
+
" fill: var(--button-hover-fill-color);\n",
|
756 |
+
" }\n",
|
757 |
+
"\n",
|
758 |
+
" .colab-df-quickchart-complete:disabled,\n",
|
759 |
+
" .colab-df-quickchart-complete:disabled:hover {\n",
|
760 |
+
" background-color: var(--disabled-bg-color);\n",
|
761 |
+
" fill: var(--disabled-fill-color);\n",
|
762 |
+
" box-shadow: none;\n",
|
763 |
+
" }\n",
|
764 |
+
"\n",
|
765 |
+
" .colab-df-spinner {\n",
|
766 |
+
" border: 2px solid var(--fill-color);\n",
|
767 |
+
" border-color: transparent;\n",
|
768 |
+
" border-bottom-color: var(--fill-color);\n",
|
769 |
+
" animation:\n",
|
770 |
+
" spin 1s steps(1) infinite;\n",
|
771 |
+
" }\n",
|
772 |
+
"\n",
|
773 |
+
" @keyframes spin {\n",
|
774 |
+
" 0% {\n",
|
775 |
+
" border-color: transparent;\n",
|
776 |
+
" border-bottom-color: var(--fill-color);\n",
|
777 |
+
" border-left-color: var(--fill-color);\n",
|
778 |
+
" }\n",
|
779 |
+
" 20% {\n",
|
780 |
+
" border-color: transparent;\n",
|
781 |
+
" border-left-color: var(--fill-color);\n",
|
782 |
+
" border-top-color: var(--fill-color);\n",
|
783 |
+
" }\n",
|
784 |
+
" 30% {\n",
|
785 |
+
" border-color: transparent;\n",
|
786 |
+
" border-left-color: var(--fill-color);\n",
|
787 |
+
" border-top-color: var(--fill-color);\n",
|
788 |
+
" border-right-color: var(--fill-color);\n",
|
789 |
+
" }\n",
|
790 |
+
" 40% {\n",
|
791 |
+
" border-color: transparent;\n",
|
792 |
+
" border-right-color: var(--fill-color);\n",
|
793 |
+
" border-top-color: var(--fill-color);\n",
|
794 |
+
" }\n",
|
795 |
+
" 60% {\n",
|
796 |
+
" border-color: transparent;\n",
|
797 |
+
" border-right-color: var(--fill-color);\n",
|
798 |
+
" }\n",
|
799 |
+
" 80% {\n",
|
800 |
+
" border-color: transparent;\n",
|
801 |
+
" border-right-color: var(--fill-color);\n",
|
802 |
+
" border-bottom-color: var(--fill-color);\n",
|
803 |
+
" }\n",
|
804 |
+
" 90% {\n",
|
805 |
+
" border-color: transparent;\n",
|
806 |
+
" border-bottom-color: var(--fill-color);\n",
|
807 |
+
" }\n",
|
808 |
+
" }\n",
|
809 |
+
"</style>\n",
|
810 |
+
"\n",
|
811 |
+
" <script>\n",
|
812 |
+
" async function quickchart(key) {\n",
|
813 |
+
" const quickchartButtonEl =\n",
|
814 |
+
" document.querySelector('#' + key + ' button');\n",
|
815 |
+
" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
|
816 |
+
" quickchartButtonEl.classList.add('colab-df-spinner');\n",
|
817 |
+
" try {\n",
|
818 |
+
" const charts = await google.colab.kernel.invokeFunction(\n",
|
819 |
+
" 'suggestCharts', [key], {});\n",
|
820 |
+
" } catch (error) {\n",
|
821 |
+
" console.error('Error during call to suggestCharts:', error);\n",
|
822 |
+
" }\n",
|
823 |
+
" quickchartButtonEl.classList.remove('colab-df-spinner');\n",
|
824 |
+
" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
|
825 |
+
" }\n",
|
826 |
+
" (() => {\n",
|
827 |
+
" let quickchartButtonEl =\n",
|
828 |
+
" document.querySelector('#df-9c0cf789-1974-4328-9cab-15ab87144caf button');\n",
|
829 |
+
" quickchartButtonEl.style.display =\n",
|
830 |
+
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
|
831 |
+
" })();\n",
|
832 |
+
" </script>\n",
|
833 |
+
"</div>\n",
|
834 |
+
"\n",
|
835 |
+
" <div id=\"id_ffa98c39-a611-4929-a669-d3f7b8d8d0ae\">\n",
|
836 |
+
" <style>\n",
|
837 |
+
" .colab-df-generate {\n",
|
838 |
+
" background-color: #E8F0FE;\n",
|
839 |
+
" border: none;\n",
|
840 |
+
" border-radius: 50%;\n",
|
841 |
+
" cursor: pointer;\n",
|
842 |
+
" display: none;\n",
|
843 |
+
" fill: #1967D2;\n",
|
844 |
+
" height: 32px;\n",
|
845 |
+
" padding: 0 0 0 0;\n",
|
846 |
+
" width: 32px;\n",
|
847 |
+
" }\n",
|
848 |
+
"\n",
|
849 |
+
" .colab-df-generate:hover {\n",
|
850 |
+
" background-color: #E2EBFA;\n",
|
851 |
+
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
|
852 |
+
" fill: #174EA6;\n",
|
853 |
+
" }\n",
|
854 |
+
"\n",
|
855 |
+
" [theme=dark] .colab-df-generate {\n",
|
856 |
+
" background-color: #3B4455;\n",
|
857 |
+
" fill: #D2E3FC;\n",
|
858 |
+
" }\n",
|
859 |
+
"\n",
|
860 |
+
" [theme=dark] .colab-df-generate:hover {\n",
|
861 |
+
" background-color: #434B5C;\n",
|
862 |
+
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
|
863 |
+
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
|
864 |
+
" fill: #FFFFFF;\n",
|
865 |
+
" }\n",
|
866 |
+
" </style>\n",
|
867 |
+
" <button class=\"colab-df-generate\" onclick=\"generateWithVariable('english_df')\"\n",
|
868 |
+
" title=\"Generate code using this dataframe.\"\n",
|
869 |
+
" style=\"display:none;\">\n",
|
870 |
+
"\n",
|
871 |
+
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
|
872 |
+
" width=\"24px\">\n",
|
873 |
+
" <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n",
|
874 |
+
" </svg>\n",
|
875 |
+
" </button>\n",
|
876 |
+
" <script>\n",
|
877 |
+
" (() => {\n",
|
878 |
+
" const buttonEl =\n",
|
879 |
+
" document.querySelector('#id_ffa98c39-a611-4929-a669-d3f7b8d8d0ae button.colab-df-generate');\n",
|
880 |
+
" buttonEl.style.display =\n",
|
881 |
+
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
|
882 |
+
"\n",
|
883 |
+
" buttonEl.onclick = () => {\n",
|
884 |
+
" google.colab.notebook.generateWithVariable('english_df');\n",
|
885 |
+
" }\n",
|
886 |
+
" })();\n",
|
887 |
+
" </script>\n",
|
888 |
+
" </div>\n",
|
889 |
+
"\n",
|
890 |
+
" </div>\n",
|
891 |
+
" </div>\n"
|
892 |
+
],
|
893 |
+
"application/vnd.google.colaboratory.intrinsic+json": {
|
894 |
+
"type": "dataframe",
|
895 |
+
"variable_name": "english_df",
|
896 |
+
"summary": "{\n \"name\": \"english_df\",\n \"rows\": 6,\n \"fields\": [\n {\n \"column\": \"label\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 2,\n \"samples\": [\n \"NEGATIVE\",\n \"POSITIVE\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"score\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.20175035173408953,\n \"min\": 0.5054381489753723,\n \"max\": 0.9998489618301392,\n \"num_unique_values\": 6,\n \"samples\": [\n 0.9998489618301392,\n 0.999841570854187\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Sentences\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 6,\n \"samples\": [\n \"What a great day!!! Looks like dream.\",\n \"Today first time I arrive in the boat. Its amazing journey\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
|
897 |
+
}
|
898 |
+
},
|
899 |
+
"metadata": {},
|
900 |
+
"execution_count": 20
|
901 |
+
}
|
902 |
+
]
|
903 |
+
},
|
904 |
+
{
|
905 |
+
"cell_type": "markdown",
|
906 |
+
"source": [
|
907 |
+
"### User Input Feature\n",
|
908 |
+
"\n",
|
909 |
+
"Here users can input thier own sentences for both English and Arabic languages, the results are then formatted and displayed in a table just like above."
|
910 |
+
],
|
911 |
+
"metadata": {
|
912 |
+
"id": "T5Kp_ICCfAOn"
|
913 |
+
}
|
914 |
+
},
|
915 |
+
{
|
916 |
+
"cell_type": "code",
|
917 |
+
"source": [
|
918 |
+
"# Analyze user's input for the Arabic language\n",
|
919 |
+
"\n",
|
920 |
+
"input_arb = input(\"Enter a sentece in Arabic: \") # Prompts the user to enter a sentence in Arabic\n",
|
921 |
+
"res_arb = arabic_analyzer(input_arb) # Perform sentiment-analysis on the input\n",
|
922 |
+
"df_in_arb = pd.DataFrame(res_arb) # Convert the results in a formatted table\n",
|
923 |
+
"df_in_arb['Sentence'] = input_arb # add column for the sentence\n",
|
924 |
+
"df_in_arb"
|
925 |
+
],
|
926 |
+
"metadata": {
|
927 |
+
"colab": {
|
928 |
+
"base_uri": "https://localhost:8080/",
|
929 |
+
"height": 106
|
930 |
+
},
|
931 |
+
"id": "WN8xMOZ8hFjJ",
|
932 |
+
"outputId": "285c0d46-cca9-4ea0-c55d-9ec97e3a6015"
|
933 |
+
},
|
934 |
+
"execution_count": 26,
|
935 |
+
"outputs": [
|
936 |
+
{
|
937 |
+
"name": "stdout",
|
938 |
+
"output_type": "stream",
|
939 |
+
"text": [
|
940 |
+
"Enter a sentece in Arabic: جميل\n"
|
941 |
+
]
|
942 |
+
},
|
943 |
+
{
|
944 |
+
"output_type": "execute_result",
|
945 |
+
"data": {
|
946 |
+
"text/plain": [
|
947 |
+
" label score Sentence\n",
|
948 |
+
"0 positive 0.943679 جميل"
|
949 |
+
],
|
950 |
+
"text/html": [
|
951 |
+
"\n",
|
952 |
+
" <div id=\"df-1b349c8a-83d2-4c3d-a25d-13b234e7ee9c\" class=\"colab-df-container\">\n",
|
953 |
+
" <div>\n",
|
954 |
+
"<style scoped>\n",
|
955 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
956 |
+
" vertical-align: middle;\n",
|
957 |
+
" }\n",
|
958 |
+
"\n",
|
959 |
+
" .dataframe tbody tr th {\n",
|
960 |
+
" vertical-align: top;\n",
|
961 |
+
" }\n",
|
962 |
+
"\n",
|
963 |
+
" .dataframe thead th {\n",
|
964 |
+
" text-align: right;\n",
|
965 |
+
" }\n",
|
966 |
+
"</style>\n",
|
967 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
968 |
+
" <thead>\n",
|
969 |
+
" <tr style=\"text-align: right;\">\n",
|
970 |
+
" <th></th>\n",
|
971 |
+
" <th>label</th>\n",
|
972 |
+
" <th>score</th>\n",
|
973 |
+
" <th>Sentence</th>\n",
|
974 |
+
" </tr>\n",
|
975 |
+
" </thead>\n",
|
976 |
+
" <tbody>\n",
|
977 |
+
" <tr>\n",
|
978 |
+
" <th>0</th>\n",
|
979 |
+
" <td>positive</td>\n",
|
980 |
+
" <td>0.943679</td>\n",
|
981 |
+
" <td>جميل</td>\n",
|
982 |
+
" </tr>\n",
|
983 |
+
" </tbody>\n",
|
984 |
+
"</table>\n",
|
985 |
+
"</div>\n",
|
986 |
+
" <div class=\"colab-df-buttons\">\n",
|
987 |
+
"\n",
|
988 |
+
" <div class=\"colab-df-container\">\n",
|
989 |
+
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-1b349c8a-83d2-4c3d-a25d-13b234e7ee9c')\"\n",
|
990 |
+
" title=\"Convert this dataframe to an interactive table.\"\n",
|
991 |
+
" style=\"display:none;\">\n",
|
992 |
+
"\n",
|
993 |
+
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
|
994 |
+
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
|
995 |
+
" </svg>\n",
|
996 |
+
" </button>\n",
|
997 |
+
"\n",
|
998 |
+
" <style>\n",
|
999 |
+
" .colab-df-container {\n",
|
1000 |
+
" display:flex;\n",
|
1001 |
+
" gap: 12px;\n",
|
1002 |
+
" }\n",
|
1003 |
+
"\n",
|
1004 |
+
" .colab-df-convert {\n",
|
1005 |
+
" background-color: #E8F0FE;\n",
|
1006 |
+
" border: none;\n",
|
1007 |
+
" border-radius: 50%;\n",
|
1008 |
+
" cursor: pointer;\n",
|
1009 |
+
" display: none;\n",
|
1010 |
+
" fill: #1967D2;\n",
|
1011 |
+
" height: 32px;\n",
|
1012 |
+
" padding: 0 0 0 0;\n",
|
1013 |
+
" width: 32px;\n",
|
1014 |
+
" }\n",
|
1015 |
+
"\n",
|
1016 |
+
" .colab-df-convert:hover {\n",
|
1017 |
+
" background-color: #E2EBFA;\n",
|
1018 |
+
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
|
1019 |
+
" fill: #174EA6;\n",
|
1020 |
+
" }\n",
|
1021 |
+
"\n",
|
1022 |
+
" .colab-df-buttons div {\n",
|
1023 |
+
" margin-bottom: 4px;\n",
|
1024 |
+
" }\n",
|
1025 |
+
"\n",
|
1026 |
+
" [theme=dark] .colab-df-convert {\n",
|
1027 |
+
" background-color: #3B4455;\n",
|
1028 |
+
" fill: #D2E3FC;\n",
|
1029 |
+
" }\n",
|
1030 |
+
"\n",
|
1031 |
+
" [theme=dark] .colab-df-convert:hover {\n",
|
1032 |
+
" background-color: #434B5C;\n",
|
1033 |
+
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
|
1034 |
+
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
|
1035 |
+
" fill: #FFFFFF;\n",
|
1036 |
+
" }\n",
|
1037 |
+
" </style>\n",
|
1038 |
+
"\n",
|
1039 |
+
" <script>\n",
|
1040 |
+
" const buttonEl =\n",
|
1041 |
+
" document.querySelector('#df-1b349c8a-83d2-4c3d-a25d-13b234e7ee9c button.colab-df-convert');\n",
|
1042 |
+
" buttonEl.style.display =\n",
|
1043 |
+
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
|
1044 |
+
"\n",
|
1045 |
+
" async function convertToInteractive(key) {\n",
|
1046 |
+
" const element = document.querySelector('#df-1b349c8a-83d2-4c3d-a25d-13b234e7ee9c');\n",
|
1047 |
+
" const dataTable =\n",
|
1048 |
+
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
|
1049 |
+
" [key], {});\n",
|
1050 |
+
" if (!dataTable) return;\n",
|
1051 |
+
"\n",
|
1052 |
+
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
|
1053 |
+
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
|
1054 |
+
" + ' to learn more about interactive tables.';\n",
|
1055 |
+
" element.innerHTML = '';\n",
|
1056 |
+
" dataTable['output_type'] = 'display_data';\n",
|
1057 |
+
" await google.colab.output.renderOutput(dataTable, element);\n",
|
1058 |
+
" const docLink = document.createElement('div');\n",
|
1059 |
+
" docLink.innerHTML = docLinkHtml;\n",
|
1060 |
+
" element.appendChild(docLink);\n",
|
1061 |
+
" }\n",
|
1062 |
+
" </script>\n",
|
1063 |
+
" </div>\n",
|
1064 |
+
"\n",
|
1065 |
+
"\n",
|
1066 |
+
" <div id=\"id_cc4f8c4c-95b5-4d5e-ad5b-16f293a2ff4e\">\n",
|
1067 |
+
" <style>\n",
|
1068 |
+
" .colab-df-generate {\n",
|
1069 |
+
" background-color: #E8F0FE;\n",
|
1070 |
+
" border: none;\n",
|
1071 |
+
" border-radius: 50%;\n",
|
1072 |
+
" cursor: pointer;\n",
|
1073 |
+
" display: none;\n",
|
1074 |
+
" fill: #1967D2;\n",
|
1075 |
+
" height: 32px;\n",
|
1076 |
+
" padding: 0 0 0 0;\n",
|
1077 |
+
" width: 32px;\n",
|
1078 |
+
" }\n",
|
1079 |
+
"\n",
|
1080 |
+
" .colab-df-generate:hover {\n",
|
1081 |
+
" background-color: #E2EBFA;\n",
|
1082 |
+
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
|
1083 |
+
" fill: #174EA6;\n",
|
1084 |
+
" }\n",
|
1085 |
+
"\n",
|
1086 |
+
" [theme=dark] .colab-df-generate {\n",
|
1087 |
+
" background-color: #3B4455;\n",
|
1088 |
+
" fill: #D2E3FC;\n",
|
1089 |
+
" }\n",
|
1090 |
+
"\n",
|
1091 |
+
" [theme=dark] .colab-df-generate:hover {\n",
|
1092 |
+
" background-color: #434B5C;\n",
|
1093 |
+
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
|
1094 |
+
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
|
1095 |
+
" fill: #FFFFFF;\n",
|
1096 |
+
" }\n",
|
1097 |
+
" </style>\n",
|
1098 |
+
" <button class=\"colab-df-generate\" onclick=\"generateWithVariable('df_in_arb')\"\n",
|
1099 |
+
" title=\"Generate code using this dataframe.\"\n",
|
1100 |
+
" style=\"display:none;\">\n",
|
1101 |
+
"\n",
|
1102 |
+
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
|
1103 |
+
" width=\"24px\">\n",
|
1104 |
+
" <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n",
|
1105 |
+
" </svg>\n",
|
1106 |
+
" </button>\n",
|
1107 |
+
" <script>\n",
|
1108 |
+
" (() => {\n",
|
1109 |
+
" const buttonEl =\n",
|
1110 |
+
" document.querySelector('#id_cc4f8c4c-95b5-4d5e-ad5b-16f293a2ff4e button.colab-df-generate');\n",
|
1111 |
+
" buttonEl.style.display =\n",
|
1112 |
+
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
|
1113 |
+
"\n",
|
1114 |
+
" buttonEl.onclick = () => {\n",
|
1115 |
+
" google.colab.notebook.generateWithVariable('df_in_arb');\n",
|
1116 |
+
" }\n",
|
1117 |
+
" })();\n",
|
1118 |
+
" </script>\n",
|
1119 |
+
" </div>\n",
|
1120 |
+
"\n",
|
1121 |
+
" </div>\n",
|
1122 |
+
" </div>\n"
|
1123 |
+
],
|
1124 |
+
"application/vnd.google.colaboratory.intrinsic+json": {
|
1125 |
+
"type": "dataframe",
|
1126 |
+
"variable_name": "df_in_arb",
|
1127 |
+
"summary": "{\n \"name\": \"df_in_arb\",\n \"rows\": 1,\n \"fields\": [\n {\n \"column\": \"label\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"positive\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"score\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 0.9436786770820618,\n \"max\": 0.9436786770820618,\n \"num_unique_values\": 1,\n \"samples\": [\n 0.9436786770820618\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Sentence\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"\\u062c\\u0645\\u064a\\u0644\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
|
1128 |
+
}
|
1129 |
+
},
|
1130 |
+
"metadata": {},
|
1131 |
+
"execution_count": 26
|
1132 |
+
}
|
1133 |
+
]
|
1134 |
+
},
|
1135 |
+
{
|
1136 |
+
"cell_type": "code",
|
1137 |
+
"source": [
|
1138 |
+
"# Analyze user's input for the English language\n",
|
1139 |
+
"\n",
|
1140 |
+
"input_eng = input(\"Enter a sentece in English: \") # Prompts the user to enter a sentence in English\n",
|
1141 |
+
"res_eng = english_analyzer (input_eng) # Perform sentiment-analysis on the input\n",
|
1142 |
+
"df_in_eng = pd.DataFrame(res_eng) # Convert the results in a formatted table\n",
|
1143 |
+
"df_in_eng['Sentence'] = input_eng # add column for the sentence\n",
|
1144 |
+
"df_in_eng"
|
1145 |
+
],
|
1146 |
+
"metadata": {
|
1147 |
+
"colab": {
|
1148 |
+
"base_uri": "https://localhost:8080/",
|
1149 |
+
"height": 106
|
1150 |
+
},
|
1151 |
+
"id": "ETvVN5pjfPRm",
|
1152 |
+
"outputId": "7631ed05-8952-4ea8-9314-9fc28281103a"
|
1153 |
+
},
|
1154 |
+
"execution_count": 25,
|
1155 |
+
"outputs": [
|
1156 |
+
{
|
1157 |
+
"name": "stdout",
|
1158 |
+
"output_type": "stream",
|
1159 |
+
"text": [
|
1160 |
+
"Enter a sentece in English: Good\n"
|
1161 |
+
]
|
1162 |
+
},
|
1163 |
+
{
|
1164 |
+
"output_type": "execute_result",
|
1165 |
+
"data": {
|
1166 |
+
"text/plain": [
|
1167 |
+
" label score Sentence\n",
|
1168 |
+
"0 POSITIVE 0.999816 Good"
|
1169 |
+
],
|
1170 |
+
"text/html": [
|
1171 |
+
"\n",
|
1172 |
+
" <div id=\"df-73a7f830-1b8b-4d83-9162-209ca8d3b70b\" class=\"colab-df-container\">\n",
|
1173 |
+
" <div>\n",
|
1174 |
+
"<style scoped>\n",
|
1175 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
1176 |
+
" vertical-align: middle;\n",
|
1177 |
+
" }\n",
|
1178 |
+
"\n",
|
1179 |
+
" .dataframe tbody tr th {\n",
|
1180 |
+
" vertical-align: top;\n",
|
1181 |
+
" }\n",
|
1182 |
+
"\n",
|
1183 |
+
" .dataframe thead th {\n",
|
1184 |
+
" text-align: right;\n",
|
1185 |
+
" }\n",
|
1186 |
+
"</style>\n",
|
1187 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
1188 |
+
" <thead>\n",
|
1189 |
+
" <tr style=\"text-align: right;\">\n",
|
1190 |
+
" <th></th>\n",
|
1191 |
+
" <th>label</th>\n",
|
1192 |
+
" <th>score</th>\n",
|
1193 |
+
" <th>Sentence</th>\n",
|
1194 |
+
" </tr>\n",
|
1195 |
+
" </thead>\n",
|
1196 |
+
" <tbody>\n",
|
1197 |
+
" <tr>\n",
|
1198 |
+
" <th>0</th>\n",
|
1199 |
+
" <td>POSITIVE</td>\n",
|
1200 |
+
" <td>0.999816</td>\n",
|
1201 |
+
" <td>Good</td>\n",
|
1202 |
+
" </tr>\n",
|
1203 |
+
" </tbody>\n",
|
1204 |
+
"</table>\n",
|
1205 |
+
"</div>\n",
|
1206 |
+
" <div class=\"colab-df-buttons\">\n",
|
1207 |
+
"\n",
|
1208 |
+
" <div class=\"colab-df-container\">\n",
|
1209 |
+
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-73a7f830-1b8b-4d83-9162-209ca8d3b70b')\"\n",
|
1210 |
+
" title=\"Convert this dataframe to an interactive table.\"\n",
|
1211 |
+
" style=\"display:none;\">\n",
|
1212 |
+
"\n",
|
1213 |
+
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
|
1214 |
+
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
|
1215 |
+
" </svg>\n",
|
1216 |
+
" </button>\n",
|
1217 |
+
"\n",
|
1218 |
+
" <style>\n",
|
1219 |
+
" .colab-df-container {\n",
|
1220 |
+
" display:flex;\n",
|
1221 |
+
" gap: 12px;\n",
|
1222 |
+
" }\n",
|
1223 |
+
"\n",
|
1224 |
+
" .colab-df-convert {\n",
|
1225 |
+
" background-color: #E8F0FE;\n",
|
1226 |
+
" border: none;\n",
|
1227 |
+
" border-radius: 50%;\n",
|
1228 |
+
" cursor: pointer;\n",
|
1229 |
+
" display: none;\n",
|
1230 |
+
" fill: #1967D2;\n",
|
1231 |
+
" height: 32px;\n",
|
1232 |
+
" padding: 0 0 0 0;\n",
|
1233 |
+
" width: 32px;\n",
|
1234 |
+
" }\n",
|
1235 |
+
"\n",
|
1236 |
+
" .colab-df-convert:hover {\n",
|
1237 |
+
" background-color: #E2EBFA;\n",
|
1238 |
+
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
|
1239 |
+
" fill: #174EA6;\n",
|
1240 |
+
" }\n",
|
1241 |
+
"\n",
|
1242 |
+
" .colab-df-buttons div {\n",
|
1243 |
+
" margin-bottom: 4px;\n",
|
1244 |
+
" }\n",
|
1245 |
+
"\n",
|
1246 |
+
" [theme=dark] .colab-df-convert {\n",
|
1247 |
+
" background-color: #3B4455;\n",
|
1248 |
+
" fill: #D2E3FC;\n",
|
1249 |
+
" }\n",
|
1250 |
+
"\n",
|
1251 |
+
" [theme=dark] .colab-df-convert:hover {\n",
|
1252 |
+
" background-color: #434B5C;\n",
|
1253 |
+
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
|
1254 |
+
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
|
1255 |
+
" fill: #FFFFFF;\n",
|
1256 |
+
" }\n",
|
1257 |
+
" </style>\n",
|
1258 |
+
"\n",
|
1259 |
+
" <script>\n",
|
1260 |
+
" const buttonEl =\n",
|
1261 |
+
" document.querySelector('#df-73a7f830-1b8b-4d83-9162-209ca8d3b70b button.colab-df-convert');\n",
|
1262 |
+
" buttonEl.style.display =\n",
|
1263 |
+
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
|
1264 |
+
"\n",
|
1265 |
+
" async function convertToInteractive(key) {\n",
|
1266 |
+
" const element = document.querySelector('#df-73a7f830-1b8b-4d83-9162-209ca8d3b70b');\n",
|
1267 |
+
" const dataTable =\n",
|
1268 |
+
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
|
1269 |
+
" [key], {});\n",
|
1270 |
+
" if (!dataTable) return;\n",
|
1271 |
+
"\n",
|
1272 |
+
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
|
1273 |
+
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
|
1274 |
+
" + ' to learn more about interactive tables.';\n",
|
1275 |
+
" element.innerHTML = '';\n",
|
1276 |
+
" dataTable['output_type'] = 'display_data';\n",
|
1277 |
+
" await google.colab.output.renderOutput(dataTable, element);\n",
|
1278 |
+
" const docLink = document.createElement('div');\n",
|
1279 |
+
" docLink.innerHTML = docLinkHtml;\n",
|
1280 |
+
" element.appendChild(docLink);\n",
|
1281 |
+
" }\n",
|
1282 |
+
" </script>\n",
|
1283 |
+
" </div>\n",
|
1284 |
+
"\n",
|
1285 |
+
"\n",
|
1286 |
+
" <div id=\"id_6a6706d1-7670-4671-9d32-ae2ad96a97b2\">\n",
|
1287 |
+
" <style>\n",
|
1288 |
+
" .colab-df-generate {\n",
|
1289 |
+
" background-color: #E8F0FE;\n",
|
1290 |
+
" border: none;\n",
|
1291 |
+
" border-radius: 50%;\n",
|
1292 |
+
" cursor: pointer;\n",
|
1293 |
+
" display: none;\n",
|
1294 |
+
" fill: #1967D2;\n",
|
1295 |
+
" height: 32px;\n",
|
1296 |
+
" padding: 0 0 0 0;\n",
|
1297 |
+
" width: 32px;\n",
|
1298 |
+
" }\n",
|
1299 |
+
"\n",
|
1300 |
+
" .colab-df-generate:hover {\n",
|
1301 |
+
" background-color: #E2EBFA;\n",
|
1302 |
+
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
|
1303 |
+
" fill: #174EA6;\n",
|
1304 |
+
" }\n",
|
1305 |
+
"\n",
|
1306 |
+
" [theme=dark] .colab-df-generate {\n",
|
1307 |
+
" background-color: #3B4455;\n",
|
1308 |
+
" fill: #D2E3FC;\n",
|
1309 |
+
" }\n",
|
1310 |
+
"\n",
|
1311 |
+
" [theme=dark] .colab-df-generate:hover {\n",
|
1312 |
+
" background-color: #434B5C;\n",
|
1313 |
+
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
|
1314 |
+
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
|
1315 |
+
" fill: #FFFFFF;\n",
|
1316 |
+
" }\n",
|
1317 |
+
" </style>\n",
|
1318 |
+
" <button class=\"colab-df-generate\" onclick=\"generateWithVariable('df_in_eng')\"\n",
|
1319 |
+
" title=\"Generate code using this dataframe.\"\n",
|
1320 |
+
" style=\"display:none;\">\n",
|
1321 |
+
"\n",
|
1322 |
+
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
|
1323 |
+
" width=\"24px\">\n",
|
1324 |
+
" <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n",
|
1325 |
+
" </svg>\n",
|
1326 |
+
" </button>\n",
|
1327 |
+
" <script>\n",
|
1328 |
+
" (() => {\n",
|
1329 |
+
" const buttonEl =\n",
|
1330 |
+
" document.querySelector('#id_6a6706d1-7670-4671-9d32-ae2ad96a97b2 button.colab-df-generate');\n",
|
1331 |
+
" buttonEl.style.display =\n",
|
1332 |
+
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
|
1333 |
+
"\n",
|
1334 |
+
" buttonEl.onclick = () => {\n",
|
1335 |
+
" google.colab.notebook.generateWithVariable('df_in_eng');\n",
|
1336 |
+
" }\n",
|
1337 |
+
" })();\n",
|
1338 |
+
" </script>\n",
|
1339 |
+
" </div>\n",
|
1340 |
+
"\n",
|
1341 |
+
" </div>\n",
|
1342 |
+
" </div>\n"
|
1343 |
+
],
|
1344 |
+
"application/vnd.google.colaboratory.intrinsic+json": {
|
1345 |
+
"type": "dataframe",
|
1346 |
+
"variable_name": "df_in_eng",
|
1347 |
+
"summary": "{\n \"name\": \"df_in_eng\",\n \"rows\": 1,\n \"fields\": [\n {\n \"column\": \"label\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"POSITIVE\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"score\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 0.9998161196708679,\n \"max\": 0.9998161196708679,\n \"num_unique_values\": 1,\n \"samples\": [\n 0.9998161196708679\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Sentence\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"Good\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
|
1348 |
+
}
|
1349 |
+
},
|
1350 |
+
"metadata": {},
|
1351 |
+
"execution_count": 25
|
1352 |
+
}
|
1353 |
+
]
|
1354 |
+
}
|
1355 |
+
]
|
1356 |
+
}
|