前提・実現したいこと
pythonでニューラルネットワークの学習をしています
エラーそのものの意味は分かるのですが、
ニューラルネットの参考プログラム等の
h = F.sigmoid(self.l1(x))
h = F.sigmoid(self.l2(h))
a = F.sigmoid(self.l3(h))
というような書き方で上手く動く理由や、与えるべき入力、改善方法等が知りたいです
発生している問題・エラーメッセージ
Exception in main training loop:
Invalid operation is performed in: LinearFunction (Forward)
Expect: in_types[0].shape[1] == in_types[1].shape[1]
Actual: 800 != 200
該当のソースコード
python
1~~~ 2class test(chainer.Chain): 3 def __init__(self, n_vocab, n_units, loss_func,n_unit_test1, n_unit_test2): 4 super(test, self).__init__() 5 with self.init_scope(): 6 print(n_vocab)#32945 7 print(n_units)#200 8 print(n_unit_test2)#50 9 print(n_unit_test1)#200 10 self.embed = L.EmbedID( 11 n_vocab, n_units, initialW=I.Uniform(1. / n_units)) 12 self.layer1=L.Linear(n_units,n_unit_test2) 13 self.layer2=L.Linear(n_unit_test2,n_unit_test1) 14 self.loss_func = loss_func 15 16 def __call__(self, x, context):#batchsize=100 17 print(context.shape)#(100, 4) 18 e = self.embed(context) 19 print(e.shape)#(100, 4, 200) 20 ef=F.sigmoid(e) 21 print(ef.shape)#(100, 4, 200) 22 #ここでエラー 23 h1=self.layer1(ef) 24 #ここでエラー 25 print(h1.shape) 26 """ 27 for (ei,ew) in enumerate(e): 28 if ei==0: 29 print(ew.shape) 30 h1=[np.array(self.layer1(ew))] 31 else: 32 h1=np.append(h1,[np.array(self.layer1(ew))],axis=0) 33 """
試したこと
コメントアウトしているプログラムのように(100,4,200)のリストを(4,200)に分割し、入力を行えば"h1"そのものは改善できました。が、さらにニューラルネットに入れる際にエラーが発生してしまうこと、そもそも動かない理由などがわかりません
回答1件
あなたの回答
tips
プレビュー