Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
5adf2a8ac3 | |||
d2b7b4b4ff | |||
281da11048 | |||
75a4a7f841 | |||
8221929ce3 | |||
adb3d16237 | |||
4cb03f148f | |||
580d456788 | |||
c66367b7bb | |||
d930141277 | |||
5d25cd9587 | |||
|
0adf4ab778 | ||
|
bad68dfb59 |
5452
dev-0/out.tsv
Normal file
5452
dev-0/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
116
run.ipynb
Normal file
116
run.ipynb
Normal file
@ -0,0 +1,116 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "835530c2-0129-4b5f-a41c-f1870ca1307f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"import sklearn\n",
|
||||
"import pandas as pd\n",
|
||||
"from sklearn.metrics import accuracy_score\n",
|
||||
"from gzip import open as open_gz\n",
|
||||
"from sklearn.feature_extraction.text import TfidfVectorizer\n",
|
||||
"from sklearn.naive_bayes import MultinomialNB\n",
|
||||
"from sklearn.pipeline import make_pipeline"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"id": "5db73671-80b9-4099-85a0-08ecf77250d1",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def evaluation(x, path_out, model):\n",
|
||||
" results = model.predict(x)\n",
|
||||
"\n",
|
||||
" with open(path_out, 'wt') as file:\n",
|
||||
" for r in results:\n",
|
||||
" file.write(str(r) + '\\n')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "2120f43e-d587-4481-a04c-dea9520cecec",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"train = pd.read_csv('train/train.tsv', header = None, sep = '\\t', error_bad_lines = False)\n",
|
||||
"\n",
|
||||
"x_train = train[1]\n",
|
||||
"y_train = train[0]\n",
|
||||
"x_dev = pd.read_csv('dev-0/in.tsv',header = None, sep = '/t',engine = 'python')\n",
|
||||
"x_dev = x_dev[0]\n",
|
||||
"x_test = pd.read_csv('test-A/in.tsv',header = None, sep = '/t',engine = 'python')\n",
|
||||
"x_test = x_test[0]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"id": "cdfefa84-e535-48e8-844a-10e24b2a3555",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Pipeline(steps=[('tfidfvectorizer', TfidfVectorizer()),\n",
|
||||
" ('multinomialnb', MultinomialNB())])"
|
||||
]
|
||||
},
|
||||
"execution_count": 24,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"model = make_pipeline(TfidfVectorizer(), MultinomialNB())\n",
|
||||
"model.fit(x_train, y_train)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 25,
|
||||
"id": "e1b7fe0c-a21a-42cf-8cd4-46ee932d5282",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"evaluation(x_dev,'dev-0/out.tsv', model)\n",
|
||||
"evaluation(x_test,'test-A/out.tsv', model)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7a269ea0-eefd-4907-bf65-9bb53ad296b7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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.9.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
31
run.py
Normal file
31
run.py
Normal file
@ -0,0 +1,31 @@
|
||||
import os
|
||||
import sklearn
|
||||
import pandas as pd
|
||||
from sklearn.metrics import accuracy_score
|
||||
from gzip import open as open_gz
|
||||
from sklearn.feature_extraction.text import TfidfVectorizer
|
||||
from sklearn.naive_bayes import MultinomialNB
|
||||
from sklearn.pipeline import make_pipeline
|
||||
|
||||
def evaluation(x, path_out, model):
|
||||
results = model.predict(x)
|
||||
|
||||
with open(path_out, 'wt') as file:
|
||||
for r in results:
|
||||
file.write(str(r) + '\n')
|
||||
|
||||
|
||||
train = pd.read_csv('train/train.tsv', header = None, sep = '\t', error_bad_lines = False)
|
||||
|
||||
x_train = train[1]
|
||||
y_train = train[0]
|
||||
x_dev = pd.read_csv('dev-0/in.tsv',header = None, sep = '/t',engine = 'python')
|
||||
x_dev = x_dev[0]
|
||||
x_test = pd.read_csv('test-A/in.tsv',header = None, sep = '/t',engine = 'python')
|
||||
x_test = x_test[0]
|
||||
|
||||
model = make_pipeline(TfidfVectorizer(), MultinomialNB())
|
||||
model.fit(x_train, y_train)
|
||||
|
||||
evaluation(x_dev,'dev-0/out.tsv', model)
|
||||
evaluation(x_test,'test-A/out.tsv', model)
|
5447
test-A/out.tsv
Normal file
5447
test-A/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
98132
train/train.tsv
Normal file
98132
train/train.tsv
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user