{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Copy of Test_LSTM.ipynb","provenance":[{"file_id":"1EhAX__UgmFiWOA22jCFKMW8rCFu_M8D9","timestamp":1660402644434}],"collapsed_sections":[],"machine_shape":"hm"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"},"gpuClass":"standard","accelerator":"GPU"},"cells":[{"cell_type":"markdown","source":["# Load model"],"metadata":{"id":"fvFoKnCQMUsl"}},{"cell_type":"code","execution_count":1,"metadata":{"id":"ao81MHnPg2n5","executionInfo":{"status":"ok","timestamp":1660402906690,"user_tz":-420,"elapsed":1495,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"outputs":[],"source":["import numpy as np # linear algebra\n","import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n","\n","from tensorflow import keras\n","from sklearn.feature_extraction.text import CountVectorizer\n","from keras.preprocessing.text import Tokenizer\n","from keras.preprocessing.sequence import pad_sequences\n","from keras.models import Sequential\n","from keras.layers import Dense, Embedding, LSTM, SpatialDropout1D\n","from sklearn.model_selection import train_test_split\n","from keras.utils.np_utils import to_categorical\n","import re"]},{"cell_type":"markdown","source":["Kết nối xuống driver"],"metadata":{"id":"q0YOUrI32PH4"}},{"cell_type":"code","source":["#Connect to gg drive\n","from google.colab import drive\n","drive.mount('/content/drive')\n","try:\n"," import os\n"," os.chdir(\"drive/My Drive/Colab Notebooks/lstm_32_epoch/saved_data\")\n","except:\n"," print('Already mount')"],"metadata":{"id":"ofD48Vn22KLZ","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1660403130558,"user_tz":-420,"elapsed":25028,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}},"outputId":"cef968cd-a1c9-4b6b-dfa9-5ad90fc9a372"},"execution_count":2,"outputs":[{"output_type":"stream","name":"stdout","text":["Mounted at /content/drive\n"]}]},{"cell_type":"markdown","source":["Đọc và tiền xử lý dữ liệu"],"metadata":{"id":"AgWOZBhO4681"}},{"cell_type":"code","source":["from numpy import loadtxt\n"],"metadata":{"id":"85Zv3qZw2vTC","executionInfo":{"status":"ok","timestamp":1660403146906,"user_tz":-420,"elapsed":2,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"execution_count":3,"outputs":[]},{"cell_type":"code","source":["\n","#Load dataset\n","X_train = loadtxt('X_train.csv', delimiter=',')\n","Y_train = loadtxt('Y_train.csv', delimiter=',')\n","X_test = loadtxt('X_test.csv', delimiter=',')\n","Y_test = loadtxt('Y_test.csv', delimiter=',')\n","\n","# Load token\n","import pickle\n","\n","with open('tokenizer.pickle', 'rb') as handle:\n"," tokenizer = pickle.load(handle)\n"],"metadata":{"id":"dX0E9qHND57r","executionInfo":{"status":"ok","timestamp":1660403245187,"user_tz":-420,"elapsed":90799,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"execution_count":4,"outputs":[]},{"cell_type":"code","source":["with open('MAX_LEN.txt', 'r') as f:\n"," MAX_LEN = int(f.read())"],"metadata":{"id":"QifjowDM2SWr","executionInfo":{"status":"ok","timestamp":1660403252343,"user_tz":-420,"elapsed":1848,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"execution_count":5,"outputs":[]},{"cell_type":"code","source":["MAX_LEN"],"metadata":{"id":"ck_6fnhC2U6J","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1660403254932,"user_tz":-420,"elapsed":6,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}},"outputId":"a8e4181c-f27f-42aa-bfef-022862430d3a"},"execution_count":6,"outputs":[{"output_type":"execute_result","data":{"text/plain":["1632"]},"metadata":{},"execution_count":6}]},{"cell_type":"markdown","source":["Load model keras và thực hiện validation"],"metadata":{"id":"N5eHxx1J5BUX"}},{"cell_type":"code","source":["model = keras.models.load_model('LSTM_Model.h5')"],"metadata":{"id":"O0vrpCYaqZQF","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1660403270852,"user_tz":-420,"elapsed":8306,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}},"outputId":"316ed955-cec9-415d-e586-39d9d67b3a11"},"execution_count":7,"outputs":[{"output_type":"stream","name":"stderr","text":["WARNING:tensorflow:Layer lstm will not use cuDNN kernels since it doesn't meet the criteria. It will use a generic GPU kernel as fallback when running on GPU.\n"]}]},{"cell_type":"code","source":["\n","batch_size = 32\n","\n","validation_size = 1500\n","\n","X_validate = X_test[-validation_size:]\n","Y_validate = Y_test[-validation_size:]\n","X_test = X_test[:-validation_size]\n","Y_test = Y_test[:-validation_size]\n","score,acc = model.evaluate(X_test, Y_test, verbose = 2, batch_size = batch_size)\n","print(\"score: %.2f\" % (score))\n","print(\"acc: %.2f\" % (acc))"],"metadata":{"id":"RExQAe6xhAkg","executionInfo":{"status":"ok","timestamp":1659835472660,"user_tz":-420,"elapsed":158836,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}},"colab":{"base_uri":"https://localhost:8080/"},"outputId":"87501704-76fb-4579-981a-4b560001407c"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["469/469 - 158s - loss: 0.4973 - accuracy: 0.7961 - 158s/epoch - 338ms/step\n","score: 0.50\n","acc: 0.80\n"]}]},{"cell_type":"markdown","source":["Thử test với đoạn văn bản"],"metadata":{"id":"DRhMTdda5H6J"}},{"cell_type":"markdown","source":["# Hàm tiền xử lý"],"metadata":{"id":"UztG6PrQLk5o"}},{"cell_type":"code","execution_count":8,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"xj6Q69YB_cEq","outputId":"974681de-2c6b-41c4-edda-dda808e8048e","pycharm":{"name":"#%%\n"},"executionInfo":{"status":"ok","timestamp":1660403310310,"user_tz":-420,"elapsed":23224,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Collecting contractions\n"," Downloading contractions-0.1.72-py2.py3-none-any.whl (8.3 kB)\n","Collecting textsearch>=0.0.21\n"," Downloading textsearch-0.0.21-py2.py3-none-any.whl (7.5 kB)\n","Collecting anyascii\n"," Downloading anyascii-0.3.1-py3-none-any.whl (287 kB)\n","\u001b[K |████████████████████████████████| 287 kB 40.9 MB/s \n","\u001b[?25hCollecting pyahocorasick\n"," Downloading pyahocorasick-1.4.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (106 kB)\n","\u001b[K |████████████████████████████████| 106 kB 98.1 MB/s \n","\u001b[?25hInstalling collected packages: pyahocorasick, anyascii, textsearch, contractions\n","Successfully installed anyascii-0.3.1 contractions-0.1.72 pyahocorasick-1.4.4 textsearch-0.0.21\n","Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Collecting autocorrect\n"," Downloading autocorrect-2.6.1.tar.gz (622 kB)\n","\u001b[K |████████████████████████████████| 622 kB 35.6 MB/s \n","\u001b[?25hBuilding wheels for collected packages: autocorrect\n"," Building wheel for autocorrect (setup.py) ... \u001b[?25l\u001b[?25hdone\n"," Created wheel for autocorrect: filename=autocorrect-2.6.1-py3-none-any.whl size=622382 sha256=b2df044a13599de7f4eb047268be4900ff95d331468cc3d4e80721859b12b546\n"," Stored in directory: /root/.cache/pip/wheels/54/d4/37/8244101ad50b0f7d9bffd93ce58ed7991ee1753b290923934b\n","Successfully built autocorrect\n","Installing collected packages: autocorrect\n","Successfully installed autocorrect-2.6.1\n","Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (4.64.0)\n","Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Collecting emoticon-fix\n"," Downloading emoticon_fix-0.0.2.tar.gz (3.1 kB)\n","Building wheels for collected packages: emoticon-fix\n"," Building wheel for emoticon-fix (setup.py) ... \u001b[?25l\u001b[?25hdone\n"," Created wheel for emoticon-fix: filename=emoticon_fix-0.0.2-py3-none-any.whl size=3448 sha256=0508c2a20b9940c37de363e547385fae32cb09da0b34e50c98a0d8491761f8d9\n"," Stored in directory: /root/.cache/pip/wheels/2b/79/84/60b67bbd172bbaf6ad27e97e3b3c6acbdd2d6d4d796809298a\n","Successfully built emoticon-fix\n","Installing collected packages: emoticon-fix\n","Successfully installed emoticon-fix-0.0.2\n","Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Collecting emoji\n"," Downloading emoji-2.0.0.tar.gz (197 kB)\n","\u001b[K |████████████████████████████████| 197 kB 36.1 MB/s \n","\u001b[?25hBuilding wheels for collected packages: emoji\n"," Building wheel for emoji (setup.py) ... \u001b[?25l\u001b[?25hdone\n"," Created wheel for emoji: filename=emoji-2.0.0-py3-none-any.whl size=193022 sha256=dd8e470bf4c60ce289dd23e7bf67cc7c782893a6941cfad2f60c47180ce3eb71\n"," Stored in directory: /root/.cache/pip/wheels/ec/29/4d/3cfe7452ac7d8d83b1930f8a6205c3c9649b24e80f9029fc38\n","Successfully built emoji\n","Installing collected packages: emoji\n","Successfully installed emoji-2.0.0\n"]}],"source":["#download contractions: \n","!pip install contractions\n","# !pip install pyspellchecker\n","!pip install autocorrect\n","!pip install tqdm\n","!pip install emoticon-fix\n","!pip install emoji"]},{"cell_type":"code","execution_count":9,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"74-sBZoY5Byt","outputId":"b5358e40-1e29-4259-a651-598245177c74","pycharm":{"name":"#%%\n"},"executionInfo":{"status":"ok","timestamp":1660403312535,"user_tz":-420,"elapsed":2230,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"outputs":[{"output_type":"stream","name":"stderr","text":["[nltk_data] Downloading package punkt to /root/nltk_data...\n","[nltk_data] Unzipping tokenizers/punkt.zip.\n","[nltk_data] Downloading package omw-1.4 to /root/nltk_data...\n","[nltk_data] Downloading package wordnet to /root/nltk_data...\n","[nltk_data] Downloading package stopwords to /root/nltk_data...\n","[nltk_data] Unzipping corpora/stopwords.zip.\n","[nltk_data] Downloading package averaged_perceptron_tagger to\n","[nltk_data] /root/nltk_data...\n","[nltk_data] Unzipping taggers/averaged_perceptron_tagger.zip.\n"]}],"source":["# Import Module\n","import os\n","import re\n","import pandas as pd\n","\n","import contractions\n","import nltk\n","import numpy as np\n","from bs4 import BeautifulSoup\n","from nltk.corpus import stopwords\n","from nltk.stem import LancasterStemmer, WordNetLemmatizer\n","# Lemmatize with POS Tag\n","from nltk.corpus import wordnet\n","from nltk.tokenize import word_tokenize\n","# spellchecker\n","# from spellchecker import SpellChecker\n","from autocorrect import Speller\n","from tqdm import tqdm\n","from collections import Counter\n","\n","import emoji\n","from emoticon_fix import emoticon_fix\n","\n","\n","nltk.download('punkt')\n","nltk.download('omw-1.4')\n","nltk.download('wordnet')\n","nltk.download('stopwords')\n","nltk.download('averaged_perceptron_tagger')\n","\n","tqdm.pandas()"]},{"cell_type":"code","execution_count":10,"metadata":{"id":"-uTJJ9dI5IHW","pycharm":{"name":"#%%\n"},"executionInfo":{"status":"ok","timestamp":1660403312536,"user_tz":-420,"elapsed":5,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"outputs":[],"source":["#remove all web associated\n","# to remove HTML tag\n","def html_remover(text):\n"," beauti = BeautifulSoup(text, 'html.parser')\n"," return beauti.get_text()\n","\n","\n","def web_associated(text):\n"," text = str(text)\n"," text = html_remover(text)\n"," text = re.sub(r'(www\\S+ ?)|(\\w+\\.com)|(http\\S+)', '', text)\n"," return text"]},{"cell_type":"code","source":["def remove_noise(text):\n"," return re.sub(r'(\\'s|s\\'|’s|s’|\\(|\\)|\\[|\\]|\\{|\\\"|\\'|\\“|\\’|\\”|\\‘|(\\'.*))|\\`|\\—', '', text)"],"metadata":{"id":"01hf0-lPTGZA","executionInfo":{"status":"ok","timestamp":1660403312536,"user_tz":-420,"elapsed":4,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"execution_count":11,"outputs":[]},{"cell_type":"code","execution_count":12,"metadata":{"id":"tYKfiwNag50r","pycharm":{"name":"#%%\n"},"executionInfo":{"status":"ok","timestamp":1660403313098,"user_tz":-420,"elapsed":566,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"outputs":[],"source":["#Noise preprocessing\n","#remove all noise\n","# def remove_round_brackets(data):\n","# return re.sub('\\(.*?\\)', '', data)\n","\n","# def contraction_replace(data):\n","# return contractions.fix(data)\n","\n","# def convert_emoticons(text):\n","# for emot in EMOTICONS_EMO:\n","# text = re.sub(u'(' + emot + ')',\" \"+ \"_\".join(EMOTICONS_EMO[emot].replace(\",\", \"\").split())+\" \", text)\n","# return text\n","\n","# def convert_emojis(text):\n","# for emot in UNICODE_EMO:\n","# text = re.sub(r'(' + emot + ')',\" \"+ \"_\".join(UNICODE_EMO[emot].replace(\",\", \"\").replace(\":\",\"\").split())+\" \", text)\n","# return text\n","\n","# def standardize_words(data):\n","# return re.sub(r'(.)\\1+', r'\\1\\1', data)\n","# spell = SpellChecker(language='en')\n","\n","\n","# def correct_spellings(text): \n","# tokens = text.split()\n","# misspelled_words = spell.unknown(tokens)\n","# corrected_text = []\n","# for word in tokens:\n","# if word in misspelled_words:\n","# corrected_text.append(spell.correction(word))\n","# else:\n","# corrected_text.append(word)\n","# return ' '.join(corrected_text)\n","spell = Speller(fast=True)\n","def noise_preprocessing(text):\n"," text = contractions.fix(text)\n"," text = remove_noise(text)\n"," text = emoticon_fix.emoticon_fix(text)\n"," text = emoji.demojize(text).replace(\"_\",\" \").replace(':',' ')\n"," text = re.sub(r'(.)\\1+', r'\\1\\1', text)\n"," # text = correct_spellings(text)\n"," text = spell(text)\n"," text = text.lower()\n"," return text\n"]},{"cell_type":"code","execution_count":13,"metadata":{"id":"K0wy5yN_2ibL","pycharm":{"name":"#%%\n"},"executionInfo":{"status":"ok","timestamp":1660403313098,"user_tz":-420,"elapsed":7,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"outputs":[],"source":["punctuations = [token for token in '?!.,\"#$%\\'()*+-/:;<=>@[\\\\]^_`{|}~“”’‘&']\n","punctuations.extend(['...','``','--','—','——','•','«','……','––','—-','°','¬','·','▪','–-','—','−','―','›','-','..','»','+','*','‹','♦','₪','%N%','%$%','%^%','「','」','『','』','〈','〉','》','《','¿'])\n","\n","def tokenize_doc(text):\n"," return word_tokenize(text)\n","\n","def remove_punc(tokens):\n"," return [token for token in tokens if token not in punctuations and token.isascii()]\n","\n","def remove_one_character(tokens):\n"," return [token for token in tokens if len(token)>1]\n"]},{"cell_type":"code","execution_count":14,"metadata":{"id":"FNiEgNVA_Fkq","pycharm":{"name":"#%%\n"},"executionInfo":{"status":"ok","timestamp":1660403313098,"user_tz":-420,"elapsed":7,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"outputs":[],"source":["stop_words = stopwords.words('english')\n","# get all negative words from stopwords\n","negative_words = []\n","for word in stop_words:\n"," if word.endswith(\"n't\"):\n"," negative_words.append(word)\n"," negative_words.append(word[:-2])\n","negative_words.extend([\"not\",'ain','no','nor'])\n","\n","\n","# remove all negative words from stopwords\n","stop_words = [word for word in stop_words if word not in negative_words]\n","model_words = ['can','could','may','might','will','would','must','shall','should','have','has','had','maybe']\n","#filter word pauses\n","# 'okay','hi',\n","filter_word_pauses = ['um','uhm','um-hum','uh','yeah','uh-huh','oh','huh','uh-huh']\n","stop_words.extend(filter_word_pauses)\n","stop_words.extend(model_words)\n","\n","\n","stop_words_dict = Counter(stop_words)\n","\n","#clean stopwords\n","def stopword(tokens):\n"," return [token for token in tokens if token not in stop_words_dict]\n"," "]},{"cell_type":"code","execution_count":15,"metadata":{"id":"AgMjhjIi5ylC","pycharm":{"name":"#%%\n"},"executionInfo":{"status":"ok","timestamp":1660403313099,"user_tz":-420,"elapsed":7,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"outputs":[],"source":["#lemmatize doc\n","def get_wordnet_pos(word):\n"," \"\"\"Map POS tag to first character lemmatize() accepts\"\"\"\n"," tag = nltk.pos_tag([word])[0][1][0].upper()\n"," tag_dict = {\"J\": wordnet.ADJ,\n"," \"N\": wordnet.NOUN,\n"," \"V\": wordnet.VERB,\n"," \"R\": wordnet.ADV}\n","\n"," return tag_dict.get(tag, wordnet.NOUN)\n","\n","\n","def lemmatization(tokens):\n"," lemma = WordNetLemmatizer()\n"," lemmas = []\n"," for i in tokens:\n"," lem = lemma.lemmatize(i, pos=get_wordnet_pos(i))\n"," lemmas.append(lem)\n"," return lemmas\n","\n","\n","def normalization_preprocessing(data):\n"," tokens = tokenize_doc(data)\n"," tokens = remove_punc(tokens)\n"," tokens = remove_one_character(tokens)\n"," tokens = stopword(tokens)\n"," # tokens = lemmatization(tokens)\n"," return tokens"]},{"cell_type":"code","execution_count":16,"metadata":{"id":"B-XYLalo535L","pycharm":{"name":"#%%\n"},"executionInfo":{"status":"ok","timestamp":1660403314242,"user_tz":-420,"elapsed":2,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"outputs":[],"source":["def preprocessing_doc(doc):\n"," doc = web_associated(doc) \n"," doc = noise_preprocessing(doc) \n"," tokens = normalization_preprocessing(doc)\n"," return tokens"]},{"cell_type":"code","source":["def concate_text(tokens):\n"," return \" \".join(tokens)"],"metadata":{"id":"sk0p99WoZbUW","executionInfo":{"status":"ok","timestamp":1660403316700,"user_tz":-420,"elapsed":3,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"execution_count":17,"outputs":[]},{"cell_type":"markdown","source":["# Hàm dự đoán"],"metadata":{"id":"OqO8_L-FLx1P"}},{"cell_type":"code","source":["def predict(text):\n"," twt = np.array([concate_text(preprocessing_doc(text))])\n"," # print(\"preprocessing text: \" + str(twt[0]))\n"," #vectorizing the tweet by the pre-fitted tokenizer instance\n"," twt = tokenizer.texts_to_sequences(twt)\n"," #padding the tweet to have exactly the same shape as `embedding_2` input\n"," twt = pad_sequences(twt, maxlen=MAX_LEN, dtype='int32', value=0)\n"," \n"," sentiment = model.predict(twt,batch_size=1,verbose = 2)[0]\n"," predicted_class = np.argmax(sentiment)\n"," # if(np.argmax(sentiment) == 0):\n"," # print(\"negative\")\n"," # elif (np.argmax(sentiment) == 1):\n"," # print(\"neutral\")\n"," # elif(np.argmax(sentiment) == 2):\n"," # print(\"positive\")\n"," # return np.argmax(sentiment)\n"," total = sentiment[0]+sentiment[1]+sentiment[2]\n"," percents = [sentiment[0]*100/total, sentiment[1]*100/total, sentiment[2]*100/total]\n"," return percents"],"metadata":{"id":"qjRpRIbNnvns","executionInfo":{"status":"ok","timestamp":1660408287012,"user_tz":-420,"elapsed":2,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}}},"execution_count":55,"outputs":[]},{"cell_type":"code","source":["predict(\"\"\" \n","Camera error notice keeps coming up. No fix. Can't switch lens or take pics quicky. Unable to take pics at my 40 year reunion weekend. Visited SAMSUNG store-they claimed they have never seen this issue, so I did a Google search with them to show the long list of similar complaints with no fix. IT sucks to borrow an iPhone to take a basic picture. FIX or REPLACE\n","\"\"\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"rbebzDTv9-jS","executionInfo":{"status":"ok","timestamp":1660408290518,"user_tz":-420,"elapsed":525,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}},"outputId":"217cf4ab-32a7-4291-adfb-9f48e0d810b3"},"execution_count":56,"outputs":[{"output_type":"stream","name":"stdout","text":["1/1 - 0s - 399ms/epoch - 399ms/step\n"]},{"output_type":"execute_result","data":{"text/plain":["[51.168864826099295, 48.11221681687631, 0.718910161386709]"]},"metadata":{},"execution_count":56}]},{"cell_type":"markdown","source":["# Dự đoán"],"metadata":{"id":"qzKpL57yMNwi"}},{"cell_type":"code","source":["print(preprocessing_doc('TEMPORARY MACHINE OK. GENERAL IS EASY TO USE. STILL DURABLE OR NOT SATISFACTION TIME WILL KNOW. THE OTHER TEAM OF TGDD IS CUTE, ENJOYED'.lower()))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"C-sYupIUPcLj","executionInfo":{"status":"ok","timestamp":1660404625955,"user_tz":-420,"elapsed":558,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}},"outputId":"65d48f71-2342-46c7-97be-0e891973c371"},"execution_count":34,"outputs":[{"output_type":"stream","name":"stdout","text":["['temporary', 'machine', 'ok', 'general', 'easy', 'use', 'still', 'durable', 'not', 'satisfaction', 'time', 'know', 'team', 'todd', 'cute', 'enjoyed']\n"]}]},{"cell_type":"code","source":["predict(\"\"\"I really like the Galaxy A12, It is robust, easy to use and fast, and yes this one comes unlocked. The dual sim card/external memory tray is a breeze to set up. Just be careful not to reinstall it upside down. That won't damage the phone, but the phone cannot recognize the sim card that way. Battery life is excellent, and with the included USB-C high-speed charger, it recharges very quickly. The screen is beautiful, easy to read and very fast. The Samsung Smart Switch function makes moving data and apps over from another phone a breeze. I highly recommend adding one of the many cases that are made for the A12. I got the inexpensive but highly regarded Galaxy A12 case from \"Cell Phone Basic Cases by V/A\". Their case with green edges makes the phone extremel easy to find if you place it down on a dark surface.\n","\n","\n","\"\"\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"UrAytadnMPNO","executionInfo":{"status":"ok","timestamp":1660407948080,"user_tz":-420,"elapsed":553,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}},"outputId":"e0f504e2-a97a-4a2f-9c76-4ad349df572a"},"execution_count":49,"outputs":[{"output_type":"stream","name":"stdout","text":["1/1 - 0s - 397ms/epoch - 397ms/step\n"]},{"output_type":"execute_result","data":{"text/plain":["([0.0016443942513433285, 0.37329636979848146, 99.6250569820404], 2)"]},"metadata":{},"execution_count":49}]},{"cell_type":"code","source":["df_comment = pd.read_csv('amazon_comment2.csv',encoding='utf8')\n","df_comment"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":424},"id":"JO-lHue2mZAq","executionInfo":{"status":"ok","timestamp":1660404636039,"user_tz":-420,"elapsed":608,"user":{"displayName":"Quang Tiến Trịnh","userId":"11735285263347952329"}},"outputId":"24393444-e89a-4c8f-e582-d4e6f52ca448"},"execution_count":36,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" name Rating Comment \\\n","0 Cong Dien 5.0 For those not expecting a Galaxy S22, this pho... \n","1 Cong Dien 5.0 For those not expecting a Galaxy S22, this pho... \n","2 Le Dien 5.0 I'm an old guy that never wanted or needed a c... \n","3 Cong Dien 3.0 I researched before I purchased, having found ... \n","4 Le Dien 5.0 I really like the Galaxy A12, It is robust, ea... \n","... ... ... ... \n","1550 Trinh Tien 1.0 Extremely disappointed with the color. It's so... \n","1551 Le Dien 1.0 Feels okay but i'm really unhappy with the che... \n","1552 Cong Dien 1.0 The hard plastic shell cracked after 3 months ... \n","1553 Quang Tien 1.0 Does not fit! After an extremely lengthy delay... \n","1554 Le Dien 1.0 I like the look but first drop on the corner a... \n","\n"," product_id user_id id \n","0 35 2 1 \n","1 237 2 2 \n","2 95 4 3 \n","3 28 2 4 \n","4 58 4 5 \n","... ... ... ... \n","1550 6 1 1551 \n","1551 72 4 1552 \n","1552 158 2 1553 \n","1553 205 3 1554 \n","1554 29 4 1555 \n","\n","[1555 rows x 6 columns]"],"text/html":["\n","
| \n"," | name | \n","Rating | \n","Comment | \n","product_id | \n","user_id | \n","id | \n","
|---|---|---|---|---|---|---|
| 0 | \n","Cong Dien | \n","5.0 | \n","For those not expecting a Galaxy S22, this pho... | \n","35 | \n","2 | \n","1 | \n","
| 1 | \n","Cong Dien | \n","5.0 | \n","For those not expecting a Galaxy S22, this pho... | \n","237 | \n","2 | \n","2 | \n","
| 2 | \n","Le Dien | \n","5.0 | \n","I'm an old guy that never wanted or needed a c... | \n","95 | \n","4 | \n","3 | \n","
| 3 | \n","Cong Dien | \n","3.0 | \n","I researched before I purchased, having found ... | \n","28 | \n","2 | \n","4 | \n","
| 4 | \n","Le Dien | \n","5.0 | \n","I really like the Galaxy A12, It is robust, ea... | \n","58 | \n","4 | \n","5 | \n","
| ... | \n","... | \n","... | \n","... | \n","... | \n","... | \n","... | \n","
| 1550 | \n","Trinh Tien | \n","1.0 | \n","Extremely disappointed with the color. It's so... | \n","6 | \n","1 | \n","1551 | \n","
| 1551 | \n","Le Dien | \n","1.0 | \n","Feels okay but i'm really unhappy with the che... | \n","72 | \n","4 | \n","1552 | \n","
| 1552 | \n","Cong Dien | \n","1.0 | \n","The hard plastic shell cracked after 3 months ... | \n","158 | \n","2 | \n","1553 | \n","
| 1553 | \n","Quang Tien | \n","1.0 | \n","Does not fit! After an extremely lengthy delay... | \n","205 | \n","3 | \n","1554 | \n","
| 1554 | \n","Le Dien | \n","1.0 | \n","I like the look but first drop on the corner a... | \n","29 | \n","4 | \n","1555 | \n","
1555 rows × 6 columns
\n","