This commit is contained in:
jakubknczny 2021-05-26 00:07:15 +02:00
parent 756ef4277a
commit 3fea4b5ee5
10 changed files with 10547 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="gpu" project-jdk-type="Python SDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/paranormal-or-skeptic-ISI-public.iml" filepath="$PROJECT_DIR$/.idea/paranormal-or-skeptic-ISI-public.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

5272
dev-0/out.tsv Normal file

File diff suppressed because it is too large Load Diff

BIN
geval Executable file

Binary file not shown.

86
log_reg.py Normal file
View File

@ -0,0 +1,86 @@
import gensim.downloader as gensim
import numpy as np
import pandas as pd
import torch
from nltk.tokenize import word_tokenize
class NeuralNetworkModel(torch.nn.Module):
def __init__(self):
super(NeuralNetworkModel, self).__init__()
self.l01 = torch.nn.Linear(300, 500)
self.l02 = torch.nn.Linear(500, 1)
def forward(self, x):
x = self.l01(x)
x = torch.relu(x)
x = self.l02(x)
x = torch.sigmoid(x)
return x
def doc2vec(doc):
return np.mean([word2vec[word] for word in doc if word in word2vec] or [np.zeros(300)], axis=0)
x_train = pd.read_table('train/in.tsv.xz', compression='xz', sep='\t', header=None, error_bad_lines=False, quoting=3)
y_train = pd.read_table('train/expected.tsv', sep='\t', header=None, quoting=3)
x_dev = pd.read_table('dev-0/in.tsv.xz', compression='xz', sep='\t', header=None, quoting=3)
x_test = pd.read_table('test-A/in.tsv.xz', compression='xz', sep='\t', header=None, quoting=3)
y_train = y_train[0]
x_train = x_train[0].str.lower()
x_train = [word_tokenize(x) for x in x_train]
x_dev = x_dev[0].str.lower()
x_dev = [word_tokenize(x) for x in x_dev]
x_test = x_test[0].str.lower()
x_test = [word_tokenize(x) for x in x_test]
word2vec = gensim.load('word2vec-google-news-300')
x_train = [doc2vec(doc) for doc in x_train]
x_dev = [doc2vec(doc) for doc in x_dev]
x_test = [doc2vec(doc) for doc in x_test]
model = NeuralNetworkModel()
BATCH_SIZE = 1024
criterion = torch.nn.BCELoss()
optimizer = torch.optim.Adam(model.parameters())
for epoch in range(5):
model.train()
for i in range(0, y_train.shape[0], BATCH_SIZE):
X = x_train[i:i + BATCH_SIZE]
X = torch.tensor(X)
y = y_train[i:i + BATCH_SIZE]
y = torch.tensor(y.astype(np.float32).to_numpy()).reshape(-1, 1)
optimizer.zero_grad()
outputs = model(X.float())
loss = criterion(outputs, y)
loss.backward()
optimizer.step()
y_dev = []
y_test = []
model.eval()
with torch.no_grad():
for i in range(0, len(x_dev), BATCH_SIZE):
X = x_dev[i:i + BATCH_SIZE]
X = torch.tensor(X)
outputs = model(X.float())
y = (outputs > 0.5)
y_dev.extend(y)
for i in range(0, len(x_test), BATCH_SIZE):
X = x_test[i:i + BATCH_SIZE]
X = torch.tensor(X)
outputs = model(X.float())
y = (outputs >= 0.5)
y_test.extend(y)
y_dev = np.asarray(y_dev, dtype=np.int32)
Y_dev = pd.DataFrame({'label': y_dev})
Y_dev.to_csv(r'dev-0/out.tsv', sep='\t', index=False, header=False)
y_test = np.asarray(y_test, dtype=np.int32)
Y_test = pd.DataFrame({'label': y_test})
Y_test.to_csv(r'test-A/out.tsv', sep='\t', index=False, header=False)

5152
test-A/out.tsv Normal file

File diff suppressed because it is too large Load Diff