{ "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(\"\"))\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\u001b[0m in \u001b[0;36m\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\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\"\"\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": [ "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\n" ] } ], "source": [ "new_list = []\n", "for l in text_list:\n", " n = l\n", " n = n.replace(\"\",\"\")\n", " n = os.linesep.join([s for s in n.splitlines() if s])\n", " n = \"\"+ n + \"\"\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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Songs
0<BOS>Night CourtBehind door one:\\nThere's thre...
1<BOS>Golden ArmsYeah, yeah\\nYeah, yeah\\n[Verse...
2<BOS>Flashing Lights (Clipse Remix)[Intro]\\nWe...
3<BOS>Lights Camera Action[Intro]\\nThe lights, ...
4<BOS>Thug Life [Souljah] (Original Version 1)[...
\n", "
" ], "text/plain": [ " Songs\n", "0 Night CourtBehind door one:\\nThere's thre...\n", "1 Golden ArmsYeah, yeah\\nYeah, yeah\\n[Verse...\n", "2 Flashing Lights (Clipse Remix)[Intro]\\nWe...\n", "3 Lights Camera Action[Intro]\\nThe lights, ...\n", "4 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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Songs
0<BOS>Letter 2 My Unborn[Intro]\\nTo my unborn c...
1<BOS>Trouble[Intro]\\nTrouble on last, oh well\\...
2<BOS>SouthsideSu woo\\nBitch I'm from the south...
3<BOS>Gangsta PartyFeat. Lil B\\n[Lil Wayne]\\nI ...
4<BOS>Gangstaz Life[Verse 1: Snoop Dogg]\\n10-20...
\n", "
" ], "text/plain": [ " Songs\n", "0 Letter 2 My Unborn[Intro]\\nTo my unborn c...\n", "1 Trouble[Intro]\\nTrouble on last, oh well\\...\n", "2 SouthsideSu woo\\nBitch I'm from the south...\n", "3 Gangsta PartyFeat. Lil B\\n[Lil Wayne]\\nI ...\n", "4 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 }