Spaces:
Build error
Build error
Pietro Lesci
commited on
Commit
•
dbb343d
1
Parent(s):
4fe22cb
fix processing steps order and pick correct column
Browse files- src/components.py +4 -2
- src/configs.py +3 -2
- src/preprocessing.py +17 -12
- tests/notebook.ipynb +417 -0
src/components.py
CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
|
|
2 |
import time
|
3 |
import pandas as pd
|
4 |
|
5 |
-
from src.configs import Languages, PreprocessingConfigs, SupportedFiles
|
6 |
from src.preprocessing import PreprocessingPipeline
|
7 |
from src.wordifier import input_transform, output_transform, wordifier
|
8 |
from src.utils import get_col_indices
|
@@ -113,7 +113,9 @@ def form(df):
|
|
113 |
|
114 |
# prepare input
|
115 |
with st.spinner("Step 2/4: Preparing inputs"):
|
116 |
-
input_dict = input_transform(
|
|
|
|
|
117 |
|
118 |
# wordify
|
119 |
with st.spinner("Step 3/4: Wordifying"):
|
|
|
2 |
import time
|
3 |
import pandas as pd
|
4 |
|
5 |
+
from src.configs import Languages, PreprocessingConfigs, SupportedFiles, ColumnNames
|
6 |
from src.preprocessing import PreprocessingPipeline
|
7 |
from src.wordifier import input_transform, output_transform, wordifier
|
8 |
from src.utils import get_col_indices
|
|
|
113 |
|
114 |
# prepare input
|
115 |
with st.spinner("Step 2/4: Preparing inputs"):
|
116 |
+
input_dict = input_transform(
|
117 |
+
df[ColumnNames.PROCESSED_TEXT.value], df[label_column]
|
118 |
+
)
|
119 |
|
120 |
# wordify
|
121 |
with st.spinner("Step 3/4: Wordifying"):
|
src/configs.py
CHANGED
@@ -6,6 +6,7 @@ import pandas as pd
|
|
6 |
class ColumnNames(Enum):
|
7 |
LABEL = "label"
|
8 |
TEXT = "text"
|
|
|
9 |
|
10 |
|
11 |
class ModelConfigs(Enum):
|
@@ -24,9 +25,9 @@ class InputTransformConfigs(Enum):
|
|
24 |
|
25 |
|
26 |
class PreprocessingConfigs(Enum):
|
27 |
-
DEFAULT_PRE = [1,
|
28 |
DEFAULT_LEMMA = 1
|
29 |
-
DEFAULT_POST = [
|
30 |
|
31 |
|
32 |
class Languages(Enum):
|
|
|
6 |
class ColumnNames(Enum):
|
7 |
LABEL = "label"
|
8 |
TEXT = "text"
|
9 |
+
PROCESSED_TEXT = "processed_text"
|
10 |
|
11 |
|
12 |
class ModelConfigs(Enum):
|
|
|
25 |
|
26 |
|
27 |
class PreprocessingConfigs(Enum):
|
28 |
+
DEFAULT_PRE = [1, 14, 2, 3, 4, 21, 23, 22, 5, 24]
|
29 |
DEFAULT_LEMMA = 1
|
30 |
+
DEFAULT_POST = [0, 17, 15, 19, 23, 22, 21, 24]
|
31 |
|
32 |
|
33 |
class Languages(Enum):
|
src/preprocessing.py
CHANGED
@@ -23,9 +23,9 @@ def normalize_acronyms(t: str) -> str:
|
|
23 |
return _re_normalize_acronyms.sub(t.translate(str.maketrans("", "", string.punctuation)).upper(), t)
|
24 |
|
25 |
|
26 |
-
_re_non_word = re.compile(r"
|
27 |
def remove_non_word(t: str) -> str:
|
28 |
-
"Removes non-words characters from the text using the regex
|
29 |
return _re_non_word.sub(" ", t)
|
30 |
|
31 |
|
@@ -52,6 +52,11 @@ def normalize_repeating_words(t: str) -> str:
|
|
52 |
return _re_wrep.sub(_replace_wrep, t)
|
53 |
|
54 |
|
|
|
|
|
|
|
|
|
|
|
55 |
def lowercase(t: str) -> str:
|
56 |
"Lowercases the text"
|
57 |
return t.lower()
|
@@ -88,21 +93,20 @@ class PreprocessingPipeline:
|
|
88 |
lemmatization_step: Optional[str],
|
89 |
post_steps: Optional[List[str]],
|
90 |
):
|
|
|
91 |
self.language = language
|
92 |
self.pre_steps = pre_steps
|
93 |
self.lemmatization_step = lemmatization_step
|
94 |
self.post_steps = post_steps
|
95 |
|
96 |
-
self.nlp =
|
97 |
-
|
98 |
-
|
99 |
-
)
|
100 |
-
self.post = (
|
101 |
-
self.make_pre_post_component(self.post_steps)
|
102 |
-
if self.post_steps
|
103 |
else identity
|
104 |
)
|
105 |
-
self.
|
|
|
|
|
106 |
|
107 |
# def apply_multiproc(fn, series):
|
108 |
# with mp.Pool(mp.cpu_count()) as pool:
|
@@ -144,9 +148,9 @@ class PreprocessingPipeline:
|
|
144 |
|
145 |
# return series
|
146 |
|
147 |
-
def
|
148 |
if not steps:
|
149 |
-
return
|
150 |
components = [self.pipeline_components()[step] for step in steps]
|
151 |
|
152 |
return make_pipeline(*components)
|
@@ -176,6 +180,7 @@ class PreprocessingPipeline:
|
|
176 |
("remove_html_tags", remove.html_tags),
|
177 |
("remove_punctuation", remove.punctuation),
|
178 |
("remove_non_words", remove_non_word),
|
|
|
179 |
("normalize_useless_spaces", normalize_useless_spaces),
|
180 |
("normalize_repeating_chars", normalize_repeating_chars),
|
181 |
("normalize_repeating_words", normalize_repeating_words),
|
|
|
23 |
return _re_normalize_acronyms.sub(t.translate(str.maketrans("", "", string.punctuation)).upper(), t)
|
24 |
|
25 |
|
26 |
+
_re_non_word = re.compile(r"[^A-Za-z]+")
|
27 |
def remove_non_word(t: str) -> str:
|
28 |
+
"Removes non-words characters and digits from the text using the regex `[^A-Za-z]+`"
|
29 |
return _re_non_word.sub(" ", t)
|
30 |
|
31 |
|
|
|
52 |
return _re_wrep.sub(_replace_wrep, t)
|
53 |
|
54 |
|
55 |
+
_re_remove_numbers = re.compile(r"\d+")
|
56 |
+
def remove_numbers(t: str) -> str:
|
57 |
+
return _re_remove_numbers.sub(" ", t)
|
58 |
+
|
59 |
+
|
60 |
def lowercase(t: str) -> str:
|
61 |
"Lowercases the text"
|
62 |
return t.lower()
|
|
|
93 |
lemmatization_step: Optional[str],
|
94 |
post_steps: Optional[List[str]],
|
95 |
):
|
96 |
+
|
97 |
self.language = language
|
98 |
self.pre_steps = pre_steps
|
99 |
self.lemmatization_step = lemmatization_step
|
100 |
self.post_steps = post_steps
|
101 |
|
102 |
+
self.nlp = (
|
103 |
+
spacy.load(Languages[language].value, disable=["parser", "ner"])
|
104 |
+
if self.lemmatization_step != "Disable lemmatizer"
|
|
|
|
|
|
|
|
|
105 |
else identity
|
106 |
)
|
107 |
+
self.pre = self.make_pipe_component(self.pre_steps)
|
108 |
+
self.post = self.make_pipe_component(self.post_steps)
|
109 |
+
self.lemma = self.lemmatization_component().get(self.lemmatization_step)
|
110 |
|
111 |
# def apply_multiproc(fn, series):
|
112 |
# with mp.Pool(mp.cpu_count()) as pool:
|
|
|
148 |
|
149 |
# return series
|
150 |
|
151 |
+
def make_pipe_component(self, steps: Optional[List[str]]) -> Optional[Callable]:
|
152 |
if not steps:
|
153 |
+
return identity
|
154 |
components = [self.pipeline_components()[step] for step in steps]
|
155 |
|
156 |
return make_pipeline(*components)
|
|
|
180 |
("remove_html_tags", remove.html_tags),
|
181 |
("remove_punctuation", remove.punctuation),
|
182 |
("remove_non_words", remove_non_word),
|
183 |
+
("remove_numbers", remove_numbers),
|
184 |
("normalize_useless_spaces", normalize_useless_spaces),
|
185 |
("normalize_repeating_chars", normalize_repeating_chars),
|
186 |
("normalize_repeating_words", normalize_repeating_words),
|
tests/notebook.ipynb
ADDED
@@ -0,0 +1,417 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"%load_ext autoreload\n",
|
10 |
+
"%autoreload 2\n",
|
11 |
+
"\n",
|
12 |
+
"import sys\n",
|
13 |
+
"sys.path.append(\"..\")\n",
|
14 |
+
"from src.preprocessing import PreprocessingPipeline\n",
|
15 |
+
"import pandas as pd"
|
16 |
+
]
|
17 |
+
},
|
18 |
+
{
|
19 |
+
"cell_type": "code",
|
20 |
+
"execution_count": 2,
|
21 |
+
"metadata": {},
|
22 |
+
"outputs": [],
|
23 |
+
"source": [
|
24 |
+
"df = pd.read_csv(\"../data/test_en.csv\")"
|
25 |
+
]
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"cell_type": "code",
|
29 |
+
"execution_count": 3,
|
30 |
+
"metadata": {},
|
31 |
+
"outputs": [],
|
32 |
+
"source": [
|
33 |
+
"pre_steps = [\n",
|
34 |
+
" \"normalize_unicode\",\n",
|
35 |
+
" \"normalize_acronyms\",\n",
|
36 |
+
" \"normalize_bullet_points\",\n",
|
37 |
+
" \"normalize_hyphenated_words\",\n",
|
38 |
+
" \"normalize_quotation_marks\",\n",
|
39 |
+
" \"normalize_repeating_words\",\n",
|
40 |
+
" \"normalize_repeating_chars\",\n",
|
41 |
+
" \"normalize_whitespaces\",\n",
|
42 |
+
" \"normalize_useless_spaces\",\n",
|
43 |
+
" # \"replace_currency_symbols\",\n",
|
44 |
+
" # \"replace_emails\",\n",
|
45 |
+
" # \"replace_emojis\",\n",
|
46 |
+
" # \"replace_hashtags\",\n",
|
47 |
+
" # \"replace_numbers\",\n",
|
48 |
+
" # \"replace_phone_numbers\",\n",
|
49 |
+
" # \"replace_urls\",\n",
|
50 |
+
" # \"replace_user_handles\",\n",
|
51 |
+
" # \"remove_accents\",\n",
|
52 |
+
" # \"remove_brackets\",\n",
|
53 |
+
" # \"remove_html_tags\",\n",
|
54 |
+
" # \"remove_non_words\",\n",
|
55 |
+
" # \"remove_punctuation\",\n",
|
56 |
+
" # \"lowercase\",\n",
|
57 |
+
" \"strip\",\n",
|
58 |
+
"]\n"
|
59 |
+
]
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"cell_type": "code",
|
63 |
+
"execution_count": 4,
|
64 |
+
"metadata": {},
|
65 |
+
"outputs": [],
|
66 |
+
"source": [
|
67 |
+
"post_steps = [\n",
|
68 |
+
" \"lowercase\",\n",
|
69 |
+
" \"replace_currency_symbols\",\n",
|
70 |
+
" \"replace_urls\",\n",
|
71 |
+
" \"replace_emails\",\n",
|
72 |
+
" \"replace_user_handles\",\n",
|
73 |
+
" \"replace_hashtags\",\n",
|
74 |
+
" \"replace_emojis\",\n",
|
75 |
+
" # \"replace_phone_numbers\",\n",
|
76 |
+
" # \"replace_numbers\",\n",
|
77 |
+
" \"remove_accents\",\n",
|
78 |
+
" \"remove_brackets\",\n",
|
79 |
+
" \"remove_html_tags\",\n",
|
80 |
+
" \"remove_non_words\",\n",
|
81 |
+
" \"remove_numbers\",\n",
|
82 |
+
" \"remove_punctuation\",\n",
|
83 |
+
" \"normalize_repeating_words\",\n",
|
84 |
+
" \"normalize_repeating_chars\",\n",
|
85 |
+
" \"normalize_useless_spaces\",\n",
|
86 |
+
" \"strip\",\n",
|
87 |
+
"]"
|
88 |
+
]
|
89 |
+
},
|
90 |
+
{
|
91 |
+
"cell_type": "code",
|
92 |
+
"execution_count": 5,
|
93 |
+
"metadata": {},
|
94 |
+
"outputs": [],
|
95 |
+
"source": [
|
96 |
+
"pipe = PreprocessingPipeline(\n",
|
97 |
+
" language=\"English\",\n",
|
98 |
+
" lemmatization_step=\"Spacy lemmatizer (no stopwords)\", # \"Disable lemmatizer\",\n",
|
99 |
+
" pre_steps=pre_steps,\n",
|
100 |
+
" post_steps=post_steps,\n",
|
101 |
+
")"
|
102 |
+
]
|
103 |
+
},
|
104 |
+
{
|
105 |
+
"cell_type": "code",
|
106 |
+
"execution_count": 6,
|
107 |
+
"metadata": {},
|
108 |
+
"outputs": [
|
109 |
+
{
|
110 |
+
"data": {
|
111 |
+
"text/plain": [
|
112 |
+
"\"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.\""
|
113 |
+
]
|
114 |
+
},
|
115 |
+
"execution_count": 6,
|
116 |
+
"metadata": {},
|
117 |
+
"output_type": "execute_result"
|
118 |
+
}
|
119 |
+
],
|
120 |
+
"source": [
|
121 |
+
"pipe.pre(df.text[0])"
|
122 |
+
]
|
123 |
+
},
|
124 |
+
{
|
125 |
+
"cell_type": "code",
|
126 |
+
"execution_count": 7,
|
127 |
+
"metadata": {},
|
128 |
+
"outputs": [
|
129 |
+
{
|
130 |
+
"data": {
|
131 |
+
"text/plain": [
|
132 |
+
"'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 .'"
|
133 |
+
]
|
134 |
+
},
|
135 |
+
"execution_count": 7,
|
136 |
+
"metadata": {},
|
137 |
+
"output_type": "execute_result"
|
138 |
+
}
|
139 |
+
],
|
140 |
+
"source": [
|
141 |
+
"pipe.lemma(pipe.nlp(pipe.pre(df.text[0])))"
|
142 |
+
]
|
143 |
+
},
|
144 |
+
{
|
145 |
+
"cell_type": "code",
|
146 |
+
"execution_count": 8,
|
147 |
+
"metadata": {},
|
148 |
+
"outputs": [
|
149 |
+
{
|
150 |
+
"data": {
|
151 |
+
"text/plain": [
|
152 |
+
"'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'"
|
153 |
+
]
|
154 |
+
},
|
155 |
+
"execution_count": 8,
|
156 |
+
"metadata": {},
|
157 |
+
"output_type": "execute_result"
|
158 |
+
}
|
159 |
+
],
|
160 |
+
"source": [
|
161 |
+
"pipe.post(pipe.lemma(pipe.nlp(pipe.pre(df.text[0]))))"
|
162 |
+
]
|
163 |
+
},
|
164 |
+
{
|
165 |
+
"cell_type": "code",
|
166 |
+
"execution_count": 9,
|
167 |
+
"metadata": {},
|
168 |
+
"outputs": [],
|
169 |
+
"source": [
|
170 |
+
"odf = pipe.vaex_process(df, \"text\")"
|
171 |
+
]
|
172 |
+
},
|
173 |
+
{
|
174 |
+
"cell_type": "code",
|
175 |
+
"execution_count": 10,
|
176 |
+
"metadata": {},
|
177 |
+
"outputs": [
|
178 |
+
{
|
179 |
+
"data": {
|
180 |
+
"text/html": [
|
181 |
+
"<div>\n",
|
182 |
+
"<style scoped>\n",
|
183 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
184 |
+
" vertical-align: middle;\n",
|
185 |
+
" }\n",
|
186 |
+
"\n",
|
187 |
+
" .dataframe tbody tr th {\n",
|
188 |
+
" vertical-align: top;\n",
|
189 |
+
" }\n",
|
190 |
+
"\n",
|
191 |
+
" .dataframe thead th {\n",
|
192 |
+
" text-align: right;\n",
|
193 |
+
" }\n",
|
194 |
+
"</style>\n",
|
195 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
196 |
+
" <thead>\n",
|
197 |
+
" <tr style=\"text-align: right;\">\n",
|
198 |
+
" <th></th>\n",
|
199 |
+
" <th>label</th>\n",
|
200 |
+
" <th>text</th>\n",
|
201 |
+
" <th>processed_text</th>\n",
|
202 |
+
" </tr>\n",
|
203 |
+
" </thead>\n",
|
204 |
+
" <tbody>\n",
|
205 |
+
" <tr>\n",
|
206 |
+
" <th>0</th>\n",
|
207 |
+
" <td>0</td>\n",
|
208 |
+
" <td>I think it's time John Rambo move on with his ...</td>\n",
|
209 |
+
" <td>think time john rambo life try vietnam series ...</td>\n",
|
210 |
+
" </tr>\n",
|
211 |
+
" <tr>\n",
|
212 |
+
" <th>1</th>\n",
|
213 |
+
" <td>1</td>\n",
|
214 |
+
" <td>I've just watch 2 films of Pang brothers, The ...</td>\n",
|
215 |
+
" <td>watch film pang brother eye watch eye kind dis...</td>\n",
|
216 |
+
" </tr>\n",
|
217 |
+
" <tr>\n",
|
218 |
+
" <th>2</th>\n",
|
219 |
+
" <td>1</td>\n",
|
220 |
+
" <td>Jewel Thief is *THE* crime thriller of Bollywo...</td>\n",
|
221 |
+
" <td>jewel thief crime thriller bollywood direct bi...</td>\n",
|
222 |
+
" </tr>\n",
|
223 |
+
" <tr>\n",
|
224 |
+
" <th>3</th>\n",
|
225 |
+
" <td>0</td>\n",
|
226 |
+
" <td>This so called remake is terrible. I went to s...</td>\n",
|
227 |
+
" <td>call remake terrible go tonight day anticipati...</td>\n",
|
228 |
+
" </tr>\n",
|
229 |
+
" <tr>\n",
|
230 |
+
" <th>4</th>\n",
|
231 |
+
" <td>1</td>\n",
|
232 |
+
" <td>When Northfork debuted at the Cannes Film Fest...</td>\n",
|
233 |
+
" <td>northfork debut cannes film festival people li...</td>\n",
|
234 |
+
" </tr>\n",
|
235 |
+
" <tr>\n",
|
236 |
+
" <th>...</th>\n",
|
237 |
+
" <td>...</td>\n",
|
238 |
+
" <td>...</td>\n",
|
239 |
+
" <td>...</td>\n",
|
240 |
+
" </tr>\n",
|
241 |
+
" <tr>\n",
|
242 |
+
" <th>4995</th>\n",
|
243 |
+
" <td>0</td>\n",
|
244 |
+
" <td>The title tells it all -- Ed Gein, the butcher...</td>\n",
|
245 |
+
" <td>title tell ed gein butcher plainfield it zappy...</td>\n",
|
246 |
+
" </tr>\n",
|
247 |
+
" <tr>\n",
|
248 |
+
" <th>4996</th>\n",
|
249 |
+
" <td>0</td>\n",
|
250 |
+
" <td>This film makes about as much sense as an 'Ozz...</td>\n",
|
251 |
+
" <td>film make sense ozzie harriet father know best...</td>\n",
|
252 |
+
" </tr>\n",
|
253 |
+
" <tr>\n",
|
254 |
+
" <th>4997</th>\n",
|
255 |
+
" <td>0</td>\n",
|
256 |
+
" <td>\"Sex and the City\" has some great things going...</td>\n",
|
257 |
+
" <td>sex city great thing go problem saddle number ...</td>\n",
|
258 |
+
" </tr>\n",
|
259 |
+
" <tr>\n",
|
260 |
+
" <th>4998</th>\n",
|
261 |
+
" <td>0</td>\n",
|
262 |
+
" <td>Please...if anybody gets the chance to read th...</td>\n",
|
263 |
+
" <td>please if anybody get chance read watch movie ...</td>\n",
|
264 |
+
" </tr>\n",
|
265 |
+
" <tr>\n",
|
266 |
+
" <th>4999</th>\n",
|
267 |
+
" <td>0</td>\n",
|
268 |
+
" <td>...a film comes along that manages to be absol...</td>\n",
|
269 |
+
" <td>a film come manage absolutely terrible open ti...</td>\n",
|
270 |
+
" </tr>\n",
|
271 |
+
" </tbody>\n",
|
272 |
+
"</table>\n",
|
273 |
+
"<p>5000 rows × 3 columns</p>\n",
|
274 |
+
"</div>"
|
275 |
+
],
|
276 |
+
"text/plain": [
|
277 |
+
" label text \\\n",
|
278 |
+
"0 0 I think it's time John Rambo move on with his ... \n",
|
279 |
+
"1 1 I've just watch 2 films of Pang brothers, The ... \n",
|
280 |
+
"2 1 Jewel Thief is *THE* crime thriller of Bollywo... \n",
|
281 |
+
"3 0 This so called remake is terrible. I went to s... \n",
|
282 |
+
"4 1 When Northfork debuted at the Cannes Film Fest... \n",
|
283 |
+
"... ... ... \n",
|
284 |
+
"4995 0 The title tells it all -- Ed Gein, the butcher... \n",
|
285 |
+
"4996 0 This film makes about as much sense as an 'Ozz... \n",
|
286 |
+
"4997 0 \"Sex and the City\" has some great things going... \n",
|
287 |
+
"4998 0 Please...if anybody gets the chance to read th... \n",
|
288 |
+
"4999 0 ...a film comes along that manages to be absol... \n",
|
289 |
+
"\n",
|
290 |
+
" processed_text \n",
|
291 |
+
"0 think time john rambo life try vietnam series ... \n",
|
292 |
+
"1 watch film pang brother eye watch eye kind dis... \n",
|
293 |
+
"2 jewel thief crime thriller bollywood direct bi... \n",
|
294 |
+
"3 call remake terrible go tonight day anticipati... \n",
|
295 |
+
"4 northfork debut cannes film festival people li... \n",
|
296 |
+
"... ... \n",
|
297 |
+
"4995 title tell ed gein butcher plainfield it zappy... \n",
|
298 |
+
"4996 film make sense ozzie harriet father know best... \n",
|
299 |
+
"4997 sex city great thing go problem saddle number ... \n",
|
300 |
+
"4998 please if anybody get chance read watch movie ... \n",
|
301 |
+
"4999 a film come manage absolutely terrible open ti... \n",
|
302 |
+
"\n",
|
303 |
+
"[5000 rows x 3 columns]"
|
304 |
+
]
|
305 |
+
},
|
306 |
+
"execution_count": 10,
|
307 |
+
"metadata": {},
|
308 |
+
"output_type": "execute_result"
|
309 |
+
}
|
310 |
+
],
|
311 |
+
"source": [
|
312 |
+
"odf"
|
313 |
+
]
|
314 |
+
},
|
315 |
+
{
|
316 |
+
"cell_type": "code",
|
317 |
+
"execution_count": 11,
|
318 |
+
"metadata": {},
|
319 |
+
"outputs": [],
|
320 |
+
"source": [
|
321 |
+
"steps = list(PreprocessingPipeline.pipeline_components().keys())\n",
|
322 |
+
"default_pre_steps_idx = [steps.index(i) for i in pre_steps]\n",
|
323 |
+
"default_post_steps_idx = [steps.index(i) for i in post_steps]"
|
324 |
+
]
|
325 |
+
},
|
326 |
+
{
|
327 |
+
"cell_type": "code",
|
328 |
+
"execution_count": 12,
|
329 |
+
"metadata": {},
|
330 |
+
"outputs": [
|
331 |
+
{
|
332 |
+
"data": {
|
333 |
+
"text/plain": [
|
334 |
+
"[1, 14, 2, 3, 4, 23, 22, 5, 21, 24]"
|
335 |
+
]
|
336 |
+
},
|
337 |
+
"execution_count": 12,
|
338 |
+
"metadata": {},
|
339 |
+
"output_type": "execute_result"
|
340 |
+
}
|
341 |
+
],
|
342 |
+
"source": [
|
343 |
+
"default_pre_steps_idx"
|
344 |
+
]
|
345 |
+
},
|
346 |
+
{
|
347 |
+
"cell_type": "code",
|
348 |
+
"execution_count": 13,
|
349 |
+
"metadata": {},
|
350 |
+
"outputs": [
|
351 |
+
{
|
352 |
+
"data": {
|
353 |
+
"text/plain": [
|
354 |
+
"[0, 7, 6, 8, 13, 10, 9, 15, 16, 17, 19, 20, 18, 23, 22, 21, 24]"
|
355 |
+
]
|
356 |
+
},
|
357 |
+
"execution_count": 13,
|
358 |
+
"metadata": {},
|
359 |
+
"output_type": "execute_result"
|
360 |
+
}
|
361 |
+
],
|
362 |
+
"source": [
|
363 |
+
"default_post_steps_idx"
|
364 |
+
]
|
365 |
+
},
|
366 |
+
{
|
367 |
+
"cell_type": "code",
|
368 |
+
"execution_count": null,
|
369 |
+
"metadata": {},
|
370 |
+
"outputs": [],
|
371 |
+
"source": [
|
372 |
+
"sorted(list(PreprocessingPipeline.pipeline_components().keys()))"
|
373 |
+
]
|
374 |
+
},
|
375 |
+
{
|
376 |
+
"cell_type": "code",
|
377 |
+
"execution_count": null,
|
378 |
+
"metadata": {},
|
379 |
+
"outputs": [],
|
380 |
+
"source": [
|
381 |
+
"list(PreprocessingPipeline.lemmatization_component().keys())"
|
382 |
+
]
|
383 |
+
},
|
384 |
+
{
|
385 |
+
"cell_type": "code",
|
386 |
+
"execution_count": null,
|
387 |
+
"metadata": {},
|
388 |
+
"outputs": [],
|
389 |
+
"source": []
|
390 |
+
}
|
391 |
+
],
|
392 |
+
"metadata": {
|
393 |
+
"interpreter": {
|
394 |
+
"hash": "aa7efd0b3ada76bb0689aa8ed0b61d7de788847e3d11d2d142fc5800c765982f"
|
395 |
+
},
|
396 |
+
"kernelspec": {
|
397 |
+
"display_name": "Python 3.7.11 64-bit ('wordify': conda)",
|
398 |
+
"language": "python",
|
399 |
+
"name": "python3"
|
400 |
+
},
|
401 |
+
"language_info": {
|
402 |
+
"codemirror_mode": {
|
403 |
+
"name": "ipython",
|
404 |
+
"version": 3
|
405 |
+
},
|
406 |
+
"file_extension": ".py",
|
407 |
+
"mimetype": "text/x-python",
|
408 |
+
"name": "python",
|
409 |
+
"nbconvert_exporter": "python",
|
410 |
+
"pygments_lexer": "ipython3",
|
411 |
+
"version": "3.7.11"
|
412 |
+
},
|
413 |
+
"orig_nbformat": 4
|
414 |
+
},
|
415 |
+
"nbformat": 4,
|
416 |
+
"nbformat_minor": 2
|
417 |
+
}
|