This commit is contained in:
JulianZablonski 2022-05-17 22:20:36 +02:00
parent 6896527c9c
commit 87a9c7ca30
13 changed files with 125627 additions and 1 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*~
*.pyc
*.swp

21
README.md Normal file
View File

@ -0,0 +1,21 @@
Sport Texts Classification Challenge
====================================
Guess the sport discipline for a Polish article.
Possible disciplines: pilka-nozna, siatkowka, sporty-walki, pilka-reczna, koszykowka, tenis, moto, zimowe. Evaluation metric is Accuracy.
Directory structure
-------------------
* `README.md` — this file
* `config.txt` — configuration file
* `train/` — directory with training data
* `train/train.tsv` — sample train set
* `dev-0/` — directory with dev (test) data
* `dev-0/in.tsv` — input data for the dev set
* `dev-0/expected.tsv` — expected (reference) data for the dev set
* `test-A` — directory with test data
* `test-A/in.tsv` — input data for the test set
* `test-A/expected.tsv` — expected (reference) data for the test set

1
config.txt Normal file
View File

@ -0,0 +1 @@
--metric LikelihoodHashed --metric Accuracy --precision 5

5452
dev-0/expected.tsv Normal file

File diff suppressed because it is too large Load Diff

5452
dev-0/in.tsv Normal file

File diff suppressed because it is too large Load Diff

5452
dev-0/out.tsv Normal file

File diff suppressed because it is too large Load Diff

167
run.ipynb Normal file
View File

@ -0,0 +1,167 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"\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": 31,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\User\\anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3444: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version.\n",
"\n",
"\n",
" exec(code_obj, self.user_global_ns, self.user_ns)\n",
"b'Skipping line 3249: expected 2 fields, saw 3\\nSkipping line 66393: expected 2 fields, saw 3\\nSkipping line 76415: expected 2 fields, saw 3\\n'\n"
]
}
],
"source": [
"data = pd.read_csv('train/train.tsv', sep='\\t', header=None, error_bad_lines=False)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"X = data[1]\n",
"\n",
"with open('dev-0/in.tsv', 'r', encoding='utf8') as f:\n",
" Xdev = f.readlines()\n",
"Xdev = pd.Series(Xdev)\n",
"\n",
"with open('test-A/in.tsv', 'r', encoding='utf8') as f:\n",
" Xtest = f.readlines()\n",
"Xtest = pd.Series(Xtest)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"y = data[0].astype('string')\n",
"\n",
"ydev = pd.read_csv('dev-0/expected.tsv', sep='\\t', header=None)\n",
"ydev = ydev.squeeze()"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"model = make_pipeline(TfidfVectorizer(), MultinomialNB())"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Pipeline(steps=[('tfidfvectorizer', TfidfVectorizer()),\n",
" ('multinomialnb', MultinomialNB())])"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.fit(X, y)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"predictions_dev0 = model.predict(Xdev)\n",
"predictions_dev0 = pd.Series(predictions_dev0)\n",
"predictions_dev0 = predictions_dev0"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"with open('dev-0/out.tsv', 'wt') as f:\n",
" for pred in predictions_dev0:\n",
" f.write(str(pred)+'\\n')"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"predictions_testA = model.predict(Xtest)\n",
"predictions_testA = pd.Series(predictions_testA)\n",
"predictions_testA = predictions_testA"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"with open('test-A/out.tsv', 'wt') as f:\n",
" for pred in predictions_testA:\n",
" f.write(str(pred)+'\\n')"
]
}
],
"metadata": {
"interpreter": {
"hash": "f08154012ddadd8e950e6e9e035c7a7b32c136e7647e9b7c77e02eb723a8bedb"
},
"kernelspec": {
"display_name": "Python 3.9.7 ('base')",
"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.7"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

53
run.py Normal file
View File

@ -0,0 +1,53 @@
import pandas as pd
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import make_pipeline
data = pd.read_csv('train/train.tsv', sep='\t', header=None, error_bad_lines=False)
X = data[1]
with open('dev-0/in.tsv', 'r', encoding='utf8') as f:
Xdev = f.readlines()
Xdev = pd.Series(Xdev)
with open('test-A/in.tsv', 'r', encoding='utf8') as f:
Xtest = f.readlines()
Xtest = pd.Series(Xtest)
y = data[0].astype('string')
ydev = pd.read_csv('dev-0/expected.tsv', sep='\t', header=None)
ydev = ydev.squeeze()
model = make_pipeline(TfidfVectorizer(), MultinomialNB())
model.fit(X, y)
predictions_dev0 = model.predict(Xdev)
predictions_dev0 = pd.Series(predictions_dev0)
predictions_dev0 = predictions_dev0
with open('dev-0/out.tsv', 'wt') as f:
for pred in predictions_dev0:
f.write(str(pred)+'\n')
predictions_testA = model.predict(Xtest)
predictions_testA = pd.Series(predictions_testA)
predictions_testA = predictions_testA
with open('test-A/out.tsv', 'wt') as f:
for pred in predictions_testA:
f.write(str(pred)+'\n')

@ -1 +0,0 @@
Subproject commit 793a89fc6fef6a5c9691a716f6e8b2737e6e8cd5

5447
test-A/in.tsv Normal file

File diff suppressed because it is too large Load Diff

5447
test-A/out.tsv Normal file

File diff suppressed because it is too large Load Diff

98132
train/train.tsv Normal file

File diff suppressed because it is too large Load Diff

BIN
train/train.tsv.gz Normal file

Binary file not shown.