Skip to content

Commit 018acae

Browse files
committed
Use print() function in both Python 2 and Python 3
Legacy __print__ statements are syntax errors in Python 3 but __print()__ function works as expected in both Python 2 and Python 3.
1 parent e441572 commit 018acae

3 files changed

Lines changed: 19 additions & 16 deletions

File tree

code/Hierarchical_Attention_Networks/textClassifierConv.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# author - Richard Liao
23
# Dec 26 2016
34
import numpy as np
@@ -38,7 +39,7 @@ def clean_str(string):
3839
return string.strip().lower()
3940

4041
data_train = pd.read_csv('~/Testground/data/imdb/labeledTrainData.tsv', sep='\t')
41-
print data_train.shape
42+
print(data_train.shape)
4243

4344
texts = []
4445
labels = []
@@ -59,8 +60,8 @@ def clean_str(string):
5960
data = pad_sequences(sequences, maxlen=MAX_SEQUENCE_LENGTH)
6061

6162
labels = to_categorical(np.asarray(labels))
62-
print('Shape of data tensor:', data.shape)
63-
print('Shape of label tensor:', labels.shape)
63+
print(('Shape of data tensor:', data.shape))
64+
print(('Shape of label tensor:', labels.shape))
6465

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

7677
print('Number of positive and negative reviews in traing and validation set ')
77-
print y_train.sum(axis=0)
78-
print y_val.sum(axis=0)
78+
print(y_train.sum(axis=0))
79+
print(y_val.sum(axis=0))
7980

8081
GLOVE_DIR = "/ext/home/analyst/Testground/data/glove"
8182
embeddings_index = {}

code/Hierarchical_Attention_Networks/textClassifierHATT.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# author - Richard Liao
23
# Dec 26 2016
34
import numpy as np
@@ -43,7 +44,7 @@ def clean_str(string):
4344
return string.strip().lower()
4445

4546
data_train = pd.read_csv('~/Testground/data/imdb/labeledTrainData.tsv', sep='\t')
46-
print data_train.shape
47+
print(data_train.shape)
4748

4849
from nltk import tokenize
4950

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

8182
labels = to_categorical(np.asarray(labels))
82-
print('Shape of data tensor:', data.shape)
83-
print('Shape of label tensor:', labels.shape)
83+
print(('Shape of data tensor:', data.shape))
84+
print(('Shape of label tensor:', labels.shape))
8485

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

9697
print('Number of positive and negative reviews in traing and validation set')
97-
print y_train.sum(axis=0)
98-
print y_val.sum(axis=0)
98+
print(y_train.sum(axis=0))
99+
print(y_val.sum(axis=0))
99100

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

140141
print("model fitting - Hierachical LSTM")
141-
print model.summary()
142+
print(model.summary())
142143
model.fit(x_train, y_train, validation_data=(x_val, y_val),
143144
nb_epoch=10, batch_size=50)
144145

code/Hierarchical_Attention_Networks/textClassifierRNN.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# author - Richard Liao
23
# Dec 26 2016
34
import numpy as np
@@ -42,7 +43,7 @@ def clean_str(string):
4243
return string.strip().lower()
4344

4445
data_train = pd.read_csv('~/Testground/data/imdb/labeledTrainData.tsv', sep='\t')
45-
print data_train.shape
46+
print(data_train.shape)
4647

4748
texts = []
4849
labels = []
@@ -63,8 +64,8 @@ def clean_str(string):
6364
data = pad_sequences(sequences, maxlen=MAX_SEQUENCE_LENGTH)
6465

6566
labels = to_categorical(np.asarray(labels))
66-
print('Shape of data tensor:', data.shape)
67-
print('Shape of label tensor:', labels.shape)
67+
print(('Shape of data tensor:', data.shape))
68+
print(('Shape of label tensor:', labels.shape))
6869

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

8081
print('Traing and validation set number of positive and negative reviews')
81-
print y_train.sum(axis=0)
82-
print y_val.sum(axis=0)
82+
print(y_train.sum(axis=0))
83+
print(y_val.sum(axis=0))
8384

8485
GLOVE_DIR = "~/Testground/data/glove"
8586
embeddings_index = {}

0 commit comments

Comments
 (0)