在Lasagne中定義一個簡單的神經網絡模型需要以下步驟:
import lasagne
import theano.tensor as T
input_var = T.matrix('inputs')
target_var = T.ivector('targets')
input_layer = lasagne.layers.InputLayer(shape=(None, num_features), input_var=input_var)
hidden_layer = lasagne.layers.DenseLayer(input_layer, num_units=100, nonlinearity=lasagne.nonlinearities.rectify)
output_layer = lasagne.layers.DenseLayer(hidden_layer, num_units=num_classes, nonlinearity=lasagne.nonlinearities.softmax)
prediction = lasagne.layers.get_output(output_layer)
loss = lasagne.objectives.categorical_crossentropy(prediction, target_var)
loss = loss.mean()
params = lasagne.layers.get_all_params(output_layer, trainable=True)
updates = lasagne.updates.adam(loss, params)
train_fn = theano.function([input_var, target_var], loss, updates=updates)
test_prediction = lasagne.layers.get_output(output_layer, deterministic=True)
test_fn = theano.function([input_var], test_prediction)
這樣就定義了一個簡單的神經網絡模型,可以使用Lasagne庫進行訓練和測試。需要根據具體的數據集和任務來調整網絡結構和參數。