Playing with perceptron using Python
Perceptron code from ゼロから作るDeep Learning
(def ANDの所)
words.txt
Hello my name is Tsubasa Kato. I like supercomputer.
perceptron-test.py
f = open ('words.txt') x1 = 0 x2 = 0 def AND(x1, x2): w1, w2, theta = 0.5, 0.5, 0.7 tmp = x1*w1 + x2*w2 if tmp <= theta: return 0 elif tmp > theta: return 1 for word in f.read().split(): hitflag = 0 word = word.replace(',','') word = word.replace('.','') print(word) if word == "supercomputer": hitflag = 1 x1 = x1 + 1 x2 = x2 + 1 if word == "Hello": hitflag = 1 x1 = x1 -2 x2 = x2 -2 if hitflag == 1: print "HIT!" print AND(x1,x2)