Compare commits
4 Commits
master
...
neuralNetw
Author | SHA1 | Date | |
---|---|---|---|
b8a409e014 | |||
7616b2d9f5 | |||
|
4388b7d18d | ||
5e66be7f46 |
5272
dev-0/in.tsv
Normal file
5272
dev-0/in.tsv
Normal file
File diff suppressed because one or more lines are too long
5272
dev-0/out.tsv
Normal file
5272
dev-0/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
65
main.py
Normal file
65
main.py
Normal file
@ -0,0 +1,65 @@
|
||||
from gensim.test.utils import common_texts
|
||||
from gensim.models import Word2Vec
|
||||
|
||||
from sklearn import preprocessing
|
||||
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import gensim
|
||||
import torch
|
||||
|
||||
class NeuralNetworkModel(torch.nn.Module):
|
||||
|
||||
def __init__(self):
|
||||
super(NeuralNetworkModel, self).__init__()
|
||||
self.fc1 = torch.nn.Linear(maxim, 500)
|
||||
self.fc2 = torch.nn.Linear(500, 1)
|
||||
|
||||
def forward(self, x):
|
||||
x = self.fc1(x)
|
||||
x = torch.relu(x)
|
||||
x = self.fc2(x)
|
||||
x = torch.sigmoid(x)
|
||||
return x
|
||||
|
||||
with open("train/in.tsv") as xd:
|
||||
x1 = xd.readlines()
|
||||
with open("train/expected.tsv") as xdd:
|
||||
y1 = xdd.readlines()
|
||||
with open("test-A/in.tsv") as xddd:
|
||||
x = xddd.readlines()
|
||||
|
||||
maxim = 500
|
||||
bLen = 5
|
||||
|
||||
exp = Word2Vec(x1, min_count = 1, vector_size = 500, workers = 3, window = 3, sg = 1)
|
||||
exp1 = Word2Vec(x, min_count = 1, vector_size = 500, workers = 3, window = 3, sg = 1)
|
||||
exp2 = NeuralNetworkModel()
|
||||
|
||||
x1 = exp.wv
|
||||
x = exp1.wv
|
||||
|
||||
crt = torch.nn.BCELoss()
|
||||
miz = torch.optim.SGD(exp2.parameters(), lr = 0.1)
|
||||
|
||||
for each in range(10):
|
||||
lossScore, accScore, sums = 0
|
||||
exp2.train()
|
||||
for i in range(0, y1.shape[0], bLen):
|
||||
x = x1[i : i + bLen]
|
||||
x = torch.tensor(x.astype(np.float32).todense())
|
||||
y = y1[i : i + bLen]
|
||||
y = torch.tensor(y.astype(np.float32)).reshape(-1, 1)
|
||||
y2 = exp2(x)
|
||||
accScore += torch.sum((y2 > 0.5) == y).item()
|
||||
sums += y.shape[0]
|
||||
|
||||
miz.zero_grad()
|
||||
loss = crt(y2, Y)
|
||||
loss.backward()
|
||||
miz.step()
|
||||
|
||||
lossScore += loss.item() * Y.shape[0]
|
||||
with open('test-A/out.tsv', 'w') as file:
|
||||
for each in y2:
|
||||
file.write("%f\n" % each)
|
5152
test-A/in.tsv
Normal file
5152
test-A/in.tsv
Normal file
File diff suppressed because one or more lines are too long
5152
test-A/out.tsv
Normal file
5152
test-A/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
289579
train/in.tsv
Normal file
289579
train/in.tsv
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user