ver 2 pre-trained word2vec
This commit is contained in:
parent
79d0d3491c
commit
6fb853de01
1252
dev-0/out.tsv
1252
dev-0/out.tsv
File diff suppressed because it is too large
Load Diff
15
main.py
15
main.py
@ -42,12 +42,13 @@ X_dev = [word_tokenize(content) for content in X_dev]
|
||||
X_test = [word_tokenize(content) for content in X_test]
|
||||
|
||||
# word2vec
|
||||
word2vec = Word2Vec(X_train, vector_size=50, window=5, min_count=1)
|
||||
X_train = [np.mean([word2vec.wv[word] for word in content if word in word2vec.wv] or [np.zeros(50)], axis=0) for content in X_train]
|
||||
X_dev = [np.mean([word2vec.wv[word] for word in content if word in word2vec.wv] or [np.zeros(50)], axis=0) for content in X_dev]
|
||||
X_test = [np.mean([word2vec.wv[word] for word in content if word in word2vec.wv] or [np.zeros(50)], axis=0) for content in X_test]
|
||||
#word2vec = Word2Vec(X_train, vector_size=50, window=5, min_count=1)
|
||||
word2vec = gensim.downloader.load('word2vec-google-news-300')
|
||||
X_train = [np.mean([word2vec[word] for word in content if word in word2vec] or [np.zeros(300)], axis=0) for content in X_train]
|
||||
X_dev = [np.mean([word2vec[word] for word in content if word in word2vec] or [np.zeros(300)], axis=0) for content in X_dev]
|
||||
X_test = [np.mean([word2vec[word] for word in content if word in word2vec] or [np.zeros(300)], axis=0) for content in X_test]
|
||||
|
||||
model = NeuralNetwork(50, 400, 1)
|
||||
model = NeuralNetwork(300, 600, 1)
|
||||
|
||||
criterion = torch.nn.BCELoss()
|
||||
optimizer = torch.optim.SGD(model.parameters(), lr = 0.01)
|
||||
@ -63,7 +64,7 @@ for epoch in range(6):
|
||||
y = y_train[i:i+batch_size]
|
||||
y = torch.tensor(y.astype(np.float32).to_numpy()).reshape(-1,1)
|
||||
|
||||
outputs = model(X)
|
||||
outputs = model(X.float())
|
||||
loss = criterion(outputs, y)
|
||||
|
||||
optimizer.zero_grad()
|
||||
@ -85,7 +86,7 @@ with torch.no_grad():
|
||||
|
||||
prediction = (outputs > 0.5)
|
||||
dev_prediction = dev_prediction + prediction.tolist()
|
||||
|
||||
|
||||
for i in range(0, len(X_test), batch_size):
|
||||
X = X_test[i:i+batch_size]
|
||||
X = torch.tensor(X)
|
||||
|
1108
test-A/out.tsv
1108
test-A/out.tsv
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user