Skip to content

Commit 7930ff4

Browse files
authored
Merge pull request #31 from danishpruthi/master
changed cnn-activations to work with python3
2 parents 24460f1 + 8161a67 commit 7930ff4

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

05-cnn/cnn-activation.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,25 @@ def calc_predict_and_activations(wids, tag, words):
6565
pool_out = dy.rectify(pool_out)
6666

6767
scores = (W_sm * pool_out + b_sm).npvalue()
68-
print '%d ||| %s' % (tag, ' '.join(words))
68+
print ('%d ||| %s' % (tag, ' '.join(words)))
6969
predict = np.argmax(scores)
70-
print display_activations(words, activations)
71-
print 'scores=%s, predict: %d' % (scores, predict)
70+
print (display_activations(words, activations))
71+
print ('scores=%s, predict: %d' % (scores, predict))
7272
features = pool_out.npvalue()
7373
W = W_sm.npvalue()
7474
bias = b_sm.npvalue()
75-
print ' bias=%s' % bias
75+
print (' bias=%s' % bias)
7676
contributions = W * features
77-
print ' very bad (%.4f): %s' % (scores[0], contributions[0])
78-
print ' bad (%.4f): %s' % (scores[1], contributions[1])
79-
print ' neutral (%.4f): %s' % (scores[2], contributions[2])
80-
print ' good (%.4f): %s' % (scores[3], contributions[3])
81-
print 'very good (%.4f): %s' % (scores[4], contributions[4])
77+
print (' very bad (%.4f): %s' % (scores[0], contributions[0]))
78+
print (' bad (%.4f): %s' % (scores[1], contributions[1]))
79+
print (' neutral (%.4f): %s' % (scores[2], contributions[2]))
80+
print (' good (%.4f): %s' % (scores[3], contributions[3]))
81+
print ('very good (%.4f): %s' % (scores[4], contributions[4]))
8282

8383

8484
def display_activations(words, activations):
85-
pad_begin = (WIN_SIZE - 1) / 2
86-
pad_end = WIN_SIZE - 1 - pad_begin
85+
pad_begin = int((WIN_SIZE - 1) / 2)
86+
pad_end = int(WIN_SIZE - 1 - pad_begin)
8787
words_padded = ['pad' for i in range(pad_begin)] + words + ['pad' for i in range(pad_end)]
8888

8989
ngrams = []
@@ -121,4 +121,5 @@ def display_activations(words, activations):
121121

122122
for words, wids, tag in dev:
123123
calc_predict_and_activations(wids, tag, words)
124-
raw_input()
124+
# input prompt so that the next example is revealed on a key press
125+
input()

0 commit comments

Comments
 (0)