作为个人项目的一部分,我正在尝试使用我自己的数据修改 Theano 文档(多层感知器)中给出的示例代码。
到目前为止,我设法以所需的格式带来了我自己的(文本)数据,并且我想构建一个二进制分类器。问题是当我写输出的数量是 1 即
classifier = MLP(rng=rng, input=x, n_in=49, n_hidden=n_hidden, n_out=1)
我收到以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Asterios\Anaconda\lib\site-packages\spyderlib\widgets\externalshell \sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "C:/Users/Asterios/Documents/Python/TripAdvisor/untitled4.py", line 603, in <module>
params = test_mlp()
File "C:/Users/Asterios/Documents/Python/TripAdvisor/untitled4.py", line 553, in test_mlp
minibatch_avg_cost = train_model(minibatch_index)
File "C:\Users\Asterios\Anaconda\lib\site-packages\theano-0.6.0-py2.7.egg\theano\compile\function_module.py", line 588, in __call__
self.fn.thunks[self.fn.position_of_error])
File "C:\Users\Asterios\Anaconda\lib\site-packages\theano-0.6.0-py2.7.egg\theano\compile\function_module.py", line 579, in __call__
outputs = self.fn()
ValueError: y_i value out of bounds
Apply node that caused the error: CrossentropySoftmaxArgmax1HotWithBias(Dot22.0, b, Elemwise{Cast{int32}}.0)
Inputs shapes: [(10L, 1L), (1L,), (10L,)]
Inputs strides: [(8L, 8L), (8L,), (4L,)]
Inputs types: [TensorType(float64, matrix), TensorType(float64, vector), TensorType(int32, vector)]
Use the Theano flag 'exception_verbosity=high' for a debugprint of this apply node.
我的训练数据的输出(在转换为 theano 共享类型之前)是这样的:
array([1, 1, 1, ..., 0, 0, 0], dtype=int64)
奇怪的是,如果我使用超过 1 的任何输出神经元(例如 n_out=2)作为输出神经元,代码运行时没有任何错误,但当然现在有许多输出神经元没有实际意义。
有人可以解释为什么带有二进制输出的代码似乎给了我一个错误吗?我怎样才能得到这个工作?
谢谢!