paranormal-or-skeptic-ISI-p.../logistic-regression.ipynb
2021-05-25 17:09:13 +02:00

104 lines
2.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import torch\n",
"import gensim.downloader as gn\n",
"import csv\n",
"from nltk.tokenize import word_tokenize"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"STEP 3 - PREPROCESSING\n"
]
}
],
"source": [
"names = ['content', 'id', 'label']\n",
"train_data_content = pd.read_table('train/in.tsv', error_bad_lines = False, header = None, quoting = csv.QUOTE_NONE, names = ['content', 'id'])\n",
"train_data_labels = pd.read_table('train/expected.tsv', error_bad_lines = False, header = None, quoting=csv.QUOTE_NONE, names = ['label'])\n",
"dev_data = pd.read_table('dev-0/in.tsv', error_bad_lines = False, header = None, quoting = csv.QUOTE_NONE, names = ['content', 'id'])\n",
"test_data = pd.read_table('test-A/in.tsv', error_bad_lines = False, header = None, quoting = csv.QUOTE_NONE, names = ['content', 'id'])\n",
"\n",
"print('STEP 3 - PREPROCESSING')\n",
"# lowercase all content\n",
"X_train = train_data_content['content'].str.lower()\n",
"y_train = train_data_labels['label']\n",
"X_dev = dev_data['content'].str.lower()\n",
"X_test = test_data['content'].str.lower()\n",
"\n",
"# tokenize datasets\n",
"X_train = [word_tokenize(content) for content in X_train]\n",
"X_dev = [word_tokenize(content) for content in X_dev]\n",
"X_test = [word_tokenize(content) for content in X_test]"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[==================================================] 100.0% 1662.8/1662.8MB downloaded\n"
]
}
],
"source": [
"w2v = gn.load('word2vec-google-news-300')\n"
]
},
{
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}