Spaces:
Build error
Build error
File size: 13,164 Bytes
dbb343d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"import sys\n",
"sys.path.append(\"..\")\n",
"from src.preprocessing import PreprocessingPipeline\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(\"../data/test_en.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"pre_steps = [\n",
" \"normalize_unicode\",\n",
" \"normalize_acronyms\",\n",
" \"normalize_bullet_points\",\n",
" \"normalize_hyphenated_words\",\n",
" \"normalize_quotation_marks\",\n",
" \"normalize_repeating_words\",\n",
" \"normalize_repeating_chars\",\n",
" \"normalize_whitespaces\",\n",
" \"normalize_useless_spaces\",\n",
" # \"replace_currency_symbols\",\n",
" # \"replace_emails\",\n",
" # \"replace_emojis\",\n",
" # \"replace_hashtags\",\n",
" # \"replace_numbers\",\n",
" # \"replace_phone_numbers\",\n",
" # \"replace_urls\",\n",
" # \"replace_user_handles\",\n",
" # \"remove_accents\",\n",
" # \"remove_brackets\",\n",
" # \"remove_html_tags\",\n",
" # \"remove_non_words\",\n",
" # \"remove_punctuation\",\n",
" # \"lowercase\",\n",
" \"strip\",\n",
"]\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"post_steps = [\n",
" \"lowercase\",\n",
" \"replace_currency_symbols\",\n",
" \"replace_urls\",\n",
" \"replace_emails\",\n",
" \"replace_user_handles\",\n",
" \"replace_hashtags\",\n",
" \"replace_emojis\",\n",
" # \"replace_phone_numbers\",\n",
" # \"replace_numbers\",\n",
" \"remove_accents\",\n",
" \"remove_brackets\",\n",
" \"remove_html_tags\",\n",
" \"remove_non_words\",\n",
" \"remove_numbers\",\n",
" \"remove_punctuation\",\n",
" \"normalize_repeating_words\",\n",
" \"normalize_repeating_chars\",\n",
" \"normalize_useless_spaces\",\n",
" \"strip\",\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"pipe = PreprocessingPipeline(\n",
" language=\"English\",\n",
" lemmatization_step=\"Spacy lemmatizer (no stopwords)\", # \"Disable lemmatizer\",\n",
" pre_steps=pre_steps,\n",
" post_steps=post_steps,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"I think it's time John Rambo move on with his life and try to put Vietnam behind him. This series is getting old and Rambo is no longer a solider but a cold blooded killer. Ever time he turns up on the screen someone dies. Vietnam was not a fun place to be and frankly I am tired of Hollywood making it seem like it was. This is not the worst of the films concerning Vietnam, that honor goes to John Waynes Green Berets. In any case John Rambo carrying around a 50 cal Machine Gun taking on what seems to be half of the Viet Cong army plus a good many Russians is an insult to watch. What is worse is Rambos cheesy speech at the end.Please!! Oh yeah I heard they are making another one.\""
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pipe.pre(df.text[0])"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'think time John Rambo life try Vietnam . series get old Rambo long solider cold blooded killer . time turn screen die . Vietnam fun place frankly tired Hollywood make like . bad film concern Vietnam , honor go John Waynes Green Berets . case John Rambo carry 50 cal Machine Gun take half Viet Cong army plus good Russians insult watch . bad Rambos cheesy speech end . ! ! oh yeah hear make .'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pipe.lemma(pipe.nlp(pipe.pre(df.text[0])))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'think time john rambo life try vietnam series get old rambo long solider cold blooded killer time turn screen die vietnam fun place frankly tired hollywood make like bad film concern vietnam honor go john waynes green berets case john rambo carry cal machine gun take half viet cong army plus good russians insult watch bad rambos cheesy speech end oh yeah hear make'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pipe.post(pipe.lemma(pipe.nlp(pipe.pre(df.text[0]))))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"odf = pipe.vaex_process(df, \"text\")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>label</th>\n",
" <th>text</th>\n",
" <th>processed_text</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>I think it's time John Rambo move on with his ...</td>\n",
" <td>think time john rambo life try vietnam series ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>I've just watch 2 films of Pang brothers, The ...</td>\n",
" <td>watch film pang brother eye watch eye kind dis...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1</td>\n",
" <td>Jewel Thief is *THE* crime thriller of Bollywo...</td>\n",
" <td>jewel thief crime thriller bollywood direct bi...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0</td>\n",
" <td>This so called remake is terrible. I went to s...</td>\n",
" <td>call remake terrible go tonight day anticipati...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1</td>\n",
" <td>When Northfork debuted at the Cannes Film Fest...</td>\n",
" <td>northfork debut cannes film festival people li...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4995</th>\n",
" <td>0</td>\n",
" <td>The title tells it all -- Ed Gein, the butcher...</td>\n",
" <td>title tell ed gein butcher plainfield it zappy...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4996</th>\n",
" <td>0</td>\n",
" <td>This film makes about as much sense as an 'Ozz...</td>\n",
" <td>film make sense ozzie harriet father know best...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4997</th>\n",
" <td>0</td>\n",
" <td>\"Sex and the City\" has some great things going...</td>\n",
" <td>sex city great thing go problem saddle number ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4998</th>\n",
" <td>0</td>\n",
" <td>Please...if anybody gets the chance to read th...</td>\n",
" <td>please if anybody get chance read watch movie ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4999</th>\n",
" <td>0</td>\n",
" <td>...a film comes along that manages to be absol...</td>\n",
" <td>a film come manage absolutely terrible open ti...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5000 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" label text \\\n",
"0 0 I think it's time John Rambo move on with his ... \n",
"1 1 I've just watch 2 films of Pang brothers, The ... \n",
"2 1 Jewel Thief is *THE* crime thriller of Bollywo... \n",
"3 0 This so called remake is terrible. I went to s... \n",
"4 1 When Northfork debuted at the Cannes Film Fest... \n",
"... ... ... \n",
"4995 0 The title tells it all -- Ed Gein, the butcher... \n",
"4996 0 This film makes about as much sense as an 'Ozz... \n",
"4997 0 \"Sex and the City\" has some great things going... \n",
"4998 0 Please...if anybody gets the chance to read th... \n",
"4999 0 ...a film comes along that manages to be absol... \n",
"\n",
" processed_text \n",
"0 think time john rambo life try vietnam series ... \n",
"1 watch film pang brother eye watch eye kind dis... \n",
"2 jewel thief crime thriller bollywood direct bi... \n",
"3 call remake terrible go tonight day anticipati... \n",
"4 northfork debut cannes film festival people li... \n",
"... ... \n",
"4995 title tell ed gein butcher plainfield it zappy... \n",
"4996 film make sense ozzie harriet father know best... \n",
"4997 sex city great thing go problem saddle number ... \n",
"4998 please if anybody get chance read watch movie ... \n",
"4999 a film come manage absolutely terrible open ti... \n",
"\n",
"[5000 rows x 3 columns]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"odf"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"steps = list(PreprocessingPipeline.pipeline_components().keys())\n",
"default_pre_steps_idx = [steps.index(i) for i in pre_steps]\n",
"default_post_steps_idx = [steps.index(i) for i in post_steps]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 14, 2, 3, 4, 23, 22, 5, 21, 24]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"default_pre_steps_idx"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[0, 7, 6, 8, 13, 10, 9, 15, 16, 17, 19, 20, 18, 23, 22, 21, 24]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"default_post_steps_idx"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sorted(list(PreprocessingPipeline.pipeline_components().keys()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"list(PreprocessingPipeline.lemmatization_component().keys())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "aa7efd0b3ada76bb0689aa8ed0b61d7de788847e3d11d2d142fc5800c765982f"
},
"kernelspec": {
"display_name": "Python 3.7.11 64-bit ('wordify': conda)",
"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.7.11"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|