update
This commit is contained in:
commit
477bb03e6d
13
README.md
Normal file
13
README.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
Skeptic vs paranormal subreddits
|
||||||
|
================================
|
||||||
|
|
||||||
|
Classify a reddit as either from Skeptic subreddit or one of the
|
||||||
|
"paranormal" subreddits (Paranormal, UFOs, TheTruthIsHere, Ghosts,
|
||||||
|
,Glitch-in-the-Matrix, conspiracytheories).
|
||||||
|
|
||||||
|
Output label is the probability of a paranormal subreddit.
|
||||||
|
|
||||||
|
Sources
|
||||||
|
-------
|
||||||
|
|
||||||
|
Data taken from <https://archive.org/details/2015_reddit_comments_corpus>.
|
1
config.txt
Normal file
1
config.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
--metric Likelihood --metric Accuracy --metric F1 --metric F0:N<Precision> --metric F9999999:N<Recall> --precision 4 --in-header in-header.tsv --out-header out-header.tsv
|
5272
dev-0/expected.tsv
Normal file
5272
dev-0/expected.tsv
Normal file
File diff suppressed because it is too large
Load Diff
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
BIN
dev-0/in.tsv.xz
Normal file
BIN
dev-0/in.tsv.xz
Normal file
Binary file not shown.
5272
dev-0/out.tsv
Normal file
5272
dev-0/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
1
in-header.tsv
Normal file
1
in-header.tsv
Normal file
@ -0,0 +1 @@
|
|||||||
|
PostText Timestamp
|
|
1
out-header.tsv
Normal file
1
out-header.tsv
Normal file
@ -0,0 +1 @@
|
|||||||
|
Label
|
|
67
program.py
Normal file
67
program.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import numpy as np
|
||||||
|
import torch
|
||||||
|
import gensim
|
||||||
|
from sklearn import preprocessing
|
||||||
|
import pandas as pd
|
||||||
|
from gensim.test.utils import common_texts
|
||||||
|
from gensim.models import Word2Vec
|
||||||
|
|
||||||
|
with open("train/in.tsv") as f:
|
||||||
|
X_train = f.readlines()
|
||||||
|
with open("train/expected.tsv") as ff:
|
||||||
|
Y_train = ff.readlines()
|
||||||
|
with open("test-A/in.tsv") as d:
|
||||||
|
X = d.readlines()
|
||||||
|
|
||||||
|
model = Word2Vec(X_train, min_count=1,size= 50,workers=3, window =3, sg = 1)
|
||||||
|
X_train=model[X_train]
|
||||||
|
X=model[X]
|
||||||
|
FEAUTERES=10000
|
||||||
|
class NeuralNetworkModel(torch.nn.Module):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(NeuralNetworkModel, self).__init__()
|
||||||
|
self.fc1 = torch.nn.Linear(FEAUTERES,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
|
||||||
|
|
||||||
|
nn_model = NeuralNetworkModel()
|
||||||
|
|
||||||
|
BATCH_SIZE = 5
|
||||||
|
|
||||||
|
criterion = torch.nn.BCELoss()
|
||||||
|
|
||||||
|
optimizer = torch.optim.SGD(nn_model.parameters(), lr = 0.1)
|
||||||
|
|
||||||
|
for epoch in range(10):
|
||||||
|
loss_score = 0
|
||||||
|
acc_score = 0
|
||||||
|
items_total = 0
|
||||||
|
nn_model.train()
|
||||||
|
for i in range(0, Y_train.shape[0], BATCH_SIZE):
|
||||||
|
X = X_train[i:i+BATCH_SIZE]
|
||||||
|
X = torch.tensor(X.astype(np.float32).todense())
|
||||||
|
Y = Y_train[i:i+BATCH_SIZE]
|
||||||
|
Y = torch.tensor(Y.astype(np.float32)).reshape(-1,1)
|
||||||
|
Y_predictions = nn_model(X)
|
||||||
|
acc_score += torch.sum((Y_predictions > 0.5) == Y).item()
|
||||||
|
items_total += Y.shape[0]
|
||||||
|
|
||||||
|
optimizer.zero_grad()
|
||||||
|
loss = criterion(Y_predictions, Y)
|
||||||
|
loss.backward()
|
||||||
|
optimizer.step()
|
||||||
|
|
||||||
|
|
||||||
|
loss_score += loss.item() * Y.shape[0]
|
||||||
|
with open('test-A/out1.tsv', 'w') as file:
|
||||||
|
for e in Y_predictions:
|
||||||
|
file.write("%f\n" % e)
|
||||||
|
|
||||||
|
|
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
BIN
test-A/in.tsv.xz
Normal file
BIN
test-A/in.tsv.xz
Normal file
Binary file not shown.
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/expected.tsv
Normal file
289579
train/expected.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
BIN
train/in.tsv.xz
Normal file
BIN
train/in.tsv.xz
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user