{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-01-08T15:03:22.760166Z","iopub.execute_input":"2022-01-08T15:03:22.760953Z","iopub.status.idle":"2022-01-08T15:03:22.792944Z","shell.execute_reply.started":"2022-01-08T15:03:22.760833Z","shell.execute_reply":"2022-01-08T15:03:22.791948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('../input/quora-insincere-questions-classification/train.csv')\ntest_df = pd.read_csv('../input/quora-insincere-questions-classification/test.csv')\n\ntrain_X = train_df['question_text']\ntest_X = test_df['question_text']\n","metadata":{"execution":{"iopub.status.busy":"2022-01-08T15:03:22.794838Z","iopub.execute_input":"2022-01-08T15:03:22.795434Z","iopub.status.idle":"2022-01-08T15:03:29.074766Z","shell.execute_reply.started":"2022-01-08T15:03:22.795390Z","shell.execute_reply":"2022-01-08T15:03:29.074050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.preprocessing.text import Tokenizer\n\n\ntokenizer = Tokenizer(num_words = 150000)\n\n#tokenizer từ trong tập train và tập huấn luyện\ntokenizer.fit_on_texts(list(train_X)+list(test_X))\n\n# tạo một dict để mapping từ và số thứ tự\nword_index = tokenizer.word_index # type: dict\nlist_word = list(word_index.keys())\n\n\n","metadata":{"execution":{"iopub.status.busy":"2022-01-08T15:03:29.075760Z","iopub.execute_input":"2022-01-08T15:03:29.075995Z","iopub.status.idle":"2022-01-08T15:04:12.623186Z","shell.execute_reply.started":"2022-01-08T15:03:29.075966Z","shell.execute_reply":"2022-01-08T15:04:12.622255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Tìm các từ contraction","metadata":{}},{"cell_type":"code","source":"list_contraction = []\nfor word in list_word:\n    if \"'\" in word:\n        list_contraction.append(word)\nprint(list_contraction)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T15:04:12.625185Z","iopub.execute_input":"2022-01-08T15:04:12.625572Z","iopub.status.idle":"2022-01-08T15:04:12.687970Z","shell.execute_reply.started":"2022-01-08T15:04:12.625529Z","shell.execute_reply":"2022-01-08T15:04:12.687320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Ta có thể thấy các từ contration là viết tắt quen thuộc như I'm = I am, I'll = I will,..... ta sẽ xử lý những từ thông dụng như này","metadata":{}},{"cell_type":"markdown","source":"# Tìm các từ misspell","metadata":{}},{"cell_type":"code","source":"\nimport nltk\nnltk.download('words')\n\nlist_misspell = []\nenglish_words = set(nltk.corpus.words.words())\n\nfor w in list_word:\n    if w not in english_words:\n        list_misspell.append(w)\nprint(list_misspell)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T15:04:12.689008Z","iopub.execute_input":"2022-01-08T15:04:12.689202Z","iopub.status.idle":"2022-01-08T15:04:14.360816Z","shell.execute_reply.started":"2022-01-08T15:04:12.689176Z","shell.execute_reply":"2022-01-08T15:04:14.359845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Ta có thể thấy một vài từ nói theo dạng UK như centre, colour,... Bên cạnh đó còn vài từ ngữ bị viết sai, viết tắt, ta sẽ xử lý chúng","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}}]}