{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from IPython.display import clear_output, Markdown, Math\n", "import ipywidgets as widgets\n", "import os\n", "import glob\n", "import json\n", "import numpy as np\n", "import itertools\n", "import sklearn.utils as sku\n", "from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer, HashingVectorizer\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.preprocessing import MultiLabelBinarizer" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import sys\n", "sys.path.append(\"..\")\n", "\n", "from Tools.Emoji_Distance import sentiment_vector_to_emoji\n", "from Tools.Emoji_Distance import emoji_to_sentiment_vector\n", "\n", "def emoji2sent(emoji_arr):\n", " return np.array([emoji_to_sentiment_vector(e) for e in emoji_arr])\n", "\n", "def sent2emoji(sent_arr):\n", " return [sentiment_vector_to_emoji(s) for s in sent_arr]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "SINGLE_LABEL = True" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# simple twitter approach\n", "*for learning emoji usage by single (in the meaning of unconnected) twitter messages*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## loading train data" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "data_root_folder = \"./data_en/\" # i created a symlink here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* get all json files in `data_root_folder`" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "json_files = sorted(glob.glob(data_root_folder + \"/*.json\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "----" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* so far, only load the first file" ] }, { "cell_type": "code", "execution_count": 6, "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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
EMOJIHASHTAGSLINKED_USERdatetimeidlangpersonreply_totext
0[πŸ”₯, πŸ‘][][]2017-11-01 13:29:00925716304635547600en31507978NaNfashionbombdaily's photo <EMOJI><EMOJI>🏼
1[🀦][][]2017-11-01 13:29:00925716304664911900en231994649NaNIt’s scary how on point my horoscope be <EMOJI...
2[πŸ˜„][][]2017-11-01 13:29:03925716317214089200en2592765104NaNWoooaaaahhh <EMOJI>
3[πŸ“·][][]2017-11-01 13:29:04925716321416949800en278737933NaN<EMOJI> vivalcli: Portraits by Zhao Guojing an...
4[😩, 😩][][@hiphopphiIes]2017-11-01 13:29:06925716329801310200en8245862536349819009.257162e+17<USER> i wanna know too<EMOJI><EMOJI>
5[😭, πŸ’“][][@WizMommma]2017-11-01 13:29:02925716313019965400en15819538149.257088e+17<USER> veda was yoda too <EMOJI><EMOJI>
6[πŸ˜‚][][]2017-11-01 13:29:05925716325607133200en1001999683NaNI’m less stressed about turning 30 now <EMOJI>...
7[πŸ’―][][]2017-11-01 13:29:07925716334008082400en745222369183043600NaNFull charged. <EMOJI>
8[πŸ™„][][@SeaDimon, @lsarsour]2017-11-01 13:29:09925716342401052700en7985571552175391009.257147e+17<USER> That’s part of the problem, (they) <USE...
9[😟, πŸ˜₯, 😒][][@Ian_khetye]2017-11-01 13:29:10925716346570240000en7443960391264215009.250629e+17<USER> got me emotional there<EMOJI><EMOJI><EM...
10[🌻][][]2017-11-01 13:29:13925716359182520300en7214900101182054008.965900e+17back to the yellow <EMOJI>
11[🍁, 🌺, πŸ‚][][@Dimafadma]2017-11-01 13:29:15925716367558545400en5205367239.257159e+17<USER> Happy month to you and your loved ones ...
12[πŸƒ][#mortdale, #partofthefamily, #gorgeousboy][]2017-11-01 13:29:16925716371735900200en850852815941517300NaNMaxx and Patricia. Family hangs at For Good He...
13[πŸ’­, 🀦][][]2017-11-01 13:29:20925716388513230800en914145041588867100NaNI need to STOP beating myself up with my thoug...
14[😍, 😘][#7YearsOfKMH2][]2017-11-01 13:29:20925716388525645800en2425405622NaNCutest Son <EMOJI>Roll no. 31 <EMOJI> <HASHTAG>
15[😜][][]2017-11-01 13:29:22925716396931240000en4614871873NaNBy the summer I should have everything up and ...
16[πŸ˜‚, πŸ”₯][][]2017-11-01 13:29:23925716401125331000en2831608345NaNI know my English is not that good but that do...
17[πŸ’•][][@yungbabytate]2017-11-01 13:29:23925716401133948900en7885719746330092009.255778e+17<USER> I <EMOJI> u mama
18[πŸ˜‰][][@cmckenney]2017-11-01 13:29:23925716401125544000en2183078029.257115e+17<USER> That picture was NOT taken this morning...
19[πŸ‘…][#footfetishnation][]2017-11-01 13:29:25925716409489002500en885261166146179100NaNWelcome to <HASHTAG> <EMOJI>
20[πŸ‘Œ, πŸ™‚][][]2017-11-01 13:29:25925716409497272300en831437760833609700NaNAwkward <EMOJI><EMOJI>
21[πŸ€—, πŸ“Ί][][]2017-11-01 13:29:26925716413699854300en231664542NaNback at it with supernatural <EMOJI><EMOJI>
22[πŸ’―][][]2017-11-01 13:29:26925716413679009800en3196847035NaNOne of the best things I've learned was to sto...
23[πŸ‘…, πŸ’¦, πŸ‘][][@ctrlpurp]2017-11-01 13:29:29925716426278735900en9184928583526359009.257161e+17<USER> Can I taste?<EMOJI><EMOJI><EMOJI>
24[πŸ’”][][@saunders_court1]2017-11-01 13:29:30925716430473039900en34711873379.257163e+17<USER> we miss you ☹️<EMOJI>
25[🀐, 🀐, 🀐][][]2017-11-01 13:29:31925716434667184100en780060488600199200NaNActually my bias in WJSN are Eunseo &amp; Bona...
26[😴][][]2017-11-01 13:29:32925716438853345300en388380690NaNI so cannot be bothered with the rest of the d...
27[πŸ˜‚][][@xxxtentacion]2017-11-01 13:29:35925716451457163300en899320696869974000NaN<USER> 2lit4life<EMOJI>
28[πŸ˜‚, πŸ™„][][]2017-11-01 13:29:35925716451461357600en784790670NaNI’m not stop saying that!<EMOJI><EMOJI>
29[πŸŽ‰, πŸŽ‚, 🎈, 🎊, 🎁, πŸ’œ][][@justinerooney_]2017-11-01 13:29:37925716459828936700en3051266655NaN<USER> HAPPY BIHDAY <EMOJI><EMOJI><EMOJI><EMOJ...
..............................
68703[πŸ˜•][#halloweencostumes][]2017-11-01 07:23:04925624214522036200en1672876458NaN<HASHTAG> this one falls under the weird crazy...
68704[πŸ˜‚, 😩][][]2017-11-01 07:23:05925624218682777600en382473866NaNI'm not allowed to have chocolates yet, then I...
68705[πŸ˜‚][#MUFC][]2017-11-01 07:23:06925624222889766900en893145405457911800NaNManchester United manager Mourinho slams 'spec...
68706[πŸ’–][][]2017-11-01 07:23:07925624227088121900en240378516NaN<EMOJI> en Bushwhick
68707[πŸŒ†, πŸ‘‰, πŸš–, πŸ“ž][#BurkeCentre][]2017-11-01 07:23:18925624273237983200en784620573209002000NaN: <HASHTAG> <EMOJI> <EMOJI><EMOJI> For Taxi <E...
68708[😁][][@mychosliaheart, @BarrettoJulia, @iamjoshuaga...2017-11-01 07:23:18925624273212805100en1709981879.254136e+17<USER> <USER> <USER> Look, Mammeh and Daddeh! ...
68709[πŸ˜‹][][]2017-11-01 07:23:24925624298395533300en1348667816NaNLife is so good with you <EMOJI>
68710[πŸ‘Œ, πŸŽƒ, 😘][#portlandoregon, #portlandhalloween, #carrie…][]2017-11-01 07:23:24925624298378801200en722481645765300200NaNHappy Halloween! <EMOJI>🏽<EMOJI><EMOJI> <HASHT...
68711[πŸ‘][][@8limbsbondi...]2017-11-01 07:23:26925624306779897900en2443251500NaNSome work on the ropes in today’s boxing class...
68712[😭][][]2017-11-01 07:23:27925624310974136300en2406186390NaNScotty and Kristen’s halloween costumes <EMOJI>
68713[πŸ˜‚][][@rfrandrea, @AdaaanAndyyy]2017-11-01 07:23:30925624323557146600en10394481499.256150e+17<USER> <USER> May pre-month celebration sis <E...
68714[😭, 😭, πŸ’˜][][@peachshua1230]2017-11-01 07:23:31925624327755591700en8450855445896724009.256009e+17<USER> Awww <EMOJI> Ajsksjdjd im smiling like ...
68715[😫, βœ‹][][]2017-11-01 07:23:34925624340342812700en924752524871131100NaNI hate when I send a text or snap n I'm so anx...
68716[πŸ˜‚, πŸ™][][]2017-11-01 07:23:34925624340355280900en419493819NaNThe answer is no I have no plans and I never l...
68717[😭][][@BeachBoy_Gab]2017-11-01 07:23:34925624340346937300en24577459529.256219e+17<USER> LMAOOO I'm so proud <EMOJI>
68718[😒, πŸ’”][][]2017-11-01 07:23:34925624340338507800en1955767531NaNMy cousin/little sister is leaving to San Fran...
68719[πŸ™ƒ][][]2017-11-01 07:23:35925624344524361700en796490344581898200NaNCan't be alone w my thoughts tonight so just g...
68720[πŸ˜‚, πŸ˜‚, πŸ˜‚, πŸ˜‚, πŸ˜‚][][]2017-11-01 07:23:36925624348710285300en907808317124177900NaN<EMOJI><EMOJI><EMOJI><EMOJI><EMOJI> ambot!!!
68721[πŸ‘Œ, πŸ‘Š, πŸ™Œ][][]2017-11-01 07:23:37925624352929910800en262162415NaN<EMOJI>🏽<EMOJI>🏽 1st of the month!!Happy 1st o...
68722[😴][#WednesdayWisdom][]2017-11-01 07:23:41925624369715515400en574882525NaN<HASHTAG> ... stay in bed <EMOJI>
68723[πŸ˜‚, πŸ˜‚, πŸ˜‚, πŸ˜‚][][@Louis_Tomlinson, @NiallOfficial]2017-11-01 07:23:44925624382269124600en5561751739.254038e+17<USER> <USER> THIS IS GOLD. GOLD. <EMOJI><EMOJ...
68724[πŸ˜€][][]2017-11-01 07:23:45925624386455031800en1610265588NaN<EMOJI> thank you for the kind compliment
68725[😎][][]2017-11-01 07:23:45925624386454937600en4760724450NaNEnjoyed the silence <EMOJI>
68726[✨][][]2017-11-01 07:23:46925624390657572900en882858115636514800NaNOS: Spiderman Homecoming <EMOJI>
68727[🀷][][]2017-11-01 07:23:46925624390682849300en188129628NaNGo to hell <EMOJI>πŸ½β€β™€οΈ
68728[😘][][]2017-11-01 07:23:46925624390666129400en2473135939NaNThank you Yomi! <EMOJI>
68729[πŸ˜‚][][@discopiggu]2017-11-01 07:23:46925624390670106600en23735842099.256241e+17<USER> Lol. Just enjoy the stars. Music Kidhar...
68730[πŸ™][#NYCStrong][]2017-11-01 07:23:50925624407459971100en181689756NaNThoughts and prayers for NY<EMOJI>🏻 <HASHTAG>
68731[πŸ’][#GreatSuccess][@BrianyH]2017-11-01 07:23:50925624407460057100en601607889.254610e+17<USER> I searched COCK, PENIS, SHLONG, WINKY, ...
68732[πŸƒ, 🌻, 🌻, πŸƒ, πŸƒ, πŸ’, πŸ’, πŸƒ, πŸ™‹][][@amitbarman520]2017-11-01 07:23:53925624420022063100en37922907259.256215e+17<USER> Thank you so much<EMOJI><EMOJI><EMOJI><...
\n", "

68733 rows Γ— 9 columns

\n", "
" ], "text/plain": [ " EMOJI \\\n", "0 [πŸ”₯, πŸ‘] \n", "1 [🀦] \n", "2 [πŸ˜„] \n", "3 [πŸ“·] \n", "4 [😩, 😩] \n", "5 [😭, πŸ’“] \n", "6 [πŸ˜‚] \n", "7 [πŸ’―] \n", "8 [πŸ™„] \n", "9 [😟, πŸ˜₯, 😒] \n", "10 [🌻] \n", "11 [🍁, 🌺, πŸ‚] \n", "12 [πŸƒ] \n", "13 [πŸ’­, 🀦] \n", "14 [😍, 😘] \n", "15 [😜] \n", "16 [πŸ˜‚, πŸ”₯] \n", "17 [πŸ’•] \n", "18 [πŸ˜‰] \n", "19 [πŸ‘…] \n", "20 [πŸ‘Œ, πŸ™‚] \n", "21 [πŸ€—, πŸ“Ί] \n", "22 [πŸ’―] \n", "23 [πŸ‘…, πŸ’¦, πŸ‘] \n", "24 [πŸ’”] \n", "25 [🀐, 🀐, 🀐] \n", "26 [😴] \n", "27 [πŸ˜‚] \n", "28 [πŸ˜‚, πŸ™„] \n", "29 [πŸŽ‰, πŸŽ‚, 🎈, 🎊, 🎁, πŸ’œ] \n", "... ... \n", "68703 [πŸ˜•] \n", "68704 [πŸ˜‚, 😩] \n", "68705 [πŸ˜‚] \n", "68706 [πŸ’–] \n", "68707 [πŸŒ†, πŸ‘‰, πŸš–, πŸ“ž] \n", "68708 [😁] \n", "68709 [πŸ˜‹] \n", "68710 [πŸ‘Œ, πŸŽƒ, 😘] \n", "68711 [πŸ‘] \n", "68712 [😭] \n", "68713 [πŸ˜‚] \n", "68714 [😭, 😭, πŸ’˜] \n", "68715 [😫, βœ‹] \n", "68716 [πŸ˜‚, πŸ™] \n", "68717 [😭] \n", "68718 [😒, πŸ’”] \n", "68719 [πŸ™ƒ] \n", "68720 [πŸ˜‚, πŸ˜‚, πŸ˜‚, πŸ˜‚, πŸ˜‚] \n", "68721 [πŸ‘Œ, πŸ‘Š, πŸ™Œ] \n", "68722 [😴] \n", "68723 [πŸ˜‚, πŸ˜‚, πŸ˜‚, πŸ˜‚] \n", "68724 [πŸ˜€] \n", "68725 [😎] \n", "68726 [✨] \n", "68727 [🀷] \n", "68728 [😘] \n", "68729 [πŸ˜‚] \n", "68730 [πŸ™] \n", "68731 [πŸ’] \n", "68732 [πŸƒ, 🌻, 🌻, πŸƒ, πŸƒ, πŸ’, πŸ’, πŸƒ, πŸ™‹] \n", "\n", " HASHTAGS \\\n", "0 [] \n", "1 [] \n", "2 [] \n", "3 [] \n", "4 [] \n", "5 [] \n", "6 [] \n", "7 [] \n", "8 [] \n", "9 [] \n", "10 [] \n", "11 [] \n", "12 [#mortdale, #partofthefamily, #gorgeousboy] \n", "13 [] \n", "14 [#7YearsOfKMH2] \n", "15 [] \n", "16 [] \n", "17 [] \n", "18 [] \n", "19 [#footfetishnation] \n", "20 [] \n", "21 [] \n", "22 [] \n", "23 [] \n", "24 [] \n", "25 [] \n", "26 [] \n", "27 [] \n", "28 [] \n", "29 [] \n", "... ... \n", "68703 [#halloweencostumes] \n", "68704 [] \n", "68705 [#MUFC] \n", "68706 [] \n", "68707 [#BurkeCentre] \n", "68708 [] \n", "68709 [] \n", "68710 [#portlandoregon, #portlandhalloween, #carrie…] \n", "68711 [] \n", "68712 [] \n", "68713 [] \n", "68714 [] \n", "68715 [] \n", "68716 [] \n", "68717 [] \n", "68718 [] \n", "68719 [] \n", "68720 [] \n", "68721 [] \n", "68722 [#WednesdayWisdom] \n", "68723 [] \n", "68724 [] \n", "68725 [] \n", "68726 [] \n", "68727 [] \n", "68728 [] \n", "68729 [] \n", "68730 [#NYCStrong] \n", "68731 [#GreatSuccess] \n", "68732 [] \n", "\n", " LINKED_USER datetime \\\n", "0 [] 2017-11-01 13:29:00 \n", "1 [] 2017-11-01 13:29:00 \n", "2 [] 2017-11-01 13:29:03 \n", "3 [] 2017-11-01 13:29:04 \n", "4 [@hiphopphiIes] 2017-11-01 13:29:06 \n", "5 [@WizMommma] 2017-11-01 13:29:02 \n", "6 [] 2017-11-01 13:29:05 \n", "7 [] 2017-11-01 13:29:07 \n", "8 [@SeaDimon, @lsarsour] 2017-11-01 13:29:09 \n", "9 [@Ian_khetye] 2017-11-01 13:29:10 \n", "10 [] 2017-11-01 13:29:13 \n", "11 [@Dimafadma] 2017-11-01 13:29:15 \n", "12 [] 2017-11-01 13:29:16 \n", "13 [] 2017-11-01 13:29:20 \n", "14 [] 2017-11-01 13:29:20 \n", "15 [] 2017-11-01 13:29:22 \n", "16 [] 2017-11-01 13:29:23 \n", "17 [@yungbabytate] 2017-11-01 13:29:23 \n", "18 [@cmckenney] 2017-11-01 13:29:23 \n", "19 [] 2017-11-01 13:29:25 \n", "20 [] 2017-11-01 13:29:25 \n", "21 [] 2017-11-01 13:29:26 \n", "22 [] 2017-11-01 13:29:26 \n", "23 [@ctrlpurp] 2017-11-01 13:29:29 \n", "24 [@saunders_court1] 2017-11-01 13:29:30 \n", "25 [] 2017-11-01 13:29:31 \n", "26 [] 2017-11-01 13:29:32 \n", "27 [@xxxtentacion] 2017-11-01 13:29:35 \n", "28 [] 2017-11-01 13:29:35 \n", "29 [@justinerooney_] 2017-11-01 13:29:37 \n", "... ... ... \n", "68703 [] 2017-11-01 07:23:04 \n", "68704 [] 2017-11-01 07:23:05 \n", "68705 [] 2017-11-01 07:23:06 \n", "68706 [] 2017-11-01 07:23:07 \n", "68707 [] 2017-11-01 07:23:18 \n", "68708 [@mychosliaheart, @BarrettoJulia, @iamjoshuaga... 2017-11-01 07:23:18 \n", "68709 [] 2017-11-01 07:23:24 \n", "68710 [] 2017-11-01 07:23:24 \n", "68711 [@8limbsbondi...] 2017-11-01 07:23:26 \n", "68712 [] 2017-11-01 07:23:27 \n", "68713 [@rfrandrea, @AdaaanAndyyy] 2017-11-01 07:23:30 \n", "68714 [@peachshua1230] 2017-11-01 07:23:31 \n", "68715 [] 2017-11-01 07:23:34 \n", "68716 [] 2017-11-01 07:23:34 \n", "68717 [@BeachBoy_Gab] 2017-11-01 07:23:34 \n", "68718 [] 2017-11-01 07:23:34 \n", "68719 [] 2017-11-01 07:23:35 \n", "68720 [] 2017-11-01 07:23:36 \n", "68721 [] 2017-11-01 07:23:37 \n", "68722 [] 2017-11-01 07:23:41 \n", "68723 [@Louis_Tomlinson, @NiallOfficial] 2017-11-01 07:23:44 \n", "68724 [] 2017-11-01 07:23:45 \n", "68725 [] 2017-11-01 07:23:45 \n", "68726 [] 2017-11-01 07:23:46 \n", "68727 [] 2017-11-01 07:23:46 \n", "68728 [] 2017-11-01 07:23:46 \n", "68729 [@discopiggu] 2017-11-01 07:23:46 \n", "68730 [] 2017-11-01 07:23:50 \n", "68731 [@BrianyH] 2017-11-01 07:23:50 \n", "68732 [@amitbarman520] 2017-11-01 07:23:53 \n", "\n", " id lang person reply_to \\\n", "0 925716304635547600 en 31507978 NaN \n", "1 925716304664911900 en 231994649 NaN \n", "2 925716317214089200 en 2592765104 NaN \n", "3 925716321416949800 en 278737933 NaN \n", "4 925716329801310200 en 824586253634981900 9.257162e+17 \n", "5 925716313019965400 en 1581953814 9.257088e+17 \n", "6 925716325607133200 en 1001999683 NaN \n", "7 925716334008082400 en 745222369183043600 NaN \n", "8 925716342401052700 en 798557155217539100 9.257147e+17 \n", "9 925716346570240000 en 744396039126421500 9.250629e+17 \n", "10 925716359182520300 en 721490010118205400 8.965900e+17 \n", "11 925716367558545400 en 520536723 9.257159e+17 \n", "12 925716371735900200 en 850852815941517300 NaN \n", "13 925716388513230800 en 914145041588867100 NaN \n", "14 925716388525645800 en 2425405622 NaN \n", "15 925716396931240000 en 4614871873 NaN \n", "16 925716401125331000 en 2831608345 NaN \n", "17 925716401133948900 en 788571974633009200 9.255778e+17 \n", "18 925716401125544000 en 218307802 9.257115e+17 \n", "19 925716409489002500 en 885261166146179100 NaN \n", "20 925716409497272300 en 831437760833609700 NaN \n", "21 925716413699854300 en 231664542 NaN \n", "22 925716413679009800 en 3196847035 NaN \n", "23 925716426278735900 en 918492858352635900 9.257161e+17 \n", "24 925716430473039900 en 3471187337 9.257163e+17 \n", "25 925716434667184100 en 780060488600199200 NaN \n", "26 925716438853345300 en 388380690 NaN \n", "27 925716451457163300 en 899320696869974000 NaN \n", "28 925716451461357600 en 784790670 NaN \n", "29 925716459828936700 en 3051266655 NaN \n", "... ... ... ... ... \n", "68703 925624214522036200 en 1672876458 NaN \n", "68704 925624218682777600 en 382473866 NaN \n", "68705 925624222889766900 en 893145405457911800 NaN \n", "68706 925624227088121900 en 240378516 NaN \n", "68707 925624273237983200 en 784620573209002000 NaN \n", "68708 925624273212805100 en 170998187 9.254136e+17 \n", "68709 925624298395533300 en 1348667816 NaN \n", "68710 925624298378801200 en 722481645765300200 NaN \n", "68711 925624306779897900 en 2443251500 NaN \n", "68712 925624310974136300 en 2406186390 NaN \n", "68713 925624323557146600 en 1039448149 9.256150e+17 \n", "68714 925624327755591700 en 845085544589672400 9.256009e+17 \n", "68715 925624340342812700 en 924752524871131100 NaN \n", "68716 925624340355280900 en 419493819 NaN \n", "68717 925624340346937300 en 2457745952 9.256219e+17 \n", "68718 925624340338507800 en 1955767531 NaN \n", "68719 925624344524361700 en 796490344581898200 NaN \n", "68720 925624348710285300 en 907808317124177900 NaN \n", "68721 925624352929910800 en 262162415 NaN \n", "68722 925624369715515400 en 574882525 NaN \n", "68723 925624382269124600 en 556175173 9.254038e+17 \n", "68724 925624386455031800 en 1610265588 NaN \n", "68725 925624386454937600 en 4760724450 NaN \n", "68726 925624390657572900 en 882858115636514800 NaN \n", "68727 925624390682849300 en 188129628 NaN \n", "68728 925624390666129400 en 2473135939 NaN \n", "68729 925624390670106600 en 2373584209 9.256241e+17 \n", "68730 925624407459971100 en 181689756 NaN \n", "68731 925624407460057100 en 60160788 9.254610e+17 \n", "68732 925624420022063100 en 3792290725 9.256215e+17 \n", "\n", " text \n", "0 fashionbombdaily's photo 🏼 \n", "1 It’s scary how on point my horoscope be \n", "3 vivalcli: Portraits by Zhao Guojing an... \n", "4 i wanna know too \n", "5 veda was yoda too \n", "6 I’m less stressed about turning 30 now ... \n", "7 Full charged. \n", "8 That’s part of the problem, (they) got me emotional there \n", "11 Happy month to you and your loved ones ... \n", "12 Maxx and Patricia. Family hangs at For Good He... \n", "13 I need to STOP beating myself up with my thoug... \n", "14 Cutest Son Roll no. 31 \n", "15 By the summer I should have everything up and ... \n", "16 I know my English is not that good but that do... \n", "17 I u mama \n", "18 That picture was NOT taken this morning... \n", "19 Welcome to \n", "20 Awkward \n", "21 back at it with supernatural \n", "22 One of the best things I've learned was to sto... \n", "23 Can I taste? \n", "24 we miss you ☹️ \n", "25 Actually my bias in WJSN are Eunseo & Bona... \n", "26 I so cannot be bothered with the rest of the d... \n", "27 2lit4life \n", "28 I’m not stop saying that! \n", "29 HAPPY BIHDAY this one falls under the weird crazy... \n", "68704 I'm not allowed to have chocolates yet, then I... \n", "68705 Manchester United manager Mourinho slams 'spec... \n", "68706 en Bushwhick \n", "68707 : For Taxi Look, Mammeh and Daddeh! ... \n", "68709 Life is so good with you \n", "68710 Happy Halloween! 🏽 \n", "68713 May pre-month celebration sis Awww Ajsksjdjd im smiling like ... \n", "68715 I hate when I send a text or snap n I'm so anx... \n", "68716 The answer is no I have no plans and I never l... \n", "68717 LMAOOO I'm so proud \n", "68718 My cousin/little sister is leaving to San Fran... \n", "68719 Can't be alone w my thoughts tonight so just g... \n", "68720 ambot!!! \n", "68721 🏽🏽 1st of the month!!Happy 1st o... \n", "68722 ... stay in bed \n", "68723 THIS IS GOLD. GOLD. thank you for the kind compliment \n", "68725 Enjoyed the silence \n", "68726 OS: Spiderman Homecoming \n", "68727 Go to hell πŸ½β€β™€οΈ \n", "68728 Thank you Yomi! \n", "68729 Lol. Just enjoy the stars. Music Kidhar... \n", "68730 Thoughts and prayers for NY🏻 \n", "68731 I searched COCK, PENIS, SHLONG, WINKY, ... \n", "68732 Thank you so much<... \n", "\n", "[68733 rows x 9 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "twitter_data = pd.read_json(json_files[0], encoding=\"utf-8\")\n", "twitter_data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* extracting emojis and text" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "emojis = twitter_data['EMOJI']\n", "plain_text = twitter_data['text']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* make our plain text more \"plain\":\n", " * removing the keyword `` (just for the beginning)\n", " * removing remaining useless emojis, like skin modifier etc." ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "# defining blacklist for modifier emojis:\n", "emoji_blacklist = set([\n", " chr(0x1F3FB),\n", " chr(0x1F3FC),\n", " chr(0x1F3FD),\n", " chr(0x1F3FE),\n", " chr(0x1F3FF),\n", " chr(0x2642),\n", " chr(0x2640)\n", "])" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "# filtering them and the EMOJI keyword out:\n", "plain_text = plain_text.str.replace(\"\",\"\").str.replace(\"[\" + \"\".join(list(emoji_blacklist)) + \"]\",\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* defining different criterias for choosing a single emoji (currently `latest` is used)" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "def latest(lst):\n", " return lst[-1] if len(lst) > 0 else 'X' \n", "def most_common(lst):\n", " # trying to find the most common used emoji in the given lst\n", " return max(set(lst), key=lst.count) if len(lst) > 0 else \"X\" # setting label to 'X' if there is an empty emoji list" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* convert all emojis to a sentiment vector" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "labels = emoji2sent([latest(e) for e in emojis])\n" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "68733" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(labels)" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "wrong_labels = np.isnan(np.linalg.norm(labels, axis=1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* remove all data we have no label for" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "labels = labels[np.invert(wrong_labels)]\n", "plain_text = plain_text[np.invert(wrong_labels)]\n", "emojis = emojis[np.invert(wrong_labels)]" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "58308 58308 58308\n" ] } ], "source": [ "print(len(labels), len(emojis), len(plain_text))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* generate weights:" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [], "source": [ "# at first count over our table\n", "emoji_count = {}\n", "\n", "\n", "for e_list in emojis:\n", " for e in set(e_list):\n", " if e not in emoji_count:\n", " emoji_count[e] = 0\n", " emoji_count[e] += 1\n", "\n", "emoji_count\n", "emoji_sum = sum([emoji_count[e] for e in emoji_count])\n", "\n", "emoji_weights = {}\n", "for e in emoji_count:\n", " # tfidf for emojis\n", " emoji_weights[e] = np.log((emoji_sum / emoji_count[e]))\n", "\n", "weights_sum= sum([emoji_weights[x] for x in emoji_weights])\n", " \n", "# normalize:\n", "for e in emoji_weights:\n", " emoji_weights[e] = emoji_weights[e] / weights_sum\n", "\n", "emoji_weights['X'] = 0 # dummy values\n", "emoji_count['X'] = 0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* generating train and test set:" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "X1, Xt1, y1, yt1 = train_test_split(plain_text, labels, test_size=0.1, random_state=4222)" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [], "source": [ "#y1_weights = np.array([(sum([emoji_weights[e] for e in e_list]) / len(e_list)) if len(e_list) > 0 else 0 for e_list in sent2emoji(y1)])" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [], "source": [ "vectorizer = TfidfVectorizer(stop_words='english')\n", "vec_train = vectorizer.fit_transform(X1)\n", "vec_test = vectorizer.transform(Xt1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* train. this can take a very long time..." ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/jonas/.local/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n", " from ._conv import register_converters as _register_converters\n", "Using TensorFlow backend.\n" ] } ], "source": [ "from sklearn.neural_network import MLPClassifier as MLP\n", "from sklearn.multiclass import OneVsRestClassifier as OVRC\n", "from sklearn.tree import DecisionTreeClassifier as DTC\n", "\n", "from keras.models import Sequential\n", "from keras.layers import Dense" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [], "source": [ "def train(max_size = 10000, layers=[(1024, 'relu'),(y1[0].shape[0],'softmax')], random_state=4222, ovrc=False, n_iter=5):\n", " \n", " model = Sequential()\n", " \n", " # build mlp layers:\n", " keras_layers = []\n", " first_layer = True\n", " for layer in layers:\n", " if first_layer:\n", " model.add(Dense(units=layer[0], activation=layer[1], input_dim=vectorizer.transform([\" \"])[0]._shape[1]))\n", " first_layer = False\n", " else:\n", " model.add(Dense(units=layer[0], activation=layer[1]))\n", " \n", " #mlp = MLPClassifier(layers=sknn_layers, random_state=random_state, verbose=True, n_iter=n_iter, batch_size=100)\n", " \n", " model.compile(loss='categorical_crossentropy',\n", " optimizer='sgd',\n", " metrics=['accuracy'])\n", " \n", " clf = OVRC(model) if ovrc else model\n", "\n", " clf.fit(vec_train[:max_size].A, y1[:max_size], validation_split=0.2)#, sample_weight=y1_weights[:max_size])\n", " \n", " return clf" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Train on 8000 samples, validate on 2000 samples\n", "Epoch 1/1\n", "8000/8000 [==============================] - 80s 10ms/step - loss: 1.0421 - acc: 0.7270 - val_loss: 1.0213 - val_acc: 0.7330\n" ] } ], "source": [ "clf = train(max_size=10000,layers=[(1200, 'relu'),(1200,'relu'),(y1[0].shape[0],'softmax')])" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10237 How much do you know about the y...\n", "45851 She said she don't start until Friday \n", "28327 Ryane just told me to not stress because it's ...\n", "22017 Meet Asian & Russian Beauty From Here Fi...\n", "23341 What do u mean \n", "42942 β”Š β”Š βœ²ο½žβ”Š ✲...\n", "28320 Woot woot leafs win \n", "26801 we’re here for you and you know that, y...\n", "66054 gm Mailand have an awesome day \n", "64440 Happy halloween \n", "1695 BARCELONA SPOING CLUB \n", "57848 I will purchase a few things because I love th...\n", "6174 Ah I'll let you off then ! \n", "9295 just the idea of empowering women is so...\n", "48858 Damn!! People late on the thing. This t...\n", "17032 I miss u \n", "30856 I just want to be with you always \n", "56964 when you can’t fall asleep because you just ca...\n", "64594 less than 24hrs until the big 21\n", "14707 were furry trash \n", "54005 At this point, I will break the bank \n", "60411 Thank not me! \n", "59436 when u finally get a new nigga and all yo old ...\n", "1264 I was a Nintendo boy my friend down the...\n", "42327 Rabbit rabbit white rabbit. May everything goe...\n", "39441 rainy morning 🌧\n", "17380 I'm glad it arrived safely!! Thank you ...\n", "51558 Been in this drive through for 15 minutes Sti...\n", "24223 I'm looking into it!!! \n", "31673 Seokjin's just standing there & steal my ...\n", " ... \n", "29591 Lmfao he’s gonna wake up to 17 messages about ...\n", "52608 The seaweed is always greener in somebody else...\n", "22482 I can!\n", "552 This is actually true. I like my rooibos black...\n", "48523 Also the Punjabi in ke is dying ...\n", "61773 Always make me cry always hurting me always ma...\n", "61578 Thank you so much!!! \n", "34541 I am here for this \n", "2485 Yes bambz \n", "35802 Don’t give up just yet.\n", "8504 HAPPY BIHDAY \n", "3403 any dates of south america??? \n", "53606 So nice honey\n", "6234 my boyfriend and my sister are gonna be here f...\n", "5030 Thanks! And definitely\n", "46147 Y'all will roast my ass. Akhant \n", "6445 Click here to watch it: MILF Phoenix Marie ta...\n", "65485 Would have broke it\n", "36002 Okinnam\n", "53927 Thats my crew, I'd fit right in with th...\n", "53701 Lol they saving it for match day \n", "3549 Nooo after tonight we can be friends ag...\n", "9393 Amazing the media trying to politics a terror ...\n", "67371 Got so many compliments on our costumes tonigh...\n", "22173 The Shoes...\n", "26422 Happy Birthday today to Rep. Bruce Antone and ...\n", "41219 Good morning sex \n", "37447 My baby so cute ❀️ \n", "21608 My week on Twitter : 1 Tweet. See yours with \n", "1594 It’s fair to say I ruined my life a few times ...\n", "Name: text, Length: 52477, dtype: object" ] }, "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* make a prediction and store it in a csv file:" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [], "source": [ "pred = clf.predict(vectorizer.transform(Xt1))" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.49225155, 0.22154534, 0.28620324],\n", " [0.4917669 , 0.22080076, 0.28743234],\n", " [0.49208197, 0.22085808, 0.28705996],\n", " ...,\n", " [0.48990184, 0.22155353, 0.28854463],\n", " [0.49245682, 0.22013731, 0.28740585],\n", " [0.4891684 , 0.2214878 , 0.2893438 ]], dtype=float32)" ] }, "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pred" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [], "source": [ "# build a dataframe to visualize test results:\n", "testlist = pd.DataFrame({'text': Xt1, \n", " 'teacher': sent2emoji(yt1),\n", " 'predict': sent2emoji(pred)})" ] }, { "cell_type": "code", "execution_count": 60, "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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
predictteachertext
62474πŸ˜‚πŸ™‹Lovely
11750πŸ˜‚πŸ˜‚β˜ child they told that to slaves and look what...
316πŸ˜‚πŸ˜‚Only in Wisconsin
33553πŸ˜‚πŸ™: Barboursville For Taxi 703-445-4450
1566πŸ˜‚πŸ˜who cares anyway
54842πŸ˜‚πŸ˜­<USER> first it was spratt then faze spratt th...
16711πŸ˜‚πŸ˜šI will forever love the Dodgers! BLEED BLUE t...
52129πŸ˜‚πŸ˜Šok she nailed this ‍️
66914πŸ˜‚πŸ™†time to create the Christmas playlist
42046πŸ˜‚πŸ˜Penultimate <HASHTAG> of the 2017 race season!...
13783πŸ˜‚πŸ˜Šhey friends i need space 2nite. happy 11-1! lo...
4034πŸ˜‚πŸ˜’Sombitch! 3.5 secs left an the goddamn 2K serv...
9773πŸ˜‚πŸ˜sounds great..
27593πŸ˜‚πŸ˜΄what happens after I give babe a massage
22601πŸ˜‚πŸ™<USER> Thank you
64332πŸ˜‚πŸ˜š<USER> I love you I'm so proud of you
23677πŸ˜‚πŸ™‹<USER> <USER> Love how your coffee bags pop up...
1530πŸ˜‚πŸ˜­<USER> I know
38375πŸ˜‚πŸ˜<USER> Xmas songs all the way! I got a new chr...
37403πŸ˜‚πŸ™†54 days until Christmas!!
52706πŸ˜‚πŸ™\"November comesAnd November goes,Β With the las...
9628πŸ˜‚πŸ˜­<USER> You want me dead
41270πŸ˜‚πŸ˜Finally arrived Thank you so much <USER> So ...
56276πŸ˜‚πŸ˜‚Omfg this is amazing
14805πŸ˜‚πŸ˜ŠFinding my <HASHTAG> need it now
1275πŸ˜‚πŸ˜Š<USER> happy birthday
30821πŸ˜‚πŸ˜Œ<USER> better stock up, quenouille season is c...
36974πŸ˜‚πŸ˜‚i always think miguel is saying \"black power\" ...
31270πŸ˜‚πŸ˜š<USER> so proud
21672πŸ˜‚πŸ˜­<USER> snapchat chick ?
............
6464πŸ˜‚πŸ˜‚<USER> <USER> Actually I don’t think that woul...
14439πŸ˜‚πŸ˜›happy birthday to a really great friend, hope ...
30789πŸ˜‚πŸ˜Might fuck around and not turn in my library b...
37129πŸ˜‚πŸ˜€My lil baby sick and it’s making me sad, I den...
61305πŸ˜‚πŸ˜ƒLove our customers...always on the go! ❀️ TRO...
4821πŸ˜‚πŸ™ŒGod bless whoever you marry!
6509πŸ˜‚πŸ˜Έj-u-v-e: On 1 November, Juventus turns 120! H...
41347πŸ˜‚πŸ˜Š<USER> Yeah, sunshine, I promise I love you a...
15368πŸ˜‚πŸ™ŒYou ain't ever made love, You just wanted some...
22594πŸ˜‚πŸ˜‚This whole lingerie thing is funny sha
61471πŸ˜‚πŸ˜š<USER> Wooo congrats buddy!
63724πŸ˜‚πŸ˜‰Early mornings
7399πŸ˜‚πŸ˜­<USER> <USER> So Sad
8262πŸ˜‚πŸ˜€But opening up means trusting others.And that'...
61430πŸ˜‚πŸ˜šbambam pink hair❀️
59747πŸ˜‚πŸ˜‚Nah last nights game was well worth my months ...
47655πŸ˜‚πŸ˜š<USER> wish your many more happy returns of th...
30992πŸ˜‚πŸ˜Άmy heart breaks into a million pieces every mo...
2204πŸ˜‚πŸ™Call Congress (202) 224-3121 <HASHTAG> <HASHTA...
41224πŸ˜‚πŸ˜‚I love Lucas’s sister! ❀️ Erica is so funny!
65180πŸ˜‚πŸ˜<USER> PULL THRU JELLYBEAN
48319πŸ˜‚πŸ˜­i miss the snickerdoodle swirl from <USER> so ...
19825πŸ˜‚πŸ˜‹I love you- and I really do.
63387πŸ˜‚πŸ˜ΉLove huvin Mason, can steal aw his Halloween s...
33798πŸ˜‚πŸ˜80/0 at the end of 10 overs - Shikhar Dhawan ...
63144πŸ˜‚πŸ™‹Stoping for a few in between 12 hr shifts is p...
5185πŸ˜‚πŸ˜When a band member of Volumes actually adds yo...
65919πŸ˜‚πŸ˜Ά<USER> <USER> Evil sick humans what a world we...
27834πŸ˜‚πŸ˜‚<USER> I always thought it was <USER>
57241πŸ˜‚πŸ˜‚<USER> <USER> I thought u meant the show neve...
\n", "

5831 rows Γ— 3 columns

\n", "
" ], "text/plain": [ " predict teacher text\n", "62474 πŸ˜‚ πŸ™‹ Lovely \n", "11750 πŸ˜‚ πŸ˜‚ ☝ child they told that to slaves and look what...\n", "316 πŸ˜‚ πŸ˜‚ Only in Wisconsin \n", "33553 πŸ˜‚ πŸ™ : Barboursville For Taxi 703-445-4450 \n", "1566 πŸ˜‚ 😏 who cares anyway \n", "54842 πŸ˜‚ 😭 first it was spratt then faze spratt th...\n", "16711 πŸ˜‚ 😚 I will forever love the Dodgers! BLEED BLUE t...\n", "52129 πŸ˜‚ 😊 ok she nailed this ‍️ \n", "66914 πŸ˜‚ πŸ™† time to create the Christmas playlist \n", "42046 πŸ˜‚ 😍 Penultimate of the 2017 race season!...\n", "13783 πŸ˜‚ 😊 hey friends i need space 2nite. happy 11-1! lo...\n", "4034 πŸ˜‚ πŸ˜’ Sombitch! 3.5 secs left an the goddamn 2K serv...\n", "9773 πŸ˜‚ 😏 sounds great.. \n", "27593 πŸ˜‚ 😴 what happens after I give babe a massage \n", "22601 πŸ˜‚ πŸ™ Thank you \n", "64332 πŸ˜‚ 😚 I love you I'm so proud of you \n", "23677 πŸ˜‚ πŸ™‹ Love how your coffee bags pop up...\n", "1530 πŸ˜‚ 😭 I know \n", "38375 πŸ˜‚ 😏 Xmas songs all the way! I got a new chr...\n", "37403 πŸ˜‚ πŸ™† 54 days until Christmas!! \n", "52706 πŸ˜‚ πŸ™ \"November comesAnd November goes,Β With the las...\n", "9628 πŸ˜‚ 😭 You want me dead \n", "41270 πŸ˜‚ 😍 Finally arrived Thank you so much So ...\n", "56276 πŸ˜‚ πŸ˜‚ Omfg this is amazing \n", "14805 πŸ˜‚ 😊 Finding my need it now \n", "1275 πŸ˜‚ 😊 happy birthday\n", "30821 πŸ˜‚ 😌 better stock up, quenouille season is c...\n", "36974 πŸ˜‚ πŸ˜‚ i always think miguel is saying \"black power\" ...\n", "31270 πŸ˜‚ 😚 so proud \n", "21672 πŸ˜‚ 😭 snapchat chick ? \n", "... ... ... ...\n", "6464 πŸ˜‚ πŸ˜‚ Actually I don’t think that woul...\n", "14439 πŸ˜‚ πŸ˜› happy birthday to a really great friend, hope ...\n", "30789 πŸ˜‚ 😏 Might fuck around and not turn in my library b...\n", "37129 πŸ˜‚ πŸ˜€ My lil baby sick and it’s making me sad, I den...\n", "61305 πŸ˜‚ πŸ˜ƒ Love our customers...always on the go! ❀️ TRO...\n", "4821 πŸ˜‚ πŸ™Œ God bless whoever you marry! \n", "6509 πŸ˜‚ 😸 j-u-v-e: On 1 November, Juventus turns 120! H...\n", "41347 πŸ˜‚ 😊 Yeah, sunshine, I promise I love you a...\n", "15368 πŸ˜‚ πŸ™Œ You ain't ever made love, You just wanted some...\n", "22594 πŸ˜‚ πŸ˜‚ This whole lingerie thing is funny sha \n", "61471 πŸ˜‚ 😚 Wooo congrats buddy!\n", "63724 πŸ˜‚ πŸ˜‰ Early mornings \n", "7399 πŸ˜‚ 😭 So Sad \n", "8262 πŸ˜‚ πŸ˜€ But opening up means trusting others.And that'...\n", "61430 πŸ˜‚ 😚 bambam pink hair❀️\n", "59747 πŸ˜‚ πŸ˜‚ Nah last nights game was well worth my months ...\n", "47655 πŸ˜‚ 😚 wish your many more happy returns of th...\n", "30992 πŸ˜‚ 😢 my heart breaks into a million pieces every mo...\n", "2204 πŸ˜‚ πŸ™ Call Congress (202) 224-3121 PULL THRU JELLYBEAN \n", "48319 πŸ˜‚ 😭 i miss the snickerdoodle swirl from so ...\n", "19825 πŸ˜‚ πŸ˜‹ I love you- and I really do. \n", "63387 πŸ˜‚ 😹 Love huvin Mason, can steal aw his Halloween s...\n", "33798 πŸ˜‚ 😏 80/0 at the end of 10 overs - Shikhar Dhawan ...\n", "63144 πŸ˜‚ πŸ™‹ Stoping for a few in between 12 hr shifts is p...\n", "5185 πŸ˜‚ 😏 When a band member of Volumes actually adds yo...\n", "65919 πŸ˜‚ 😢 Evil sick humans what a world we...\n", "27834 πŸ˜‚ πŸ˜‚ I always thought it was \n", "57241 πŸ˜‚ πŸ˜‚ I thought u meant the show neve...\n", "\n", "[5831 rows x 3 columns]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "display(testlist)\n" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "testlist.to_csv('test.csv')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* a simple output widget for testing:" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "865c37ebeb2443a589ccbaf220456457", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type Text.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "Text(value='')" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d34382a5e13c4be396303afc6b138c2a", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type VBox.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "VBox(children=(Button(description='get smiley', icon='check', style=ButtonStyle(), tooltip='Click me'), Output()))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "out = widgets.Output()\n", "\n", "t = widgets.Text()\n", "b = widgets.Button(\n", " description='get smiley',\n", " disabled=False,\n", " button_style='', # 'success', 'info', 'warning', 'danger' or ''\n", " tooltip='Click me',\n", " icon='check'\n", ")\n", "\n", "\n", "\n", "def handle_submit(sender):\n", " with out:\n", " clear_output()\n", " with out:\n", " pred = clf.predict(vectorizer.transform([t.value]))\n", " \n", " display(Markdown(\"# \" + str(sent2emoji(pred))))\n", "\n", "b.on_click(handle_submit)\n", " \n", "display(t)\n", "display(widgets.VBox([b, out])) " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "y_trans = mlb.inverse_transform(yt1)\n", "pred_trans = mlb.inverse_transform(yt1)\n", "\n", "# evaluate accuracy\n", "pos = 0\n", "neg = 0\n", "all = 0\n", "for entry in range(len(y_trans)):\n", " if len(np.intersect1d(y_trans[entry], pred_trans[entry])) > 0:\n", " pos += 1\n", " else:\n", " neg += 1\n", " all += 1\n", "print(pos/all)\n", "print(neg)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 2 }