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error",
13
+ "traceback": [
14
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
15
+ "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
16
+ "Input \u001b[0;32mIn [49]\u001b[0m, in \u001b[0;36m<cell line: 12>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mnltk\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mstem\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mporter\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m PorterStemmer\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpattern\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtext\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01men\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m singularize\n\u001b[0;32m---> 12\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpandarallel\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m pandarallel \u001b[38;5;66;03m# Parallel workers on pandas dataframe\u001b[39;00m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01munidecode\u001b[39;00m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mre\u001b[39;00m \n",
17
+ "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'pandarallel'"
18
+ ]
19
+ }
20
+ ],
21
+ "source": [
22
+ "import numpy as np # linear algebra\n",
23
+ "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
24
+ "import matplotlib.pyplot as plt # Used to do plots\n",
25
+ "%matplotlib inline\n",
26
+ "\n",
27
+ "import nltk \n",
28
+ "from nltk.corpus import stopwords # Stopwords \n",
29
+ "from nltk.tokenize import word_tokenize # Word_tokenizer\n",
30
+ "from nltk.stem.porter import PorterStemmer\n",
31
+ "from pattern.text.en import singularize\n",
32
+ "\n",
33
+ "from pandarallel import pandarallel # Parallel workers on pandas dataframe\n",
34
+ "\n",
35
+ "import unidecode\n",
36
+ "import re \n",
37
+ "import time\n",
38
+ "import string\n",
39
+ "import statistics\n",
40
+ "\n",
41
+ "from datetime import datetime"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": 9,
47
+ "id": "d1ef5e57",
48
+ "metadata": {},
49
+ "outputs": [
50
+ {
51
+ "name": "stdout",
52
+ "output_type": "stream",
53
+ "text": [
54
+ "Collecting pattern\n",
55
+ " Downloading Pattern-3.6.0.tar.gz (22.2 MB)\n",
56
+ "\u001b[2K \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m22.2/22.2 MB\u001b[0m \u001b[31m201.5 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0mm eta \u001b[36m0:00:01\u001b[0m[36m0:00:03\u001b[0m\n",
57
+ "\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25ldone\n",
58
+ "\u001b[?25hRequirement already satisfied: future in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from pattern) (0.18.2)\n",
59
+ "Collecting backports.csv (from pattern)\n",
60
+ " Downloading backports.csv-1.0.7-py2.py3-none-any.whl.metadata (4.0 kB)\n",
61
+ "Collecting mysqlclient (from pattern)\n",
62
+ " Downloading mysqlclient-2.2.4.tar.gz (90 kB)\n",
63
+ "\u001b[2K \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m90.4/90.4 kB\u001b[0m \u001b[31m339.8 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m1m362.1 kB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\n",
64
+ "\u001b[?25h Installing build dependencies ... \u001b[?25ldone\n",
65
+ "\u001b[?25h Getting requirements to build wheel ... \u001b[?25ldone\n",
66
+ "\u001b[?25h Preparing metadata (pyproject.toml) ... \u001b[?25ldone\n",
67
+ "\u001b[?25hRequirement already satisfied: beautifulsoup4 in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from pattern) (4.11.1)\n",
68
+ "Requirement already satisfied: lxml in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from pattern) (4.9.1)\n",
69
+ "Collecting feedparser (from pattern)\n",
70
+ " Downloading feedparser-6.0.11-py3-none-any.whl.metadata (2.4 kB)\n",
71
+ "Collecting pdfminer.six (from pattern)\n",
72
+ " Downloading pdfminer.six-20240706-py3-none-any.whl.metadata (4.1 kB)\n",
73
+ "Requirement already satisfied: numpy in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from pattern) (1.24.3)\n",
74
+ "Requirement already satisfied: scipy in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from pattern) (1.9.1)\n",
75
+ "Requirement already satisfied: nltk in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from pattern) (3.8.1)\n",
76
+ "Collecting python-docx (from pattern)\n",
77
+ " Downloading python_docx-1.1.2-py3-none-any.whl.metadata (2.0 kB)\n",
78
+ "Collecting cherrypy (from pattern)\n",
79
+ " Downloading CherryPy-18.10.0-py3-none-any.whl.metadata (8.7 kB)\n",
80
+ "Requirement already satisfied: requests in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from pattern) (2.28.1)\n",
81
+ "Requirement already satisfied: soupsieve>1.2 in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from beautifulsoup4->pattern) (2.3.1)\n",
82
+ "Collecting cheroot>=8.2.1 (from cherrypy->pattern)\n",
83
+ " Downloading cheroot-10.0.1-py3-none-any.whl.metadata (7.1 kB)\n",
84
+ "Collecting portend>=2.1.1 (from cherrypy->pattern)\n",
85
+ " Downloading portend-3.2.0-py3-none-any.whl.metadata (3.6 kB)\n",
86
+ "Collecting more-itertools (from cherrypy->pattern)\n",
87
+ " Downloading more_itertools-10.4.0-py3-none-any.whl.metadata (36 kB)\n",
88
+ "Collecting zc.lockfile (from cherrypy->pattern)\n",
89
+ " Downloading zc.lockfile-3.0.post1-py3-none-any.whl.metadata (6.2 kB)\n",
90
+ "Collecting jaraco.collections (from cherrypy->pattern)\n",
91
+ " Downloading jaraco.collections-5.0.1-py3-none-any.whl.metadata (3.8 kB)\n",
92
+ "Collecting sgmllib3k (from feedparser->pattern)\n",
93
+ " Downloading sgmllib3k-1.0.0.tar.gz (5.8 kB)\n",
94
+ " Preparing metadata (setup.py) ... \u001b[?25ldone\n",
95
+ "\u001b[?25hRequirement already satisfied: click in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from nltk->pattern) (8.0.4)\n",
96
+ "Requirement already satisfied: joblib in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from nltk->pattern) (1.3.2)\n",
97
+ "Requirement already satisfied: regex>=2021.8.3 in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from nltk->pattern) (2022.7.9)\n",
98
+ "Requirement already satisfied: tqdm in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from nltk->pattern) (4.64.1)\n",
99
+ "Requirement already satisfied: charset-normalizer>=2.0.0 in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from pdfminer.six->pattern) (2.0.4)\n",
100
+ "Requirement already satisfied: cryptography>=36.0.0 in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from pdfminer.six->pattern) (37.0.1)\n",
101
+ "Collecting typing-extensions>=4.9.0 (from python-docx->pattern)\n",
102
+ " Downloading typing_extensions-4.12.2-py3-none-any.whl.metadata (3.0 kB)\n",
103
+ "Requirement already satisfied: idna<4,>=2.5 in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from requests->pattern) (3.3)\n",
104
+ "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from requests->pattern) (1.26.11)\n",
105
+ "Requirement already satisfied: certifi>=2017.4.17 in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from requests->pattern) (2023.7.22)\n",
106
+ "Collecting jaraco.functools (from cheroot>=8.2.1->cherrypy->pattern)\n",
107
+ " Downloading jaraco.functools-4.0.2-py3-none-any.whl.metadata (2.8 kB)\n",
108
+ "Requirement already satisfied: cffi>=1.12 in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from cryptography>=36.0.0->pdfminer.six->pattern) (1.15.1)\n",
109
+ "Collecting tempora>=1.8 (from portend>=2.1.1->cherrypy->pattern)\n",
110
+ " Downloading tempora-5.7.0-py3-none-any.whl.metadata (3.2 kB)\n",
111
+ "Collecting jaraco.text (from jaraco.collections->cherrypy->pattern)\n",
112
+ " Downloading jaraco.text-4.0.0-py3-none-any.whl.metadata (3.7 kB)\n",
113
+ "Requirement already satisfied: setuptools in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from zc.lockfile->cherrypy->pattern) (63.4.1)\n",
114
+ "Requirement already satisfied: pycparser in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from cffi>=1.12->cryptography>=36.0.0->pdfminer.six->pattern) (2.21)\n",
115
+ "Requirement already satisfied: python-dateutil in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from tempora>=1.8->portend>=2.1.1->cherrypy->pattern) (2.8.2)\n",
116
+ "Collecting jaraco.context>=4.1 (from jaraco.text->jaraco.collections->cherrypy->pattern)\n",
117
+ " Downloading jaraco.context-5.3.0-py3-none-any.whl.metadata (4.0 kB)\n",
118
+ "Collecting autocommand (from jaraco.text->jaraco.collections->cherrypy->pattern)\n",
119
+ " Downloading autocommand-2.2.2-py3-none-any.whl.metadata (15 kB)\n",
120
+ "Collecting backports.tarfile (from jaraco.context>=4.1->jaraco.text->jaraco.collections->cherrypy->pattern)\n",
121
+ " Downloading backports.tarfile-1.2.0-py3-none-any.whl.metadata (2.0 kB)\n",
122
+ "Requirement already satisfied: six>=1.5 in /Users/ramtin/anaconda3/envs/py39/lib/python3.9/site-packages (from python-dateutil->tempora>=1.8->portend>=2.1.1->cherrypy->pattern) (1.16.0)\n",
123
+ "Downloading backports.csv-1.0.7-py2.py3-none-any.whl (12 kB)\n",
124
+ "Downloading CherryPy-18.10.0-py3-none-any.whl (349 kB)\n",
125
+ "\u001b[2K \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m349.8/349.8 kB\u001b[0m \u001b[31m308.8 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m1m336.8 kB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\n",
126
+ "\u001b[?25hDownloading feedparser-6.0.11-py3-none-any.whl (81 kB)\n",
127
+ "\u001b[2K \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m81.3/81.3 kB\u001b[0m \u001b[31m352.7 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m kB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\n",
128
+ "\u001b[?25hDownloading pdfminer.six-20240706-py3-none-any.whl (5.6 MB)\n",
129
+ "\u001b[2K \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.6/5.6 MB\u001b[0m \u001b[31m219.0 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0mm eta \u001b[36m0:00:01\u001b[0m[36m0:00:01\u001b[0m\n",
130
+ "\u001b[?25hDownloading python_docx-1.1.2-py3-none-any.whl (244 kB)\n",
131
+ "\u001b[2K \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m244.3/244.3 kB\u001b[0m \u001b[31m220.7 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m1m216.4 kB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\n",
132
+ "\u001b[?25hDownloading cheroot-10.0.1-py3-none-any.whl (104 kB)\n",
133
+ "\u001b[2K \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m104.8/104.8 kB\u001b[0m \u001b[31m185.9 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m kB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m:01\u001b[0m\n",
134
+ "\u001b[?25hDownloading more_itertools-10.4.0-py3-none-any.whl (60 kB)\n",
135
+ "\u001b[2K \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m60.9/60.9 kB\u001b[0m \u001b[31m204.1 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m1m177.4 kB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\n",
136
+ "\u001b[?25hDownloading portend-3.2.0-py3-none-any.whl (5.3 kB)\n",
137
+ "Downloading typing_extensions-4.12.2-py3-none-any.whl (37 kB)\n",
138
+ "Downloading jaraco.collections-5.0.1-py3-none-any.whl (10 kB)\n",
139
+ "Downloading zc.lockfile-3.0.post1-py3-none-any.whl (9.8 kB)\n",
140
+ "Downloading tempora-5.7.0-py3-none-any.whl (13 kB)\n",
141
+ "Downloading jaraco.functools-4.0.2-py3-none-any.whl (9.9 kB)\n",
142
+ "Downloading jaraco.text-4.0.0-py3-none-any.whl (11 kB)\n",
143
+ "Downloading jaraco.context-5.3.0-py3-none-any.whl (6.5 kB)\n",
144
+ "Downloading autocommand-2.2.2-py3-none-any.whl (19 kB)\n"
145
+ ]
146
+ },
147
+ {
148
+ "name": "stdout",
149
+ "output_type": "stream",
150
+ "text": [
151
+ "Downloading backports.tarfile-1.2.0-py3-none-any.whl (30 kB)\n",
152
+ "Building wheels for collected packages: pattern, mysqlclient, sgmllib3k\n",
153
+ " Building wheel for pattern (setup.py) ... \u001b[?25ldone\n",
154
+ "\u001b[?25h Created wheel for pattern: filename=Pattern-3.6-py3-none-any.whl size=22332702 sha256=87d88aa6ebbfcb7d72318a2a3f803172542546b39356f04a9963ee0f84e0b5d9\n",
155
+ " Stored in directory: /Users/ramtin/Library/Caches/pip/wheels/50/33/f3/ea00b80d50c09f210588bda15ec60bdb38b289b452577cd5c3\n",
156
+ " Building wheel for mysqlclient (pyproject.toml) ... \u001b[?25ldone\n",
157
+ "\u001b[?25h Created wheel for mysqlclient: filename=mysqlclient-2.2.4-cp39-cp39-macosx_11_0_arm64.whl size=73775 sha256=486b18a9927e86835857d7cd65ca1488f7324577c97c4f1c9d6d8c90b2926cbb\n",
158
+ " Stored in directory: /Users/ramtin/Library/Caches/pip/wheels/df/23/68/faa07b93488a130b3295ca4e91574e85a9dc4764cd463bc152\n",
159
+ " Building wheel for sgmllib3k (setup.py) ... \u001b[?25ldone\n",
160
+ "\u001b[?25h Created wheel for sgmllib3k: filename=sgmllib3k-1.0.0-py3-none-any.whl size=6048 sha256=1143b02b589d8d7c77c44e86a44ce647e51698927b9243e3964e0562e3ef887d\n",
161
+ " Stored in directory: /Users/ramtin/Library/Caches/pip/wheels/65/7a/a7/78c287f64e401255dff4c13fdbc672fed5efbfd21c530114e1\n",
162
+ "Successfully built pattern mysqlclient sgmllib3k\n",
163
+ "Installing collected packages: sgmllib3k, backports.csv, zc.lockfile, typing-extensions, mysqlclient, more-itertools, feedparser, backports.tarfile, autocommand, python-docx, jaraco.functools, jaraco.context, tempora, pdfminer.six, jaraco.text, cheroot, portend, jaraco.collections, cherrypy, pattern\n",
164
+ " Attempting uninstall: typing-extensions\n",
165
+ " Found existing installation: typing_extensions 4.8.0\n",
166
+ " Uninstalling typing_extensions-4.8.0:\n",
167
+ " Successfully uninstalled typing_extensions-4.8.0\n",
168
+ "Successfully installed autocommand-2.2.2 backports.csv-1.0.7 backports.tarfile-1.2.0 cheroot-10.0.1 cherrypy-18.10.0 feedparser-6.0.11 jaraco.collections-5.0.1 jaraco.context-5.3.0 jaraco.functools-4.0.2 jaraco.text-4.0.0 more-itertools-10.4.0 mysqlclient-2.2.4 pattern-3.6 pdfminer.six-20240706 portend-3.2.0 python-docx-1.1.2 sgmllib3k-1.0.0 tempora-5.7.0 typing-extensions-4.12.2 zc.lockfile-3.0.post1\n",
169
+ "\n",
170
+ "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n",
171
+ "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
172
+ ]
173
+ }
174
+ ],
175
+ "source": [
176
+ "!pip install pattern"
177
+ ]
178
+ },
179
+ {
180
+ "cell_type": "code",
181
+ "execution_count": 14,
182
+ "id": "cde34094",
183
+ "metadata": {},
184
+ "outputs": [
185
+ {
186
+ "name": "stdout",
187
+ "output_type": "stream",
188
+ "text": [
189
+ "User reviews shape: (573913, 7)\n"
190
+ ]
191
+ }
192
+ ],
193
+ "source": [
194
+ "df_reviews = pd.read_json('kaggle/input/IMDB_reviews.json', lines=True) \n",
195
+ "print('User reviews shape: ', df_reviews.shape)"
196
+ ]
197
+ },
198
+ {
199
+ "cell_type": "code",
200
+ "execution_count": 15,
201
+ "id": "94060a02",
202
+ "metadata": {},
203
+ "outputs": [
204
+ {
205
+ "data": {
206
+ "text/html": [
207
+ "<div>\n",
208
+ "<style scoped>\n",
209
+ " .dataframe tbody tr th:only-of-type {\n",
210
+ " vertical-align: middle;\n",
211
+ " }\n",
212
+ "\n",
213
+ " .dataframe tbody tr th {\n",
214
+ " vertical-align: top;\n",
215
+ " }\n",
216
+ "\n",
217
+ " .dataframe thead th {\n",
218
+ " text-align: right;\n",
219
+ " }\n",
220
+ "</style>\n",
221
+ "<table border=\"1\" class=\"dataframe\">\n",
222
+ " <thead>\n",
223
+ " <tr style=\"text-align: right;\">\n",
224
+ " <th></th>\n",
225
+ " <th>review_date</th>\n",
226
+ " <th>movie_id</th>\n",
227
+ " <th>user_id</th>\n",
228
+ " <th>is_spoiler</th>\n",
229
+ " <th>review_text</th>\n",
230
+ " <th>rating</th>\n",
231
+ " <th>review_summary</th>\n",
232
+ " </tr>\n",
233
+ " </thead>\n",
234
+ " <tbody>\n",
235
+ " <tr>\n",
236
+ " <th>0</th>\n",
237
+ " <td>10 February 2006</td>\n",
238
+ " <td>tt0111161</td>\n",
239
+ " <td>ur1898687</td>\n",
240
+ " <td>True</td>\n",
241
+ " <td>In its Oscar year, Shawshank Redemption (writt...</td>\n",
242
+ " <td>10</td>\n",
243
+ " <td>A classic piece of unforgettable film-making.</td>\n",
244
+ " </tr>\n",
245
+ " <tr>\n",
246
+ " <th>1</th>\n",
247
+ " <td>6 September 2000</td>\n",
248
+ " <td>tt0111161</td>\n",
249
+ " <td>ur0842118</td>\n",
250
+ " <td>True</td>\n",
251
+ " <td>The Shawshank Redemption is without a doubt on...</td>\n",
252
+ " <td>10</td>\n",
253
+ " <td>Simply amazing. The best film of the 90's.</td>\n",
254
+ " </tr>\n",
255
+ " <tr>\n",
256
+ " <th>2</th>\n",
257
+ " <td>3 August 2001</td>\n",
258
+ " <td>tt0111161</td>\n",
259
+ " <td>ur1285640</td>\n",
260
+ " <td>True</td>\n",
261
+ " <td>I believe that this film is the best story eve...</td>\n",
262
+ " <td>8</td>\n",
263
+ " <td>The best story ever told on film</td>\n",
264
+ " </tr>\n",
265
+ " <tr>\n",
266
+ " <th>3</th>\n",
267
+ " <td>1 September 2002</td>\n",
268
+ " <td>tt0111161</td>\n",
269
+ " <td>ur1003471</td>\n",
270
+ " <td>True</td>\n",
271
+ " <td>**Yes, there are SPOILERS here**This film has ...</td>\n",
272
+ " <td>10</td>\n",
273
+ " <td>Busy dying or busy living?</td>\n",
274
+ " </tr>\n",
275
+ " <tr>\n",
276
+ " <th>4</th>\n",
277
+ " <td>20 May 2004</td>\n",
278
+ " <td>tt0111161</td>\n",
279
+ " <td>ur0226855</td>\n",
280
+ " <td>True</td>\n",
281
+ " <td>At the heart of this extraordinary movie is a ...</td>\n",
282
+ " <td>8</td>\n",
283
+ " <td>Great story, wondrously told and acted</td>\n",
284
+ " </tr>\n",
285
+ " </tbody>\n",
286
+ "</table>\n",
287
+ "</div>"
288
+ ],
289
+ "text/plain": [
290
+ " review_date movie_id user_id is_spoiler \\\n",
291
+ "0 10 February 2006 tt0111161 ur1898687 True \n",
292
+ "1 6 September 2000 tt0111161 ur0842118 True \n",
293
+ "2 3 August 2001 tt0111161 ur1285640 True \n",
294
+ "3 1 September 2002 tt0111161 ur1003471 True \n",
295
+ "4 20 May 2004 tt0111161 ur0226855 True \n",
296
+ "\n",
297
+ " review_text rating \\\n",
298
+ "0 In its Oscar year, Shawshank Redemption (writt... 10 \n",
299
+ "1 The Shawshank Redemption is without a doubt on... 10 \n",
300
+ "2 I believe that this film is the best story eve... 8 \n",
301
+ "3 **Yes, there are SPOILERS here**This film has ... 10 \n",
302
+ "4 At the heart of this extraordinary movie is a ... 8 \n",
303
+ "\n",
304
+ " review_summary \n",
305
+ "0 A classic piece of unforgettable film-making. \n",
306
+ "1 Simply amazing. The best film of the 90's. \n",
307
+ "2 The best story ever told on film \n",
308
+ "3 Busy dying or busy living? \n",
309
+ "4 Great story, wondrously told and acted "
310
+ ]
311
+ },
312
+ "execution_count": 15,
313
+ "metadata": {},
314
+ "output_type": "execute_result"
315
+ }
316
+ ],
317
+ "source": [
318
+ "df_reviews.head()"
319
+ ]
320
+ },
321
+ {
322
+ "cell_type": "code",
323
+ "execution_count": 16,
324
+ "id": "da5a873c",
325
+ "metadata": {},
326
+ "outputs": [
327
+ {
328
+ "name": "stdout",
329
+ "output_type": "stream",
330
+ "text": [
331
+ "<class 'pandas.core.frame.DataFrame'>\n",
332
+ "RangeIndex: 573913 entries, 0 to 573912\n",
333
+ "Data columns (total 7 columns):\n",
334
+ " # Column Non-Null Count Dtype \n",
335
+ "--- ------ -------------- ----- \n",
336
+ " 0 review_date 573913 non-null object\n",
337
+ " 1 movie_id 573913 non-null object\n",
338
+ " 2 user_id 573913 non-null object\n",
339
+ " 3 is_spoiler 573913 non-null bool \n",
340
+ " 4 review_text 573913 non-null object\n",
341
+ " 5 rating 573913 non-null int64 \n",
342
+ " 6 review_summary 573913 non-null object\n",
343
+ "dtypes: bool(1), int64(1), object(5)\n",
344
+ "memory usage: 26.8+ MB\n"
345
+ ]
346
+ }
347
+ ],
348
+ "source": [
349
+ "df_reviews.info()"
350
+ ]
351
+ },
352
+ {
353
+ "cell_type": "code",
354
+ "execution_count": 17,
355
+ "id": "b9fd9dad",
356
+ "metadata": {},
357
+ "outputs": [
358
+ {
359
+ "name": "stdout",
360
+ "output_type": "stream",
361
+ "text": [
362
+ "User reviews shape: (1572, 7)\n"
363
+ ]
364
+ }
365
+ ],
366
+ "source": [
367
+ "df_details = pd.read_json('kaggle/input/IMDB_movie_details.json', lines=True) \n",
368
+ "print('User reviews shape: ', df_details.shape)"
369
+ ]
370
+ },
371
+ {
372
+ "cell_type": "code",
373
+ "execution_count": 18,
374
+ "id": "9ea16b9c",
375
+ "metadata": {},
376
+ "outputs": [
377
+ {
378
+ "data": {
379
+ "text/html": [
380
+ "<div>\n",
381
+ "<style scoped>\n",
382
+ " .dataframe tbody tr th:only-of-type {\n",
383
+ " vertical-align: middle;\n",
384
+ " }\n",
385
+ "\n",
386
+ " .dataframe tbody tr th {\n",
387
+ " vertical-align: top;\n",
388
+ " }\n",
389
+ "\n",
390
+ " .dataframe thead th {\n",
391
+ " text-align: right;\n",
392
+ " }\n",
393
+ "</style>\n",
394
+ "<table border=\"1\" class=\"dataframe\">\n",
395
+ " <thead>\n",
396
+ " <tr style=\"text-align: right;\">\n",
397
+ " <th></th>\n",
398
+ " <th>movie_id</th>\n",
399
+ " <th>plot_summary</th>\n",
400
+ " <th>duration</th>\n",
401
+ " <th>genre</th>\n",
402
+ " <th>rating</th>\n",
403
+ " <th>release_date</th>\n",
404
+ " <th>plot_synopsis</th>\n",
405
+ " </tr>\n",
406
+ " </thead>\n",
407
+ " <tbody>\n",
408
+ " <tr>\n",
409
+ " <th>0</th>\n",
410
+ " <td>tt0105112</td>\n",
411
+ " <td>Former CIA analyst, Jack Ryan is in England wi...</td>\n",
412
+ " <td>1h 57min</td>\n",
413
+ " <td>[Action, Thriller]</td>\n",
414
+ " <td>6.9</td>\n",
415
+ " <td>1992-06-05</td>\n",
416
+ " <td>Jack Ryan (Ford) is on a \"working vacation\" in...</td>\n",
417
+ " </tr>\n",
418
+ " <tr>\n",
419
+ " <th>1</th>\n",
420
+ " <td>tt1204975</td>\n",
421
+ " <td>Billy (Michael Douglas), Paddy (Robert De Niro...</td>\n",
422
+ " <td>1h 45min</td>\n",
423
+ " <td>[Comedy]</td>\n",
424
+ " <td>6.6</td>\n",
425
+ " <td>2013-11-01</td>\n",
426
+ " <td>Four boys around the age of 10 are friends in ...</td>\n",
427
+ " </tr>\n",
428
+ " <tr>\n",
429
+ " <th>2</th>\n",
430
+ " <td>tt0243655</td>\n",
431
+ " <td>The setting is Camp Firewood, the year 1981. I...</td>\n",
432
+ " <td>1h 37min</td>\n",
433
+ " <td>[Comedy, Romance]</td>\n",
434
+ " <td>6.7</td>\n",
435
+ " <td>2002-04-11</td>\n",
436
+ " <td></td>\n",
437
+ " </tr>\n",
438
+ " <tr>\n",
439
+ " <th>3</th>\n",
440
+ " <td>tt0040897</td>\n",
441
+ " <td>Fred C. Dobbs and Bob Curtin, both down on the...</td>\n",
442
+ " <td>2h 6min</td>\n",
443
+ " <td>[Adventure, Drama, Western]</td>\n",
444
+ " <td>8.3</td>\n",
445
+ " <td>1948-01-24</td>\n",
446
+ " <td>Fred Dobbs (Humphrey Bogart) and Bob Curtin (T...</td>\n",
447
+ " </tr>\n",
448
+ " <tr>\n",
449
+ " <th>4</th>\n",
450
+ " <td>tt0126886</td>\n",
451
+ " <td>Tracy Flick is running unopposed for this year...</td>\n",
452
+ " <td>1h 43min</td>\n",
453
+ " <td>[Comedy, Drama, Romance]</td>\n",
454
+ " <td>7.3</td>\n",
455
+ " <td>1999-05-07</td>\n",
456
+ " <td>Jim McAllister (Matthew Broderick) is a much-a...</td>\n",
457
+ " </tr>\n",
458
+ " </tbody>\n",
459
+ "</table>\n",
460
+ "</div>"
461
+ ],
462
+ "text/plain": [
463
+ " movie_id plot_summary duration \\\n",
464
+ "0 tt0105112 Former CIA analyst, Jack Ryan is in England wi... 1h 57min \n",
465
+ "1 tt1204975 Billy (Michael Douglas), Paddy (Robert De Niro... 1h 45min \n",
466
+ "2 tt0243655 The setting is Camp Firewood, the year 1981. I... 1h 37min \n",
467
+ "3 tt0040897 Fred C. Dobbs and Bob Curtin, both down on the... 2h 6min \n",
468
+ "4 tt0126886 Tracy Flick is running unopposed for this year... 1h 43min \n",
469
+ "\n",
470
+ " genre rating release_date \\\n",
471
+ "0 [Action, Thriller] 6.9 1992-06-05 \n",
472
+ "1 [Comedy] 6.6 2013-11-01 \n",
473
+ "2 [Comedy, Romance] 6.7 2002-04-11 \n",
474
+ "3 [Adventure, Drama, Western] 8.3 1948-01-24 \n",
475
+ "4 [Comedy, Drama, Romance] 7.3 1999-05-07 \n",
476
+ "\n",
477
+ " plot_synopsis \n",
478
+ "0 Jack Ryan (Ford) is on a \"working vacation\" in... \n",
479
+ "1 Four boys around the age of 10 are friends in ... \n",
480
+ "2 \n",
481
+ "3 Fred Dobbs (Humphrey Bogart) and Bob Curtin (T... \n",
482
+ "4 Jim McAllister (Matthew Broderick) is a much-a... "
483
+ ]
484
+ },
485
+ "execution_count": 18,
486
+ "metadata": {},
487
+ "output_type": "execute_result"
488
+ }
489
+ ],
490
+ "source": [
491
+ "df_details.head()"
492
+ ]
493
+ },
494
+ {
495
+ "cell_type": "code",
496
+ "execution_count": 20,
497
+ "id": "a7591d12",
498
+ "metadata": {},
499
+ "outputs": [
500
+ {
501
+ "name": "stdout",
502
+ "output_type": "stream",
503
+ "text": [
504
+ "<class 'pandas.core.frame.DataFrame'>\n",
505
+ "RangeIndex: 1572 entries, 0 to 1571\n",
506
+ "Data columns (total 7 columns):\n",
507
+ " # Column Non-Null Count Dtype \n",
508
+ "--- ------ -------------- ----- \n",
509
+ " 0 movie_id 1572 non-null object \n",
510
+ " 1 plot_summary 1572 non-null object \n",
511
+ " 2 duration 1572 non-null object \n",
512
+ " 3 genre 1572 non-null object \n",
513
+ " 4 rating 1572 non-null float64\n",
514
+ " 5 release_date 1572 non-null object \n",
515
+ " 6 plot_synopsis 1572 non-null object \n",
516
+ "dtypes: float64(1), object(6)\n",
517
+ "memory usage: 86.1+ KB\n"
518
+ ]
519
+ }
520
+ ],
521
+ "source": [
522
+ "df_details.info()"
523
+ ]
524
+ },
525
+ {
526
+ "cell_type": "code",
527
+ "execution_count": 28,
528
+ "id": "0e45373d",
529
+ "metadata": {},
530
+ "outputs": [
531
+ {
532
+ "data": {
533
+ "text/html": [
534
+ "<div>\n",
535
+ "<style scoped>\n",
536
+ " .dataframe tbody tr th:only-of-type {\n",
537
+ " vertical-align: middle;\n",
538
+ " }\n",
539
+ "\n",
540
+ " .dataframe tbody tr th {\n",
541
+ " vertical-align: top;\n",
542
+ " }\n",
543
+ "\n",
544
+ " .dataframe thead th {\n",
545
+ " text-align: right;\n",
546
+ " }\n",
547
+ "</style>\n",
548
+ "<table border=\"1\" class=\"dataframe\">\n",
549
+ " <thead>\n",
550
+ " <tr style=\"text-align: right;\">\n",
551
+ " <th></th>\n",
552
+ " <th>review_date</th>\n",
553
+ " <th>movie_id</th>\n",
554
+ " <th>user_id</th>\n",
555
+ " <th>is_spoiler</th>\n",
556
+ " <th>review_text</th>\n",
557
+ " <th>rating</th>\n",
558
+ " <th>review_summary</th>\n",
559
+ " </tr>\n",
560
+ " </thead>\n",
561
+ " <tbody>\n",
562
+ " <tr>\n",
563
+ " <th>0</th>\n",
564
+ " <td>10 February 2006</td>\n",
565
+ " <td>tt0111161</td>\n",
566
+ " <td>ur1898687</td>\n",
567
+ " <td>True</td>\n",
568
+ " <td>In its Oscar year, Shawshank Redemption (writt...</td>\n",
569
+ " <td>10</td>\n",
570
+ " <td>A classic piece of unforgettable film-making.</td>\n",
571
+ " </tr>\n",
572
+ " <tr>\n",
573
+ " <th>1</th>\n",
574
+ " <td>6 September 2000</td>\n",
575
+ " <td>tt0111161</td>\n",
576
+ " <td>ur0842118</td>\n",
577
+ " <td>True</td>\n",
578
+ " <td>The Shawshank Redemption is without a doubt on...</td>\n",
579
+ " <td>10</td>\n",
580
+ " <td>Simply amazing. The best film of the 90's.</td>\n",
581
+ " </tr>\n",
582
+ " <tr>\n",
583
+ " <th>2</th>\n",
584
+ " <td>3 August 2001</td>\n",
585
+ " <td>tt0111161</td>\n",
586
+ " <td>ur1285640</td>\n",
587
+ " <td>True</td>\n",
588
+ " <td>I believe that this film is the best story eve...</td>\n",
589
+ " <td>8</td>\n",
590
+ " <td>The best story ever told on film</td>\n",
591
+ " </tr>\n",
592
+ " <tr>\n",
593
+ " <th>3</th>\n",
594
+ " <td>1 September 2002</td>\n",
595
+ " <td>tt0111161</td>\n",
596
+ " <td>ur1003471</td>\n",
597
+ " <td>True</td>\n",
598
+ " <td>**Yes, there are SPOILERS here**This film has ...</td>\n",
599
+ " <td>10</td>\n",
600
+ " <td>Busy dying or busy living?</td>\n",
601
+ " </tr>\n",
602
+ " <tr>\n",
603
+ " <th>4</th>\n",
604
+ " <td>20 May 2004</td>\n",
605
+ " <td>tt0111161</td>\n",
606
+ " <td>ur0226855</td>\n",
607
+ " <td>True</td>\n",
608
+ " <td>At the heart of this extraordinary movie is a ...</td>\n",
609
+ " <td>8</td>\n",
610
+ " <td>Great story, wondrously told and acted</td>\n",
611
+ " </tr>\n",
612
+ " </tbody>\n",
613
+ "</table>\n",
614
+ "</div>"
615
+ ],
616
+ "text/plain": [
617
+ " review_date movie_id user_id is_spoiler \\\n",
618
+ "0 10 February 2006 tt0111161 ur1898687 True \n",
619
+ "1 6 September 2000 tt0111161 ur0842118 True \n",
620
+ "2 3 August 2001 tt0111161 ur1285640 True \n",
621
+ "3 1 September 2002 tt0111161 ur1003471 True \n",
622
+ "4 20 May 2004 tt0111161 ur0226855 True \n",
623
+ "\n",
624
+ " review_text rating \\\n",
625
+ "0 In its Oscar year, Shawshank Redemption (writt... 10 \n",
626
+ "1 The Shawshank Redemption is without a doubt on... 10 \n",
627
+ "2 I believe that this film is the best story eve... 8 \n",
628
+ "3 **Yes, there are SPOILERS here**This film has ... 10 \n",
629
+ "4 At the heart of this extraordinary movie is a ... 8 \n",
630
+ "\n",
631
+ " review_summary \n",
632
+ "0 A classic piece of unforgettable film-making. \n",
633
+ "1 Simply amazing. The best film of the 90's. \n",
634
+ "2 The best story ever told on film \n",
635
+ "3 Busy dying or busy living? \n",
636
+ "4 Great story, wondrously told and acted "
637
+ ]
638
+ },
639
+ "execution_count": 28,
640
+ "metadata": {},
641
+ "output_type": "execute_result"
642
+ }
643
+ ],
644
+ "source": [
645
+ "df_analysed_reviews = df_reviews.copy()\n",
646
+ "df_analysed_reviews.head()"
647
+ ]
648
+ },
649
+ {
650
+ "cell_type": "code",
651
+ "execution_count": 52,
652
+ "id": "2c2a0ffe",
653
+ "metadata": {},
654
+ "outputs": [],
655
+ "source": [
656
+ "stop_words = list(set(stopwords.words('english')))\n",
657
+ "len_1 = []\n",
658
+ "for w in word_tokenize(df_reviews.iloc[0][4]):\n",
659
+ " if len(w) == 1:\n",
660
+ " len_1.append(w)\n",
661
+ " \n",
662
+ "for sym in len_1:\n",
663
+ " stop_words.append(sym)\n",
664
+ "stop_words = set(stop_words)"
665
+ ]
666
+ },
667
+ {
668
+ "cell_type": "code",
669
+ "execution_count": 53,
670
+ "id": "296ea26b",
671
+ "metadata": {},
672
+ "outputs": [],
673
+ "source": [
674
+ "ps = PorterStemmer()"
675
+ ]
676
+ },
677
+ {
678
+ "cell_type": "code",
679
+ "execution_count": 56,
680
+ "id": "c494a8a3",
681
+ "metadata": {},
682
+ "outputs": [
683
+ {
684
+ "data": {
685
+ "text/plain": [
686
+ "['cheat', 'die', 'kill']"
687
+ ]
688
+ },
689
+ "execution_count": 56,
690
+ "metadata": {},
691
+ "output_type": "execute_result"
692
+ }
693
+ ],
694
+ "source": [
695
+ "bad_words = [\"die\", \"dying\", \"died\", \"kill\", \"killed\", \"killing\", \"cheat\", \"cheating\", \"cheated\"]\n",
696
+ "bad_words = set([ps.stem(w) for w in bad_words])\n",
697
+ "bad_words = list(bad_words)\n",
698
+ "bad_words"
699
+ ]
700
+ },
701
+ {
702
+ "cell_type": "code",
703
+ "execution_count": 57,
704
+ "id": "b69e8e62",
705
+ "metadata": {},
706
+ "outputs": [],
707
+ "source": [
708
+ "df_analysed_reviews[\"bad_flag\"] = [any([y.lower() in bad_words\n",
709
+ " for y in [ps.stem(w) for w in word_tokenize(x[4]) if not w.lower() in stop_words]])\n",
710
+ " for x in df_reviews.values]"
711
+ ]
712
+ },
713
+ {
714
+ "cell_type": "code",
715
+ "execution_count": 58,
716
+ "id": "534fee23",
717
+ "metadata": {},
718
+ "outputs": [
719
+ {
720
+ "data": {
721
+ "text/html": [
722
+ "<div>\n",
723
+ "<style scoped>\n",
724
+ " .dataframe tbody tr th:only-of-type {\n",
725
+ " vertical-align: middle;\n",
726
+ " }\n",
727
+ "\n",
728
+ " .dataframe tbody tr th {\n",
729
+ " vertical-align: top;\n",
730
+ " }\n",
731
+ "\n",
732
+ " .dataframe thead th {\n",
733
+ " text-align: right;\n",
734
+ " }\n",
735
+ "</style>\n",
736
+ "<table border=\"1\" class=\"dataframe\">\n",
737
+ " <thead>\n",
738
+ " <tr style=\"text-align: right;\">\n",
739
+ " <th></th>\n",
740
+ " <th>review_date</th>\n",
741
+ " <th>movie_id</th>\n",
742
+ " <th>user_id</th>\n",
743
+ " <th>is_spoiler</th>\n",
744
+ " <th>review_text</th>\n",
745
+ " <th>rating</th>\n",
746
+ " <th>review_summary</th>\n",
747
+ " <th>bad_flag</th>\n",
748
+ " </tr>\n",
749
+ " </thead>\n",
750
+ " <tbody>\n",
751
+ " <tr>\n",
752
+ " <th>0</th>\n",
753
+ " <td>10 February 2006</td>\n",
754
+ " <td>tt0111161</td>\n",
755
+ " <td>ur1898687</td>\n",
756
+ " <td>True</td>\n",
757
+ " <td>In its Oscar year, Shawshank Redemption (writt...</td>\n",
758
+ " <td>10</td>\n",
759
+ " <td>A classic piece of unforgettable film-making.</td>\n",
760
+ " <td>True</td>\n",
761
+ " </tr>\n",
762
+ " <tr>\n",
763
+ " <th>1</th>\n",
764
+ " <td>6 September 2000</td>\n",
765
+ " <td>tt0111161</td>\n",
766
+ " <td>ur0842118</td>\n",
767
+ " <td>True</td>\n",
768
+ " <td>The Shawshank Redemption is without a doubt on...</td>\n",
769
+ " <td>10</td>\n",
770
+ " <td>Simply amazing. The best film of the 90's.</td>\n",
771
+ " <td>False</td>\n",
772
+ " </tr>\n",
773
+ " <tr>\n",
774
+ " <th>2</th>\n",
775
+ " <td>3 August 2001</td>\n",
776
+ " <td>tt0111161</td>\n",
777
+ " <td>ur1285640</td>\n",
778
+ " <td>True</td>\n",
779
+ " <td>I believe that this film is the best story eve...</td>\n",
780
+ " <td>8</td>\n",
781
+ " <td>The best story ever told on film</td>\n",
782
+ " <td>True</td>\n",
783
+ " </tr>\n",
784
+ " <tr>\n",
785
+ " <th>3</th>\n",
786
+ " <td>1 September 2002</td>\n",
787
+ " <td>tt0111161</td>\n",
788
+ " <td>ur1003471</td>\n",
789
+ " <td>True</td>\n",
790
+ " <td>**Yes, there are SPOILERS here**This film has ...</td>\n",
791
+ " <td>10</td>\n",
792
+ " <td>Busy dying or busy living?</td>\n",
793
+ " <td>True</td>\n",
794
+ " </tr>\n",
795
+ " <tr>\n",
796
+ " <th>4</th>\n",
797
+ " <td>20 May 2004</td>\n",
798
+ " <td>tt0111161</td>\n",
799
+ " <td>ur0226855</td>\n",
800
+ " <td>True</td>\n",
801
+ " <td>At the heart of this extraordinary movie is a ...</td>\n",
802
+ " <td>8</td>\n",
803
+ " <td>Great story, wondrously told and acted</td>\n",
804
+ " <td>False</td>\n",
805
+ " </tr>\n",
806
+ " </tbody>\n",
807
+ "</table>\n",
808
+ "</div>"
809
+ ],
810
+ "text/plain": [
811
+ " review_date movie_id user_id is_spoiler \\\n",
812
+ "0 10 February 2006 tt0111161 ur1898687 True \n",
813
+ "1 6 September 2000 tt0111161 ur0842118 True \n",
814
+ "2 3 August 2001 tt0111161 ur1285640 True \n",
815
+ "3 1 September 2002 tt0111161 ur1003471 True \n",
816
+ "4 20 May 2004 tt0111161 ur0226855 True \n",
817
+ "\n",
818
+ " review_text rating \\\n",
819
+ "0 In its Oscar year, Shawshank Redemption (writt... 10 \n",
820
+ "1 The Shawshank Redemption is without a doubt on... 10 \n",
821
+ "2 I believe that this film is the best story eve... 8 \n",
822
+ "3 **Yes, there are SPOILERS here**This film has ... 10 \n",
823
+ "4 At the heart of this extraordinary movie is a ... 8 \n",
824
+ "\n",
825
+ " review_summary bad_flag \n",
826
+ "0 A classic piece of unforgettable film-making. True \n",
827
+ "1 Simply amazing. The best film of the 90's. False \n",
828
+ "2 The best story ever told on film True \n",
829
+ "3 Busy dying or busy living? True \n",
830
+ "4 Great story, wondrously told and acted False "
831
+ ]
832
+ },
833
+ "execution_count": 58,
834
+ "metadata": {},
835
+ "output_type": "execute_result"
836
+ }
837
+ ],
838
+ "source": [
839
+ "df_analysed_reviews.head()"
840
+ ]
841
+ },
842
+ {
843
+ "cell_type": "code",
844
+ "execution_count": 50,
845
+ "id": "bcf1a542",
846
+ "metadata": {},
847
+ "outputs": [
848
+ {
849
+ "name": "stdout",
850
+ "output_type": "stream",
851
+ "text": [
852
+ "Percentage distribution in the dataset of spoilers and not spoilers \n",
853
+ "\n",
854
+ "False 73.7\n",
855
+ "True 26.3\n",
856
+ "Name: is_spoiler, dtype: float64\n"
857
+ ]
858
+ },
859
+ {
860
+ "data": {
861
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAh8AAAHGCAYAAADUhOmrAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAmS0lEQVR4nO3df1iV9f3H8dcR8wgFx5+cw5moaNQ0NEu7SKpBS9jMfl20laNt2o9Nh22RKwy5rnlsGxhbDBvqlmtIc2T7of1yOfGyaLvIa/irOWrWJiqlZywzDgOE1Pv7hxfn2wktDx4+h4PPx3Xd19X53DfnftOV8fQ+9+HYLMuyBAAAYMiAcA8AAADOL8QHAAAwivgAAABGER8AAMAo4gMAABhFfAAAAKOIDwAAYBTxAQAAjCI+AACAUcQHEAHWrFkjm83m3wYPHiyXy6Xrr79excXFampqCjje4/HIZrMFdY62tjZ5PB69+uqrQX3d6c41duxY3XTTTUE9z2epqqpSWVnZaffZbDZ5PJ6Qng9A7yE+gAhSUVGh119/XdXV1VqxYoWmTJmixx57TBMmTNCWLVv8x9133316/fXXg3rutrY2LV26NOj46Mm5euLT4uP111/Xfffd1+szAAiNgeEeAMDZS0lJ0bRp0/yPb7/9dj344IO69tprlZ2drXfeeUdOp1OjRo3SqFGjenWWtrY2xcTEGDnXZ7n66qvDen4AweHKBxDhRo8erccff1wtLS365S9/Ken0L4Vs3bpVGRkZGj58uKKjozV69Gjdfvvtamtr0/79+zVy5EhJ0tKlS/0v78ydOzfg+Xbu3KmvfOUrGjp0qMaPH3/Gc3XZsGGDJk+erMGDB2vcuHF64oknAvZ3vZy0f//+gPVXX31VNpvNfxUmIyNDGzdu1IEDBwJefupyupdd/vGPf+jWW2/V0KFDNXjwYE2ZMkWVlZWnPc8zzzyjwsJCud1uxcXFacaMGdq7d2/Asbt27dJNN92k+Ph42e12ud1uzZo1S+++++5pv3cAZ8aVD6AfuPHGGxUVFaXXXnvttPv379+vWbNm6brrrtOvf/1rDRkyRO+99542bdqkzs5OJSQkaNOmTfryl7+se++91/8SRleQdMnOztbs2bM1f/58tba2fupMu3fvVl5enjwej1wul37729/qgQceUGdnpx566KGgvr+VK1fq29/+tv79739rw4YNn3n83r17lZaWpvj4eD3xxBMaPny41q5dq7lz5+o///mP8vPzA45fvHixrrnmGv3qV7+Sz+fTokWLdPPNN+utt95SVFSUWltblZmZqaSkJK1YsUJOp1Ner1evvPKKWlpagvpeABAfQL9w4YUXasSIETp06NBp9+/YsUPHjh3TT37yE11++eX+9ZycHP8/T506VZI0atSoM76MMWfOHC1duvSsZjp06JB27drlP9/MmTPV1NSkH/7wh8rNzVVMTMxZPY8kTZw4UUOGDJHdbj+rl1g8Ho86Ozv1yiuvKDExUdKpQPvwww+1dOlSzZs3Tw6HI+D5165d638cFRWlO+64Q3V1dbr66qv1z3/+U0eOHNFTTz2lW2+91X/cHXfccdbfA4D/x8suQD9hWdYZ902ZMkWDBg3St7/9bVVWVmrfvn09Osftt99+1sdedtllAaEjnYodn8+nnTt39uj8Z2vr1q264YYb/OHRZe7cuWpra+t2g+wtt9wS8Hjy5MmSpAMHDkiSLr74Yg0dOlSLFi3SL37xC7355pu9OD3Q/xEfQD/Q2tqqI0eOyO12n3b/+PHjtWXLFsXHx2vBggUaP368xo8fr+XLlwd1noSEhLM+1uVynXHtyJEjQZ03WEeOHDntrF3/fj55/uHDhwc8ttvtkqT29nZJksPhUE1NjaZMmaLFixfrsssuk9vt1pIlS/TRRx/1xrcA9GvEB9APbNy4USdOnFBGRsYZj7nuuuv04osvqrm5Wdu2bdP06dOVl5endevWnfV5gvndIV6v94xrXT/sBw8eLEnq6OgIOO79998/6/OczvDhw3X48OFu610vS40YMSLo55w0aZLWrVunI0eOaPfu3brzzjv16KOP6vHHHz+nWYHz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JbbWGUZVmaO3eu7Ha7JOnYsWOaP39+t0+/XL9+fTjGAwAYQHzAqE/+kqGvf/3rYZoEABAu3HAKAACM4p4PAABgFPEBAACMIj4AAIBRxAcAADCK+AAAAEYRHwAAwCjiAwAAGPV/NR40gIcbGf4AAAAASUVORK5CYII=\n",
862
+ "text/plain": [
863
+ "<Figure size 640x480 with 1 Axes>"
864
+ ]
865
+ },
866
+ "metadata": {},
867
+ "output_type": "display_data"
868
+ }
869
+ ],
870
+ "source": [
871
+ "print('Percentage distribution in the dataset of spoilers and not spoilers \\n')\n",
872
+ "\n",
873
+ "# Compute distribution between classes\n",
874
+ "print(round(df_reviews.is_spoiler.value_counts(normalize=True)*100,2)) \n",
875
+ "# Plot distribution between classes \n",
876
+ "round(df_reviews.is_spoiler.value_counts(normalize=True)*100,2).plot(kind='bar')\n",
877
+ "\n",
878
+ "plt.title('Distributions')\n",
879
+ "plt.show()"
880
+ ]
881
+ },
882
+ {
883
+ "cell_type": "code",
884
+ "execution_count": 60,
885
+ "id": "345b9a57",
886
+ "metadata": {},
887
+ "outputs": [
888
+ {
889
+ "data": {
890
+ "text/plain": [
891
+ "'The Shawshank Redemption is without a doubt one of the most brilliant movies I have ever seen. Similar to The Green Mile in many respects (and better than it in almost all of them), these two movies have shown us that Stephen King is a master not only of horror but also of prose that shakes the soul and moves the heart. The plot is average, but King did great things with it in his novella that are only furthered by the direction, and the acting is so top-rate it\\'s almost scary.Tim Robbins plays Andy Dufrane, wrongly imprisoned for 20 years for the murder of his wife. The story focuses on Andy\\'s relationship with \"Red\" Redding (Morgan Freeman, in probably his best role) and his attempts to escape from Shawshank. Bob Gunton is positively evil and frightening as Warden Norton, and there are great performances and cameos all around; the most prominent one being Gil Bellows (late as Billy of Ally McBeal) as Tommy, a fellow inmate of Andy\\'s who suffers under the iron will of Norton.If you haven\\'t seen this movie, GO AND RENT IT NOW. You will not be disappointed. It is positively the best movie of the \\'90\\'s, and one of my Top 3 of all time. This movie is a spectacle to move the mind, soul, and heart. 10/10'"
892
+ ]
893
+ },
894
+ "execution_count": 60,
895
+ "metadata": {},
896
+ "output_type": "execute_result"
897
+ }
898
+ ],
899
+ "source": [
900
+ "df_analysed_reviews.iloc[1][4]"
901
+ ]
902
+ },
903
+ {
904
+ "cell_type": "code",
905
+ "execution_count": null,
906
+ "id": "b45e2e8e",
907
+ "metadata": {},
908
+ "outputs": [],
909
+ "source": []
910
+ }
911
+ ],
912
+ "metadata": {
913
+ "kernelspec": {
914
+ "display_name": "Python 3.9.13 64-bit ('py39': conda)",
915
+ "language": "python",
916
+ "name": "python3913jvsc74a57bd0536dd8d7cef9e0a7a3a0f6a92439f3a8950a5c8454fb0f4b78046b15afdc533f"
917
+ },
918
+ "language_info": {
919
+ "codemirror_mode": {
920
+ "name": "ipython",
921
+ "version": 3
922
+ },
923
+ "file_extension": ".py",
924
+ "mimetype": "text/x-python",
925
+ "name": "python",
926
+ "nbconvert_exporter": "python",
927
+ "pygments_lexer": "ipython3",
928
+ "version": "3.9.13"
929
+ }
930
+ },
931
+ "nbformat": 4,
932
+ "nbformat_minor": 5
933
+ }
Score1.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2024-08-15T14:44:00.362360Z","iopub.status.busy":"2024-08-15T14:44:00.361946Z","iopub.status.idle":"2024-08-15T14:44:01.523645Z","shell.execute_reply":"2024-08-15T14:44:01.522395Z","shell.execute_reply.started":"2024-08-15T14:44:00.362321Z"},"trusted":true},"outputs":[],"source":["# This Python 3 environment comes with many helpful analytics libraries installed\n","# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n","# For example, here's several helpful packages to load\n","\n","import numpy as np # linear algebra\n","import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n","\n","# Input data files are available in the read-only \"../input/\" directory\n","# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n","\n","import os\n","for dirname, _, filenames in os.walk('/kaggle/input'):\n"," for filename in filenames:\n"," print(os.path.join(dirname, filename))\n","\n","# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n","# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-08-15T14:44:01.526545Z","iopub.status.busy":"2024-08-15T14:44:01.525934Z","iopub.status.idle":"2024-08-15T14:44:01.846387Z","shell.execute_reply":"2024-08-15T14:44:01.845152Z","shell.execute_reply.started":"2024-08-15T14:44:01.526503Z"},"trusted":true},"outputs":[],"source":["movie_details = pd.read_json('/kaggle/input/movie-details/IMDB_movie_details.json', lines=True)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-08-15T14:44:01.848814Z","iopub.status.busy":"2024-08-15T14:44:01.848415Z","iopub.status.idle":"2024-08-15T14:44:17.628604Z","shell.execute_reply":"2024-08-15T14:44:17.627484Z","shell.execute_reply.started":"2024-08-15T14:44:01.848783Z"},"trusted":true},"outputs":[],"source":["reviews = pd.read_json('/kaggle/input/bad-words-flag/better_reviews.json')"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-08-15T14:44:17.631413Z","iopub.status.busy":"2024-08-15T14:44:17.631039Z","iopub.status.idle":"2024-08-15T14:44:17.652198Z","shell.execute_reply":"2024-08-15T14:44:17.650772Z","shell.execute_reply.started":"2024-08-15T14:44:17.631381Z"},"trusted":true},"outputs":[],"source":["print(movie_details.head())\n","print(reviews.head())"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-08-15T14:44:17.663776Z","iopub.status.busy":"2024-08-15T14:44:17.663306Z","iopub.status.idle":"2024-08-15T14:44:23.371720Z","shell.execute_reply":"2024-08-15T14:44:23.370184Z","shell.execute_reply.started":"2024-08-15T14:44:17.663734Z"},"trusted":true},"outputs":[],"source":["from sklearn.feature_extraction.text import TfidfVectorizer\n","from sklearn.metrics.pairwise import cosine_similarity\n","from transformers import BertTokenizer\n","import torch\n","from torch.utils.data import Dataset, DataLoader\n","from sklearn.model_selection import train_test_split\n","\n","# Preprocess and merge data\n","movie_details.dropna(subset=['plot_synopsis', 'plot_summary'], inplace=True)\n","reviews.dropna(subset=['review_text'], inplace=True)\n","data = pd.merge(reviews, movie_details, on='movie_id')\n","\n","# data = data.head(10000)\n","data.head()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-08-15T14:44:23.373876Z","iopub.status.busy":"2024-08-15T14:44:23.373308Z","iopub.status.idle":"2024-08-15T14:44:23.382136Z","shell.execute_reply":"2024-08-15T14:44:23.380852Z","shell.execute_reply.started":"2024-08-15T14:44:23.373843Z"},"trusted":true},"outputs":[],"source":["# Function to split the synopsis into three parts\n","def split_synopsis(text):\n"," parts = len(text.split()) // 3\n"," return text.split()[:parts], text.split()[parts:2*parts], text.split()[2*parts:]\n","\n","# Calculate the proximity of review text to the end of the plot synopsis\n","def calculate_proximity(review, synopsis):\n"," _, _, end = split_synopsis(synopsis)\n"," vectorizer = TfidfVectorizer()\n"," vectors = vectorizer.fit_transform([review, ' '.join(end)])\n"," return cosine_similarity(vectors)[0, 1]"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-08-15T14:44:23.383872Z","iopub.status.busy":"2024-08-15T14:44:23.383457Z","iopub.status.idle":"2024-08-15T14:44:23.399055Z","shell.execute_reply":"2024-08-15T14:44:23.397734Z","shell.execute_reply.started":"2024-08-15T14:44:23.383839Z"},"trusted":true},"outputs":[],"source":["from nltk.tokenize import sent_tokenize\n","import nltk\n","from sklearn.preprocessing import MinMaxScaler\n","\n","nltk.download('punkt')\n","\n","counter = 0\n","\n","def calculate_proximity_weighted(review, synopsis):\n"," global counter\n"," counter += 1\n"," if counter % 5000 == 0:\n"," print(counter, \"Records Ended!\")\n"," review_sentences = sent_tokenize(review)\n"," synopsis_sentences = sent_tokenize(synopsis)\n"," vectorizer = TfidfVectorizer()\n","\n"," # Create weights for synopsis sentences based on their position\n"," synopsis_weights = np.linspace(0.5, 1.0, num=len(synopsis_sentences))\n"," \n"," if len(synopsis_sentences) == 0:\n"," return 0\n"," # Vectorize synopsis sentences\n"," synopsis_vectors = vectorizer.fit_transform(synopsis_sentences)\n","\n"," significant_proximity_scores = []\n","\n"," for sentence in review_sentences:\n"," sentence_vector = vectorizer.transform([sentence])\n"," similarities = cosine_similarity(sentence_vector, synopsis_vectors)[0]\n","\n"," # Apply a threshold of 50% to consider the similarity significant\n"," significant_similarities = [sim * weight for sim, weight in zip(similarities, synopsis_weights) if sim > 0.7]\n","\n"," if significant_similarities:\n"," # Sum the significant similarities weighted by sentence position in the synopsis\n"," significant_proximity_scores.extend(significant_similarities)\n","\n"," # Return the sum of significant proximity scores\n"," return sum(significant_proximity_scores)\n","\n","# Applying the function to the dataset\n","data['end_proximity'] = data.apply(lambda x: calculate_proximity_weighted(x['review_text'], x['plot_synopsis']), axis=1)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.status.busy":"2024-08-15T14:35:59.289260Z","iopub.status.idle":"2024-08-15T14:35:59.289684Z","shell.execute_reply":"2024-08-15T14:35:59.289489Z","shell.execute_reply.started":"2024-08-15T14:35:59.289473Z"},"trusted":true},"outputs":[],"source":["scaler = MinMaxScaler()\n","data['end_proximity'] = scaler.fit_transform(data[['end_proximity']])"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["data.to_json('/kaggle/input/final_dataset2.json', orient='records', lines=True)"]}],"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"datasetId":5547860,"sourceId":9179201,"sourceType":"datasetVersion"},{"datasetId":5547886,"sourceId":9179232,"sourceType":"datasetVersion"}],"dockerImageVersionId":30746,"isGpuEnabled":false,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"kernelspec":{"display_name":"Python 3","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.10.13"}},"nbformat":4,"nbformat_minor":4}
Score2.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2024-08-15T14:44:00.362360Z","iopub.status.busy":"2024-08-15T14:44:00.361946Z","iopub.status.idle":"2024-08-15T14:44:01.523645Z","shell.execute_reply":"2024-08-15T14:44:01.522395Z","shell.execute_reply.started":"2024-08-15T14:44:00.362321Z"},"trusted":true},"outputs":[],"source":["# This Python 3 environment comes with many helpful analytics libraries installed\n","# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n","# For example, here's several helpful packages to load\n","\n","import numpy as np # linear algebra\n","import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n","\n","# Input data files are available in the read-only \"../input/\" directory\n","# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n","\n","import os\n","for dirname, _, filenames in os.walk('/kaggle/input'):\n"," for filename in filenames:\n"," print(os.path.join(dirname, filename))\n","\n","# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n","# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-08-15T14:44:01.526545Z","iopub.status.busy":"2024-08-15T14:44:01.525934Z","iopub.status.idle":"2024-08-15T14:44:01.846387Z","shell.execute_reply":"2024-08-15T14:44:01.845152Z","shell.execute_reply.started":"2024-08-15T14:44:01.526503Z"},"trusted":true},"outputs":[],"source":["movie_details = pd.read_json('/kaggle/input/movie-details/IMDB_movie_details.json', lines=True)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-08-15T14:44:01.848814Z","iopub.status.busy":"2024-08-15T14:44:01.848415Z","iopub.status.idle":"2024-08-15T14:44:17.628604Z","shell.execute_reply":"2024-08-15T14:44:17.627484Z","shell.execute_reply.started":"2024-08-15T14:44:01.848783Z"},"trusted":true},"outputs":[],"source":["reviews = pd.read_json('/kaggle/input/bad-words-flag/better_reviews.json')"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-08-15T14:44:17.631413Z","iopub.status.busy":"2024-08-15T14:44:17.631039Z","iopub.status.idle":"2024-08-15T14:44:17.652198Z","shell.execute_reply":"2024-08-15T14:44:17.650772Z","shell.execute_reply.started":"2024-08-15T14:44:17.631381Z"},"trusted":true},"outputs":[],"source":["print(movie_details.head())\n","print(reviews.head())"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-08-15T14:44:17.663776Z","iopub.status.busy":"2024-08-15T14:44:17.663306Z","iopub.status.idle":"2024-08-15T14:44:23.371720Z","shell.execute_reply":"2024-08-15T14:44:23.370184Z","shell.execute_reply.started":"2024-08-15T14:44:17.663734Z"},"trusted":true},"outputs":[],"source":["from sklearn.feature_extraction.text import TfidfVectorizer\n","from sklearn.metrics.pairwise import cosine_similarity\n","from transformers import BertTokenizer\n","import torch\n","from torch.utils.data import Dataset, DataLoader\n","from sklearn.model_selection import train_test_split\n","\n","# Preprocess and merge data\n","movie_details.dropna(subset=['plot_synopsis', 'plot_summary'], inplace=True)\n","reviews.dropna(subset=['review_text'], inplace=True)\n","data = pd.merge(reviews, movie_details, on='movie_id')\n","\n","# data = data.head(10000)\n","data.head()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-08-15T14:44:23.373876Z","iopub.status.busy":"2024-08-15T14:44:23.373308Z","iopub.status.idle":"2024-08-15T14:44:23.382136Z","shell.execute_reply":"2024-08-15T14:44:23.380852Z","shell.execute_reply.started":"2024-08-15T14:44:23.373843Z"},"trusted":true},"outputs":[],"source":["# Function to split the synopsis into three parts\n","def split_synopsis(text):\n"," parts = len(text.split()) // 3\n"," return text.split()[:parts], text.split()[parts:2*parts], text.split()[2*parts:]\n","\n","# Calculate the proximity of review text to the end of the plot synopsis\n","def calculate_proximity(review, synopsis):\n"," _, _, end = split_synopsis(synopsis)\n"," vectorizer = TfidfVectorizer()\n"," vectors = vectorizer.fit_transform([review, ' '.join(end)])\n"," return cosine_similarity(vectors)[0, 1]"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-08-15T14:44:55.099211Z","iopub.status.busy":"2024-08-15T14:44:55.098756Z","iopub.status.idle":"2024-08-15T14:45:03.186728Z","shell.execute_reply":"2024-08-15T14:45:03.184877Z","shell.execute_reply.started":"2024-08-15T14:44:55.099178Z"},"trusted":true},"outputs":[],"source":["from nltk.tokenize import sent_tokenize\n","from nltk.sentiment import SentimentIntensityAnalyzer\n","from sklearn.preprocessing import MinMaxScaler\n","import nltk\n","\n","nltk.download('punkt')\n","nltk.download('vader_lexicon')\n","\n","counter = 0\n","\n","def calculate_sentiment_proximity(review, synopsis):\n"," global counter\n"," counter += 1\n"," if counter % 5000 == 0:\n"," print(counter, \"Records Ended!\")\n"," review_sentences = sent_tokenize(review)\n"," synopsis_sentences = sent_tokenize(synopsis)\n"," vectorizer = TfidfVectorizer()\n"," sentiment_analyzer = SentimentIntensityAnalyzer()\n","\n"," if len(synopsis_sentences) == 0:\n"," return 0\n"," # Vectorize the synopsis\n"," synopsis_vectors = vectorizer.fit_transform(synopsis_sentences)\n"," synopsis_sentiments = [sentiment_analyzer.polarity_scores(sentence)['compound'] for sentence in synopsis_sentences]\n","\n"," proximity_scores = []\n"," for sentence in review_sentences:\n"," sentence_vector = vectorizer.transform([sentence])\n"," sentence_sentiment = sentiment_analyzer.polarity_scores(sentence)['compound']\n"," similarities = cosine_similarity(sentence_vector, synopsis_vectors)[0]\n","\n"," # Weighing similarity by sentiment intensity and position\n"," sentiment_weights = [abs(sentence_sentiment - s_sentiment) for s_sentiment in synopsis_sentiments]\n"," weighted_similarities = similarities * np.array(sentiment_weights)\n"," proximity_scores.append(weighted_similarities.max())\n","\n"," return np.mean(proximity_scores)\n","\n","# Applying the function to calculate proximity based on sentiment\n","data['end_proximity'] = data.apply(lambda x: calculate_sentiment_proximity(x['review_text'], x['plot_synopsis']), axis=1)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.status.busy":"2024-08-15T14:35:59.289260Z","iopub.status.idle":"2024-08-15T14:35:59.289684Z","shell.execute_reply":"2024-08-15T14:35:59.289489Z","shell.execute_reply.started":"2024-08-15T14:35:59.289473Z"},"trusted":true},"outputs":[],"source":["scaler = MinMaxScaler()\n","data['end_proximity'] = scaler.fit_transform(data[['end_proximity']])"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["data.to_json('/kaggle/input/final_dataset2.json', orient='records', lines=True)"]}],"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"datasetId":5547860,"sourceId":9179201,"sourceType":"datasetVersion"},{"datasetId":5547886,"sourceId":9179232,"sourceType":"datasetVersion"}],"dockerImageVersionId":30746,"isGpuEnabled":false,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"kernelspec":{"display_name":"Python 3","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.10.13"}},"nbformat":4,"nbformat_minor":4}
base LSTM model.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
final BERT model.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
final LSTM model.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
final T5 model.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
final roBERTA model.ipynb ADDED
The diff for this file is too large to render. See raw diff