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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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import os\n",
    "import random\n",
    "from sklearn.model_selection import train_test_split\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_text_lists(filenames):\n",
    "    text_list = []\n",
    "    text_list_clean = []\n",
    "    for filename in filenames:\n",
    "        with open(filename,'r') as file:\n",
    "            data = file.read()\n",
    "        text_list = text_list + (data.split(\"<EOS>\"))\n",
    "        \n",
    "    for text in text_list:\n",
    "        #remove trailing ugly things at end of strings\n",
    "        text = text[0:text.find(\"EmbedShare\")]\n",
    "        text_list_clean.append(text)\n",
    "    return text_list_clean"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "ename": "FileNotFoundError",
     "evalue": "[Errno 2] No such file or directory: 'novireperi.txt'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mFileNotFoundError\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-5-974cc4a9f270>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m text_list = get_text_lists([\"Lilgpt.txt\", \"ye.txt\", \"zenske.txt\", \"flowmasteri.txt\",\n\u001b[0;32m----> 2\u001b[0;31m                             \"wutang.txt\", \"novireperi.txt\", \"novireperi2.txt\", \"novireperi3.txt\", \"OF.txt\"])\n\u001b[0m\u001b[1;32m      3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext_list\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-3-81b6d230f518>\u001b[0m in \u001b[0;36mget_text_lists\u001b[0;34m(filenames)\u001b[0m\n\u001b[1;32m      3\u001b[0m     \u001b[0mtext_list_clean\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m     \u001b[0;32mfor\u001b[0m \u001b[0mfilename\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mfilenames\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m         \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'r'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mfile\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      6\u001b[0m             \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfile\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      7\u001b[0m         \u001b[0mtext_list\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtext_list\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"<EOS>\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'novireperi.txt'"
     ]
    }
   ],
   "source": [
    "text_list = get_text_lists([\"Lilgpt.txt\", \"ye.txt\", \"zenske.txt\", \"flowmasteri.txt\",\n",
    "                            \"wutang.txt\", \"novireperi.txt\", \"novireperi2.txt\", \"novireperi3.txt\", \"OF.txt\"])\n",
    "print(len(text_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<BOS>3 Headed Goat[Intro]\n",
      "(Aviator)\n",
      "[Chorus: Lil Baby]\n",
      "These ain't no Guess jeans\n",
      "I dropped out of school, I'm still good at math, but,β€…nigga,β€…don't test me\n",
      "Iβ€…played to the left, they wentβ€…to the right, they tried to finesse me\n",
      "Still riding 'round with that blicky, I hope they don't catch me\n",
      "Police had raided our spot, so we went to the next street\n",
      "Play like I'm dumb, as soon as it pop, I'm goin' retarded\n",
      "He say I'm hard and he say I'm garbage, I'm rich regardless\n",
      "We in Miami in the middle of the winter, and we on them jet skis\n",
      "If we in Atlanta, I'm runnin' the 'Cat and I'm workin' the red key\n",
      "[Verse 1: Lil Durk]\n",
      "I cannot mention my homies inside of my song 'cause I know they be trappin' a lot\n",
      "I can't keep takin' these pills, when I'm in the trenches, they say I be cappin' a lot\n",
      "I know a nigga who say he got rich off the dope, but I know he be actin' a lot\n",
      "I know some niggas who said that they took down the city, but niggas be lackin' a lot\n",
      "Yeah\n",
      "That shit was awful, nigga had that dog food\n",
      "That day they shot you, I slid on a Mongoose\n",
      "You cannot come back around me, you turned your back on me, I cannot forget\n",
      "The police was lyin', they say that they caught you, but nigga, they made you admit\n",
      "Your name was found, you put in that work, they took your stick, you a bitch\n",
      "Fuck my opps, they be on my dick, they all be mad we rich (Turn up)\n",
      "[Verse 2: Lil Baby]\n",
      "Only twenty-five, livin' like a boss, ridin' 'round with a chauffeur\n",
      "I don't sell drugs, still be paranoid, keep lookin' over my shoulder\n",
      "Niggas lyin' like I'm stealin' swag, boy, that's my shit like I wrote it\n",
      "[Verse 3: Polo G]\n",
      "Uh\n",
      "These rappers really nice as hell\n",
      "I'm a different nigga when I'm pissed off\n",
      "Man, he say he gon' press up on who?\n",
      "I'ma get the steel like I'm Chris Paul\n",
      "Back to back suburbans, I'm a big dawg\n",
      "I was in the slums servin' Fentanyl\n",
      "Zombieland, junkies havin' withdrawals\n",
      "I been gettin' to it, lotta missed calls\n",
      "Turn it off, what the fuck is he talking 'bout?\n",
      "I should slap you for sayin' he hot as me\n",
      "I don't know who could fuck with me honestly\n",
      "They know I'm the man, so they watchin' me\n",
      "Different color bands like Monopoly\n",
      "Man, he must not be usin' his head\n",
      "If he thinkin' I don't keep a Glock with me\n",
      "That's like suicide if you play with us\n",
      "Got a better chance at the lottery\n",
      "Call an ambulance when that chopper sweep\n",
      "Make the crowd dance, choreography\n",
      "Once I got a plan, ain't no stoppin' me\n",
      "Three-car garage, million-dollar crib\n",
      "With a foreign bitch ridin' on top of me\n",
      "Lot of people done said I wouldn't be shit\n",
      "Well, I guess they owe me an apology\n",
      "[Chorus: Lil Baby]\n",
      "These ain't no Guess jeans\n",
      "I dropped out of school, I'm still good at math, but, nigga, don't test me\n",
      "I played to the left, they went to the right, they tried to finesse me\n",
      "Still riding 'round with that blicky, I hope they don't catch me\n",
      "Police had raided our spot, so we went to the next street\n",
      "Play like I'm dumb, as soon as it pop, I'm goin' retarded\n",
      "He say I'm hard and he say I'm garbage, I'm rich regardless\n",
      "We in Miami in the middle of the winter, and we on them jet skis\n",
      "If we in Atlanta, I'm runnin' the 'Cat and I'm workin' the red key35<EOS>\n"
     ]
    }
   ],
   "source": [
    "new_list = []\n",
    "for l in text_list:\n",
    "    n = l\n",
    "    n = n.replace(\"<BOS>\",\"\")\n",
    "    n = os.linesep.join([s for s in n.splitlines() if s])\n",
    "    n = \"<BOS>\"+ n + \"<EOS>\"\n",
    "    new_list.append(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1287\n",
      "11583\n"
     ]
    }
   ],
   "source": [
    "List_train, List_val = train_test_split(new_list, test_size = 0.1, random_state = 420)\n",
    "print(len(List_val))\n",
    "print(len(List_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1286/1286 [00:01<00:00, 1215.57it/s]\n"
     ]
    }
   ],
   "source": [
    "val_set = List_val[0]\n",
    "for i in tqdm(range(1,len(List_val))):\n",
    "    val_set = val_set+\"\\n\\n\"+ List_val[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 11582/11582 [05:06<00:00, 37.77it/s]\n"
     ]
    }
   ],
   "source": [
    "train_set = List_train[0]\n",
    "for i in tqdm(range(1,len(List_train))):\n",
    "    train_set = train_set+\"\\n\\n\"+List_train[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "file1 = open(\"train2.txt\",\"w+\")\n",
    "file1.write(train_set)\n",
    "file1.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "file2 = open(\"val2.txt\",\"w+\")\n",
    "file2.write(val_set)\n",
    "file2.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "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>Songs</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>&lt;BOS&gt;Night CourtBehind door one:\\nThere's thre...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>&lt;BOS&gt;Golden ArmsYeah, yeah\\nYeah, yeah\\n[Verse...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>&lt;BOS&gt;Flashing Lights (Clipse Remix)[Intro]\\nWe...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>&lt;BOS&gt;Lights Camera Action[Intro]\\nThe lights, ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>&lt;BOS&gt;Thug Life [Souljah] (Original Version 1)[...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               Songs\n",
       "0  <BOS>Night CourtBehind door one:\\nThere's thre...\n",
       "1  <BOS>Golden ArmsYeah, yeah\\nYeah, yeah\\n[Verse...\n",
       "2  <BOS>Flashing Lights (Clipse Remix)[Intro]\\nWe...\n",
       "3  <BOS>Lights Camera Action[Intro]\\nThe lights, ...\n",
       "4  <BOS>Thug Life [Souljah] (Original Version 1)[..."
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_train = pd.DataFrame(List_train,columns = [\"Songs\"])\n",
    "df_train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "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>Songs</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>&lt;BOS&gt;Letter 2 My Unborn[Intro]\\nTo my unborn c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>&lt;BOS&gt;Trouble[Intro]\\nTrouble on last, oh well\\...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>&lt;BOS&gt;SouthsideSu woo\\nBitch I'm from the south...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>&lt;BOS&gt;Gangsta PartyFeat. Lil B\\n[Lil Wayne]\\nI ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>&lt;BOS&gt;Gangstaz Life[Verse 1: Snoop Dogg]\\n10-20...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               Songs\n",
       "0  <BOS>Letter 2 My Unborn[Intro]\\nTo my unborn c...\n",
       "1  <BOS>Trouble[Intro]\\nTrouble on last, oh well\\...\n",
       "2  <BOS>SouthsideSu woo\\nBitch I'm from the south...\n",
       "3  <BOS>Gangsta PartyFeat. Lil B\\n[Lil Wayne]\\nI ...\n",
       "4  <BOS>Gangstaz Life[Verse 1: Snoop Dogg]\\n10-20..."
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_val = pd.DataFrame(List_val,columns = [\"Songs\"])\n",
    "df_val.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_train.to_csv(\"Train.tsv\",sep=\"\\t\",index = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_val.to_csv(\"Val.tsv\",sep=\"\\t\",index = False)"
   ]
  }
 ],
 "metadata": {
  "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.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}