Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions code/Hierarchical_Attention_Networks/textClassifierConv.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
# author - Richard Liao
# Dec 26 2016
import numpy as np
Expand Down Expand Up @@ -38,7 +39,7 @@ def clean_str(string):
return string.strip().lower()

data_train = pd.read_csv('~/Testground/data/imdb/labeledTrainData.tsv', sep='\t')
print data_train.shape
print(data_train.shape)

texts = []
labels = []
Expand All @@ -59,8 +60,8 @@ def clean_str(string):
data = pad_sequences(sequences, maxlen=MAX_SEQUENCE_LENGTH)

labels = to_categorical(np.asarray(labels))
print('Shape of data tensor:', data.shape)
print('Shape of label tensor:', labels.shape)
print(('Shape of data tensor:', data.shape))
print(('Shape of label tensor:', labels.shape))

indices = np.arange(data.shape[0])
np.random.shuffle(indices)
Expand All @@ -74,8 +75,8 @@ def clean_str(string):
y_val = labels[-nb_validation_samples:]

print('Number of positive and negative reviews in traing and validation set ')
print y_train.sum(axis=0)
print y_val.sum(axis=0)
print(y_train.sum(axis=0))
print(y_val.sum(axis=0))

GLOVE_DIR = "/ext/home/analyst/Testground/data/glove"
embeddings_index = {}
Expand Down
13 changes: 7 additions & 6 deletions code/Hierarchical_Attention_Networks/textClassifierHATT.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
# author - Richard Liao
# Dec 26 2016
import numpy as np
Expand Down Expand Up @@ -43,7 +44,7 @@ def clean_str(string):
return string.strip().lower()

data_train = pd.read_csv('~/Testground/data/imdb/labeledTrainData.tsv', sep='\t')
print data_train.shape
print(data_train.shape)

from nltk import tokenize

Expand Down Expand Up @@ -79,8 +80,8 @@ def clean_str(string):
print('Total %s unique tokens.' % len(word_index))

labels = to_categorical(np.asarray(labels))
print('Shape of data tensor:', data.shape)
print('Shape of label tensor:', labels.shape)
print(('Shape of data tensor:', data.shape))
print(('Shape of label tensor:', labels.shape))

indices = np.arange(data.shape[0])
np.random.shuffle(indices)
Expand All @@ -94,8 +95,8 @@ def clean_str(string):
y_val = labels[-nb_validation_samples:]

print('Number of positive and negative reviews in traing and validation set')
print y_train.sum(axis=0)
print y_val.sum(axis=0)
print(y_train.sum(axis=0))
print(y_val.sum(axis=0))

GLOVE_DIR = "/ext/home/analyst/Testground/data/glove"
embeddings_index = {}
Expand Down Expand Up @@ -138,7 +139,7 @@ def clean_str(string):
metrics=['acc'])

print("model fitting - Hierachical LSTM")
print model.summary()
print(model.summary())
model.fit(x_train, y_train, validation_data=(x_val, y_val),
nb_epoch=10, batch_size=50)

Expand Down
11 changes: 6 additions & 5 deletions code/Hierarchical_Attention_Networks/textClassifierRNN.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
# author - Richard Liao
# Dec 26 2016
import numpy as np
Expand Down Expand Up @@ -42,7 +43,7 @@ def clean_str(string):
return string.strip().lower()

data_train = pd.read_csv('~/Testground/data/imdb/labeledTrainData.tsv', sep='\t')
print data_train.shape
print(data_train.shape)

texts = []
labels = []
Expand All @@ -63,8 +64,8 @@ def clean_str(string):
data = pad_sequences(sequences, maxlen=MAX_SEQUENCE_LENGTH)

labels = to_categorical(np.asarray(labels))
print('Shape of data tensor:', data.shape)
print('Shape of label tensor:', labels.shape)
print(('Shape of data tensor:', data.shape))
print(('Shape of label tensor:', labels.shape))

indices = np.arange(data.shape[0])
np.random.shuffle(indices)
Expand All @@ -78,8 +79,8 @@ def clean_str(string):
y_val = labels[-nb_validation_samples:]

print('Traing and validation set number of positive and negative reviews')
print y_train.sum(axis=0)
print y_val.sum(axis=0)
print(y_train.sum(axis=0))
print(y_val.sum(axis=0))

GLOVE_DIR = "~/Testground/data/glove"
embeddings_index = {}
Expand Down