{ "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_useless_spaces\",\n", " \"normalize_repeating_words\",\n", " \"normalize_repeating_chars\",\n", " \"normalize_whitespaces\",\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_html_tags\",\n", " \"remove_accents\",\n", " # \"remove_brackets\",\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": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | label | \n", "text | \n", "processed_text | \n", "
---|---|---|---|
0 | \n", "0 | \n", "I think it's time John Rambo move on with his ... | \n", "think time john rambo life try vietnam series ... | \n", "
1 | \n", "1 | \n", "I've just watch 2 films of Pang brothers, The ... | \n", "watch film pang brother eye watch eye kind dis... | \n", "
2 | \n", "1 | \n", "Jewel Thief is *THE* crime thriller of Bollywo... | \n", "jewel thief crime thriller bollywood direct bi... | \n", "
3 | \n", "0 | \n", "This so called remake is terrible. I went to s... | \n", "call remake terrible go tonight day anticipati... | \n", "
4 | \n", "1 | \n", "When Northfork debuted at the Cannes Film Fest... | \n", "northfork debut cannes film festival people li... | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
4995 | \n", "0 | \n", "The title tells it all -- Ed Gein, the butcher... | \n", "title tell ed gein butcher plainfield it zappy... | \n", "
4996 | \n", "0 | \n", "This film makes about as much sense as an 'Ozz... | \n", "film make sense ozzie harriet father know best... | \n", "
4997 | \n", "0 | \n", "\"Sex and the City\" has some great things going... | \n", "sex city great thing go problem saddle number ... | \n", "
4998 | \n", "0 | \n", "Please...if anybody gets the chance to read th... | \n", "please if anybody get chance read watch movie ... | \n", "
4999 | \n", "0 | \n", "...a film comes along that manages to be absol... | \n", "a film come manage absolutely terrible open ti... | \n", "
5000 rows × 3 columns
\n", "