Skip to content

Commit 02fd6b3

Browse files
author
codebasics
committed
tf data input pipeline
1 parent db143d1 commit 02fd6b3

File tree

139 files changed

+1193
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+1193
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Basically there's a family where a little boy (Jake) thinks there's a zombie in his closet & his parents are fighting all the time.<br /><br />This movie is slower than a soap opera... and suddenly, Jake decides to become Rambo and kill the zombie.<br /><br />OK, first of all when you're going to make a film you must Decide if its a thriller or a drama! As a drama the movie is watchable. Parents are divorcing & arguing like in real life. And then we have Jake with his closet which totally ruins all the film! I expected to see a BOOGEYMAN similar movie, and instead i watched a drama with some meaningless thriller spots.<br /><br />3 out of 10 just for the well playing parents & descent dialogs. As for the shots with Jake: just ignore them.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This show was an amazing, fresh & innovative idea in the 70's when it first aired. The first 7 or 8 years were brilliant, but things dropped off after that. By 1990, the show was not really funny anymore, and it's continued its decline further to the complete waste of time it is today.<br /><br />It's truly disgraceful how far this show has fallen. The writing is painfully bad, the performances are almost as bad - if not for the mildly entertaining respite of the guest-hosts, this show probably wouldn't still be on the air. I find it so hard to believe that the same creator that hand-selected the original cast also chose the band of hacks that followed. How can one recognize such brilliance and then see fit to replace it with such mediocrity? I felt I must give 2 stars out of respect for the original cast that made this show such a huge success. As it is now, the show is just awful. I can't believe it's still on the air.

44_tf_data_pipeline/Exercise/reviews/negative/neg_3.txt

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
One of the other reviewers has mentioned that after watching just 1 Oz episode you'll be hooked. They are right, as this is exactly what happened with me.<br /><br />The first thing that struck me about Oz was its brutality and unflinching scenes of violence, which set in right from the word GO. Trust me, this is not a show for the faint hearted or timid. This show pulls no punches with regards to drugs, sex or violence. Its is hardcore, in the classic use of the word.<br /><br />It is called OZ as that is the nickname given to the Oswald Maximum Security State Penitentary. It focuses mainly on Emerald City, an experimental section of the prison where all the cells have glass fronts and face inwards, so privacy is not high on the agenda. Em City is home to many..Aryans, Muslims, gangstas, Latinos, Christians, Italians, Irish and more....so scuffles, death stares, dodgy dealings and shady agreements are never far away.<br /><br />I would say the main appeal of the show is due to the fact that it goes where other shows wouldn't dare. Forget pretty pictures painted for mainstream audiences, forget charm, forget romance...OZ doesn't mess around. The first episode I ever saw struck me as so nasty it was surreal, I couldn't say I was ready for it, but as I watched more, I developed a taste for Oz, and got accustomed to the high levels of graphic violence. Not just violence, but injustice (crooked guards who'll be sold out for a nickel, inmates who'll kill on order and get away with it, well mannered, middle class inmates being turned into prison bitches due to their lack of street skills or prison experience) Watching Oz, you may become comfortable with what is uncomfortable viewing....thats if you can get in touch with your darker side.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A wonderful little production. <br /><br />The filming technique is very unassuming- very old-time-BBC fashion and gives a comforting, and sometimes discomforting, sense of realism to the entire piece. <br /><br />The actors are extremely well chosen- Michael Sheen not only "has got all the polari" but he has all the voices down pat too! You can truly see the seamless editing guided by the references to Williams' diary entries, not only is it well worth the watching but it is a terrificly written and performed piece. A masterful production about one of the great master's of comedy and his life. <br /><br />The realism really comes home with the little things: the fantasy of the guard which, rather than use the traditional 'dream' techniques remains solid then disappears. It plays on our knowledge and our senses, particularly with the scenes concerning Orton and Halliwell and the sets (particularly of their flat with Halliwell's murals decorating every surface) are terribly well done.

44_tf_data_pipeline/Exercise/reviews/positive/pos_3.txt

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"<h3 align=\"center\" style='color:blue'>TF Data Input Pipeline: Exercise Solution</h3>"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"Moview reviews are present as individual text file (one file per review) in review folder. \n",
15+
"\n",
16+
"Folder structure looks like this,\n",
17+
"\n",
18+
"reviews\n",
19+
"\n",
20+
" |__ positive\n",
21+
" |__pos_1.txt\n",
22+
" |__pos_2.txt\n",
23+
" |__pos_3.txt\n",
24+
" |__ negative\n",
25+
" |__neg_1.txt\n",
26+
" |__neg_2.txt\n",
27+
" |__neg_3.txt\n",
28+
" \n",
29+
"You need to read these reviews using tf.data.Dataset and perform following transformations,\n",
30+
"\n",
31+
"(1) Read text review and generate a label from folder name. your dataset should have review text and label as a tuple\n",
32+
"\n",
33+
"(2) Filter blank text review. Two files are blank in this dataset\n",
34+
"\n",
35+
"(3) Do all of the above transformations in single line of code. Also shuffle all the reviews"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": 168,
41+
"metadata": {},
42+
"outputs": [],
43+
"source": [
44+
"import tensorflow as tf"
45+
]
46+
},
47+
{
48+
"cell_type": "markdown",
49+
"metadata": {},
50+
"source": [
51+
"<h3 style='color:purple'>Retrieve review file paths in a tensorflow dataset</h3>"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": 177,
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"reviews_ds = tf.data.Dataset.list_files('reviews/*/*', shuffle=False)"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": 178,
66+
"metadata": {
67+
"scrolled": true
68+
},
69+
"outputs": [
70+
{
71+
"name": "stdout",
72+
"output_type": "stream",
73+
"text": [
74+
"b'reviews\\\\negative\\\\neg_1.txt'\n",
75+
"b'reviews\\\\negative\\\\neg_2.txt'\n",
76+
"b'reviews\\\\negative\\\\neg_3.txt'\n",
77+
"b'reviews\\\\positive\\\\pos_1.txt'\n",
78+
"b'reviews\\\\positive\\\\pos_2.txt'\n",
79+
"b'reviews\\\\positive\\\\pos_3.txt'\n"
80+
]
81+
}
82+
],
83+
"source": [
84+
"for file in reviews_ds:\n",
85+
" print(file.numpy())"
86+
]
87+
},
88+
{
89+
"cell_type": "markdown",
90+
"metadata": {},
91+
"source": [
92+
"<h3 style='color:purple'>Extract review text from these files. Extract label from folder name</h3>"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": 179,
98+
"metadata": {},
99+
"outputs": [],
100+
"source": [
101+
"import os\n",
102+
"def extract_review_and_label(file_path):\n",
103+
" return tf.io.read_file(file_path), tf.strings.split(file_path, os.path.sep)[-2]"
104+
]
105+
},
106+
{
107+
"cell_type": "code",
108+
"execution_count": 180,
109+
"metadata": {},
110+
"outputs": [
111+
{
112+
"name": "stdout",
113+
"output_type": "stream",
114+
"text": [
115+
"Review: b\"Basically there's a family where a little boy (Jak\"\n",
116+
"Label: b'negative'\n",
117+
"Review: b'This show was an amazing, fresh & innovative idea '\n",
118+
"Label: b'negative'\n",
119+
"Review: b''\n",
120+
"Label: b'negative'\n",
121+
"Review: b'One of the other reviewers has mentioned that afte'\n",
122+
"Label: b'positive'\n",
123+
"Review: b'A wonderful little production. <br /><br />The fil'\n",
124+
"Label: b'positive'\n",
125+
"Review: b''\n",
126+
"Label: b'positive'\n"
127+
]
128+
}
129+
],
130+
"source": [
131+
"reviews_ds_1 = reviews_ds.map(extract_review_and_label)\n",
132+
"for review, label in reviews_ds_1:\n",
133+
" print(\"Review: \",review.numpy()[:50])\n",
134+
" print(\"Label: \",label.numpy())"
135+
]
136+
},
137+
{
138+
"cell_type": "markdown",
139+
"metadata": {},
140+
"source": [
141+
"<h3 style='color:purple'>Filter blank reviews</h3>"
142+
]
143+
},
144+
{
145+
"cell_type": "code",
146+
"execution_count": 181,
147+
"metadata": {
148+
"scrolled": true
149+
},
150+
"outputs": [
151+
{
152+
"name": "stdout",
153+
"output_type": "stream",
154+
"text": [
155+
"Review: b\"Basically there's a family where a little boy (Jak\"\n",
156+
"Label: b'negative'\n",
157+
"Review: b'This show was an amazing, fresh & innovative idea '\n",
158+
"Label: b'negative'\n",
159+
"Review: b'One of the other reviewers has mentioned that afte'\n",
160+
"Label: b'positive'\n",
161+
"Review: b'A wonderful little production. <br /><br />The fil'\n",
162+
"Label: b'positive'\n"
163+
]
164+
}
165+
],
166+
"source": [
167+
"reviews_ds_2 = reviews_ds_1.filter(lambda review, label: review!=\"\")\n",
168+
"for review, label in reviews_ds_2.as_numpy_iterator():\n",
169+
" print(\"Review: \",review[:50])\n",
170+
" print(\"Label: \",label)"
171+
]
172+
},
173+
{
174+
"cell_type": "markdown",
175+
"metadata": {},
176+
"source": [
177+
"<h3 style='color:purple'>Perform map, filter and shuffle all in single line of code</h3>"
178+
]
179+
},
180+
{
181+
"cell_type": "code",
182+
"execution_count": 182,
183+
"metadata": {},
184+
"outputs": [
185+
{
186+
"name": "stdout",
187+
"output_type": "stream",
188+
"text": [
189+
"Review: b'This show was an amazing, fresh & innovative idea '\n",
190+
"Label: b'negative'\n",
191+
"Review: b\"Basically there's a family where a little boy (Jak\"\n",
192+
"Label: b'negative'\n",
193+
"Review: b'A wonderful little production. <br /><br />The fil'\n",
194+
"Label: b'positive'\n",
195+
"Review: b'One of the other reviewers has mentioned that afte'\n",
196+
"Label: b'positive'\n"
197+
]
198+
}
199+
],
200+
"source": [
201+
"final_ds = reviews_ds.map(extract_review_and_label).filter(lambda review, label: review!=\"\").shuffle(3)\n",
202+
"for review, label in final_ds.as_numpy_iterator():\n",
203+
" print(\"Review:\",review[:50])\n",
204+
" print(\"Label:\",label)"
205+
]
206+
}
207+
],
208+
"metadata": {
209+
"kernelspec": {
210+
"display_name": "Python 3",
211+
"language": "python",
212+
"name": "python3"
213+
},
214+
"language_info": {
215+
"codemirror_mode": {
216+
"name": "ipython",
217+
"version": 3
218+
},
219+
"file_extension": ".py",
220+
"mimetype": "text/x-python",
221+
"name": "python",
222+
"nbconvert_exporter": "python",
223+
"pygments_lexer": "ipython3",
224+
"version": "3.8.5"
225+
}
226+
},
227+
"nbformat": 4,
228+
"nbformat_minor": 4
229+
}

0 commit comments

Comments
 (0)