{"cells":[{"metadata":{},"cell_type":"markdown","source":"# IndoXTC - Extracting Toxic-EN Features [XLM-R] 2\nExploring Indonesian hate speech/abusive & sentiment text classification using multilingual language model.   \n   \nThis kernel is a part of my undergraduate final year project.  \nCheckout the full github repository:  \nhttps://github.com/ilhamfp/indonesian-text-classification-multilingual"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom load_data import load_dataset_foreign\nfrom extract_feature import FeatureExtractor\n\nSTART = 20000\nEND   = 40000","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","collapsed":true,"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":false},"cell_type":"markdown","source":"## Load Data"},{"metadata":{"trusted":true},"cell_type":"code","source":"data = load_dataset_foreign(data_name='toxic')\ndata_pos = data[data['label'] == 1].reset_index(drop=True)\ndata_neg = data[data['label'] == 0].reset_index(drop=True)\n\ntrain = pd.concat([data_pos[START:END], \n                   data_neg[START:END]]).reset_index(drop=True)\n\nprint(train.shape)\ntrain.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Extract Feature"},{"metadata":{"trusted":true},"cell_type":"code","source":"FE = FeatureExtractor(model_name='xlm-r')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train['text'] = train['text'].apply(lambda x: FE.extract_features(x))\ntrain.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Saving Results"},{"metadata":{"trusted":true},"cell_type":"code","source":"np.save(\"train_text.npy\", train['text'].values)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train['label'].to_csv('train_label.csv', index=False, header=['label'])","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}