2015-08-02 21 views
7

Tôi tự hỏi liệu có cách thêm nút thiên vị vào mỗi lớp trong bộ công cụ mạng nơron Lasagne không? Tôi đã cố gắng tìm thông tin liên quan trong tài liệu.Thêm thiên vị vào các lớp mạng nơron Lasagne

Đây là mạng tôi đã tạo nhưng tôi không biết cách thêm nút thiên vị vào mỗi lớp.

def build_mlp(input_var=None): 
    # This creates an MLP of two hidden layers of 800 units each, followed by 
    # a softmax output layer of 10 units. It applies 20% dropout to the input 
    # data and 50% dropout to the hidden layers. 

    # Input layer, specifying the expected input shape of the network 
    # (unspecified batchsize, 1 channel, 28 rows and 28 columns) and 
    # linking it to the given Theano variable `input_var`, if any: 
    l_in = lasagne.layers.InputLayer(shape=(None, 60), 
            input_var=input_var) 

    # Apply 20% dropout to the input data: 
    l_in_drop = lasagne.layers.DropoutLayer(l_in, p=0.2) 

    # Add a fully-connected layer of 800 units, using the linear rectifier, and 
    # initializing weights with Glorot's scheme (which is the default anyway): 
    l_hid1 = lasagne.layers.DenseLayer(
      l_in_drop, num_units=800, 
      nonlinearity=lasagne.nonlinearities.rectify, 
      W=lasagne.init.Uniform()) 

    # We'll now add dropout of 50%: 
    l_hid1_drop = lasagne.layers.DropoutLayer(l_hid1, p=0.5) 

    # Another 800-unit layer: 
    l_hid2 = lasagne.layers.DenseLayer(
      l_hid1_drop, num_units=800, 
      nonlinearity=lasagne.nonlinearities.rectify) 

    # 50% dropout again: 
    l_hid2_drop = lasagne.layers.DropoutLayer(l_hid2, p=0.5) 

    # Finally, we'll add the fully-connected output layer, of 10 softmax units: 
    l_out = lasagne.layers.DenseLayer(
      l_hid2_drop, num_units=2, 
      nonlinearity=lasagne.nonlinearities.softmax) 

    # Each layer is linked to its incoming layer(s), so we only need to pass 
    # the output layer to give access to a network in Lasagne: 
    return l_out 

Trả lời

9

Trên thực tế bạn không cần phải tạo ra một cách rõ ràng những thành kiến, vì DenseLayer(), và căn cứ chập lớp quá, có một đối số từ khóa mặc định:

b=lasagne.init.Constant(0.).

Vì vậy, bạn có thể tránh tạo bias, nếu bạn không muốn có một cách rõ ràng vượt qua bias=None, nhưng đây không phải là trường hợp đó.

Như vậy trong ngắn bạn có thông số sai lệch trong khi bạn không vượt qua None-bias tham số ví dụ .:

hidden = Denselayer(...bias=None) 
Các vấn đề liên quan