Ejemplo n.º 1
0
 def __init__(self):
     """ Initializes model layers and weights. """
     # <COGINST>
     init_kwargs = {'gain': np.sqrt(2)}
     self.conv1 = conv(200, 250, 2, stride = 1, weight_initializer = glorot_normal, weight_kwargs = init_kwargs)
     self.dense1 = dense(250, 250, weight_initializer = glorot_normal, weight_kwargs = init_kwargs)
     self.dense2 = dense(250,1, weight_initializer = glorot_normal, weight_kwargs = init_kwargs)
Ejemplo n.º 2
0
 def __init__(self):
     self.conv1 = conv(1,
                       5,
                       2,
                       2,
                       stride=2,
                       padding=0,
                       weight_initializer=glorot_uniform)
     self.conv2 = conv(5,
                       10,
                       2,
                       2,
                       stride=1,
                       padding=0,
                       weight_initializer=glorot_uniform)
     self.dense1 = dense(360, 300, weight_initializer=glorot_uniform)
     self.dense2 = dense(300, 300, weight_initializer=glorot_uniform)
     self.dense3 = dense(300, 5, weight_initializer=glorot_uniform)
     self.layers = (self.conv1, self.conv2, self.dense1, self.dense2,
                    self.dense3)
     self.tensors = []
     for layer in self.layers:
         for parameter in layer.parameters:
             self.tensors.append(parameter)
     self.weights = [parameter.data for parameter in self.tensors]
 def __init__(self, input_dim, f1, f2, d1, num_classes):
     '''
     Parameters
     ----------
     input_dim:
         size of input based on training data
     n1 : int
         The number of neurons in the first hidden layer
     num_classes : int
         The number of classes predicted by the model'''
     init_kwargs = {'gain': np.sqrt(2)}
     self.conv1 = conv(input_dim,
                       f1,
                       5,
                       5,
                       weight_initializer=glorot_uniform,
                       weight_kwargs=init_kwargs)
     self.conv2 = conv(f1,
                       f2,
                       5,
                       5,
                       weight_initializer=glorot_uniform,
                       weight_kwargs=init_kwargs)
     self.dense1 = dense(f2 * 37 * 37,
                         d1,
                         weight_initializer=glorot_uniform,
                         weight_kwargs=init_kwargs)
     self.dense2 = dense(d1,
                         num_classes,
                         weight_initializer=glorot_uniform,
                         weight_kwargs=init_kwargs)
    def __init__(self):
        params = np.load("params.npy")

        #this gain is a parameter for the weight initializiation function glorot_uniform
        #which you can read more about in the documentation, but it isn't crucial for now
        #If you would like to read more about how Xavier Glorot explains the rationalization behind these weight initializations,
        #look here for his paper written with Yoshua Bengio. (http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf)
        init_kwargs = {'gain': np.sqrt(2)}

        #We will use a dropout probability of 0.5 so that values are randomly set to 0 in our data
        self.dropout_prob = 0.5

        #initialize your two dense and convolution layers as class attributes using the functions imported from MyNN
        #We will use weight_initializer=glorot_uniform for all 4 layers

        #You know the input size of your first convolution layer. Try messing around with the output size but make sure that the following
        #layers dimmensions line up. For your first convolution layer start with input = 1, output = 20, filter_dims = 5, stride = 5,
        #padding = 0

        self.dense1 = dense(180,
                            200,
                            weight_initializer=glorot_uniform,
                            weight_kwargs=init_kwargs)

        self.dense2 = dense(200,
                            10,
                            weight_initializer=glorot_uniform,
                            weight_kwargs=init_kwargs)

        self.conv1 = conv(1,
                          20, (5, 5),
                          stride=1,
                          padding=0,
                          weight_initializer=glorot_uniform,
                          weight_kwargs=init_kwargs)

        self.conv2 = conv(20,
                          20, (2, 2),
                          stride=2,
                          padding=0,
                          weight_initializer=glorot_uniform,
                          weight_kwargs=init_kwargs)

        self.dropout = dropout(self.dropout_prob)

        self.conv1.weight = Tensor(params[0])
        self.conv1.bias = Tensor(params[1])

        self.conv2.weight = Tensor(params[2])
        self.conv2.bias = Tensor(params[3])

        self.dense1.weight = Tensor(params[4])
        self.dense1.bias = Tensor(params[5])

        self.dense2.weight = Tensor(params[6])
        self.dense2.bias = Tensor(params[7])
Ejemplo n.º 5
0
 def __init__(self):
     self.dense1 = dense(2 * 68, 100, weight_initializer=glorot_normal)
     self.dense1.weight = new_parameters[0]
     self.dense1.bias = new_parameters[1]
     self.dense2 = dense(100, 10, weight_initializer=glorot_normal)
     self.dense2.weight = new_parameters[2]
     self.dense2.bias = new_parameters[3]
     self.dense3 = dense(10, 3, weight_initializer=glorot_normal)
     self.dense3.weight = new_parameters[4]
     self.dense3.bias = new_parameters[5]
Ejemplo n.º 6
0
 def __init__(self):
     self.conv1 = conv(1,
                       10,
                       5,
                       padding=0,
                       weight_initializer=glorot_uniform)
     self.conv2 = conv(5,
                       20,
                       5,
                       padding=0,
                       weight_initializer=glorot_uniform)
     self.dense1 = dense(290, 20, weight_initializer=glorot_uniform)
     self.dense2 = dense(20, 2, weight_initializer=glorot_uniform)
Ejemplo n.º 7
0
 def __init__(self):
     '''Hidden words is the hidden layer for each word iteration
        Hidden sentence is the hidden layer for each sentence iteration
        llayers is a list of all the layers
        L = length of embbedding array
        Unknown Words is a safety in case the word is not in the embedding
        GRUU is the update function of the GRU
        GRUR is the reset function of the GRU
        '''
     L = 0
     self.L = L
     self.hiddenwordsF = [np.zeros((L))]
     self.hiddensentenceF = [np.zeros((L))]
     self.hiddenwordsB = [np.zeros((L))]
     self.hiddensentenceB = [np.zeros((L))]
     self.llayers = []
     self.unknownwords = []
     self.GRUUW = dense(L, L)
     self.GRURW = dense(L, L)
     self.GRUHW = dense(L, L)
     self.GRUUS = dense(L, L)
     self.GRURS = dense(L, L)
     self.GRUHS = dense(L, L)
     self.EntireDocument = dense(2 * L,
                                 )  # Used for the logistical binary layer
     self.Content = dense(2 * L)
     self.salience
     self.novelty
     self.AbsolutePos
     self.RelativePos
Ejemplo n.º 8
0
    def __init__(self, d_data, d_embed):
        """
        Initializes the layers in the model.

        Parametersv
        ----------
        d_desc : int
            dimension of the descriptor vector.

        d_embed : int
            dimension of the embedding
        """
        self.dense1 = dense(d_data, 1500, weight_initializer=normal)
        self.dense2 = dense(1500, 1000, weight_initializer=normal)
        self.dense3 = dense(1000, d_embed, weight_initializer=normal)
Ejemplo n.º 9
0
    def __init__(self, d_in, d_out):
        """

        :param d_in: int dimensions in
        :param d_out: int dimensions out
        """
        self.dense1 = dense(d_in, d_out, weight_initializer=glorot_normal)
Ejemplo n.º 10
0
    def __init__(self):
        self.conv1 = conv(1,
                          50,
                          3,
                          3,
                          stride=1,
                          weight_initializer=glorot_uniform)
        self.conv2 = conv(50,
                          20,
                          3,
                          3,
                          stride=1,
                          weight_initializer=glorot_uniform)
        self.dense1 = dense(180, 50, weight_initializer=glorot_uniform)
        self.dense2 = dense(50, 29, weight_initializer=glorot_uniform)

        pass
    def __init__(self, dim_input, dim_recurrent, dim_output):
        """ Initializes all layers needed for RNN

        Parameters
        ----------
        dim_input: int
            Dimensionality of data passed to RNN (C)

        dim_recurrent: int
            Dimensionality of hidden state in RNN (D)

        dim_output: int
            Dimensionality of output of RNN (K)
        """

        self.fc_x2h = dense(dim_input,
                            dim_recurrent,
                            weight_initializer=glorot_normal)
        self.fc_h2h = dense(dim_recurrent,
                            dim_recurrent,
                            weight_initializer=glorot_normal,
                            bias=False)
        self.fc_h2y = dense(dim_recurrent,
                            dim_output,
                            weight_initializer=glorot_normal)
        self.Uz = mg.Tensor(
            np.random.randn(dim_input * dim_recurrent).reshape(
                dim_input, dim_recurrent))
        self.Wz = mg.Tensor(
            np.random.randn(dim_recurrent * dim_recurrent).reshape(
                dim_recurrent, dim_recurrent))
        self.bz = mg.Tensor(np.random.randn(dim_recurrent))
        self.Ur = mg.Tensor(
            np.random.randn(dim_input * dim_recurrent).reshape(
                dim_input, dim_recurrent))
        self.Wr = mg.Tensor(
            np.random.randn(dim_recurrent * dim_recurrent).reshape(
                dim_recurrent, dim_recurrent))
        self.br = mg.Tensor(np.random.randn(dim_recurrent))
        self.Uh = mg.Tensor(
            np.random.randn(dim_input * dim_recurrent).reshape(
                dim_input, dim_recurrent))
        self.Wh = mg.Tensor(
            np.random.randn(dim_recurrent * dim_recurrent).reshape(
                dim_recurrent, dim_recurrent))
        self.bh = mg.Tensor(np.random.randn(dim_recurrent))
Ejemplo n.º 12
0
 def __init__(self, dim_input: int, dim_output: int):
     """
     Initializes the Img2Caption Linear Encoder
     Parameters
     ----------
     dim_input the dimensions of the input descriptor
     dim_output the dimensions of the encoded value
     """
     self.layer = dense(dim_input, dim_output)
Ejemplo n.º 13
0
    def __init__(self, dim_input, dim_recurrent, dim_output):
        """ Initializes all layers needed for RNN

        Parameters
        ----------
        dim_input: int
            Dimensionality of data passed to RNN (C)

        dim_recurrent: int
            Dimensionality of hidden state in RNN (D)

        dim_output: int
            Dimensionality of output of RNN (K)
        """
        self.fc_x2h = dense(dim_input, dim_recurrent, weight_initializer=glorot_normal)
        self.fc_h2h = dense(
            dim_recurrent, dim_recurrent, weight_initializer=glorot_normal, bias=False
        )
        self.fc_h2y = dense(dim_recurrent, dim_output, weight_initializer=glorot_normal)
Ejemplo n.º 14
0
 def __init__(self):
     #Check this: the 3s-- kernel size
     gain = {'gain': np.sqrt(2)}
     
     self.conv1 = conv(3, 20, (5,5), weight_initializer=glorot_uniform, 
   weight_kwargs=gain)
     self.conv2 = conv(20, 10, (5,5), weight_initializer=glorot_uniform, 
   weight_kwargs=gain)
     
     #Check the dimensions on this:
     self.dense3 = dense(49000 , 232, weight_initializer=glorot_uniform, 
   weight_kwargs=gain)
Ejemplo n.º 15
0
    def __init__(self):
        self.conv1 = conv(1,
                          50, (5, 5),
                          stride=5,
                          weight_initializer=glorot_uniform,
                          weight_kwargs=gain)
        self.conv2 = conv(50,
                          20, (2, 2),
                          stride=2,
                          weight_initializer=glorot_uniform,
                          weight_kwargs=gain)
        self.dense1 = dense(500,
                            50,
                            weight_initializer=glorot_uniform,
                            weight_kwargs=gain)
        self.dense2 = dense(50,
                            29,
                            weight_initializer=glorot_uniform,
                            weight_kwargs=gain)

        pass
Ejemplo n.º 16
0
 def __init__(self, dim_in=48, num_out=7, load=False):
     self.conv1 = conv(1, 32, 2, 2, stride=1, padding=0, weight_initializer=Model.init)
     self.conv2 = conv(32, 64, 3, 3, stride=2, padding=1, weight_initializer=Model.init)
     self.conv3 = conv(64, 128, 2, 2, stride=2, weight_initializer=Model.init)
     self.conv4 = conv(128, 256, 3, 3, stride=3, weight_initializer=Model.init)
     self.dense1 = dense(256, 512, weight_initializer=Model.init)
     self.dense2 = dense(512, num_out, weight_initializer=Model.init)
     if (load):
         data = np.load("data/npmodelParam.npz")
         self.conv1.weight = data["l1w"]
         self.conv1.bias = data["l1b"]
         self.conv2.weight = data["l2w"]
         self.conv2.bias = data["l2b"]
         self.conv3.weight = data["l3w"]
         self.conv3.bias = data["l3b"]
         self.conv4.weight = data["l4w"]
         self.conv4.bias = data["l4b"]
         self.dense1.weight = data["l5w"]
         self.dense1.bias = data["l5b"]
         self.dense2.weight = data["l6w"]
         self.dense2.bias = data["l6b"]
Ejemplo n.º 17
0
 def __init__(self, dim_input, dim_output):
     """This initializes the layer for our Linear Encoder, and sets it
     as an attribute of the model.
     
     Parameters
     ----------
     dim_input : int
         The size of our input
         
     dim_output : int
         The size of the output layer 
     """
     self.layer = dense(dim_input, dim_output)
Ejemplo n.º 18
0
 def __init__(self, d_feature, d_embed):
     """
     Initializes all of the layers in our model and sets
     them as attributes of the model.
     
     Parameters
     ----------
     d_feature : int
         The dimension of the image feature vector.
     
     d_embed : int
         The dimension of the semantic embedding (i.e. the reduced
         dimensionality).
     """
     self.encode = dense(d_feature, d_embed, weight_initializer=normal)
Ejemplo n.º 19
0
 def __init__(self, dim_input=512, dim_encoded=50):
     """This initializes the single layer in our model, and sets it
     as an attribute of the model.
     
     
     Parameters
     ----------
     dim_input : int
         the size of the inputs
         
     dum_encoded : int
         the size of the outputs of the encoded layer
     
     
     """
     self.dense1 = dense(dim_input, dim_encoded, weight_initializer=he_normal)
Ejemplo n.º 20
0
    def __init__(
            self, dim_input,
            dim_output):  #default dim_input should be 512, output should be 50
        """ Initializes all layers needed for RNN
        
        Parameters
        ----------
        dim_input: int
            Dimensionality of data passed to RNN
        
        
        dim_output: int
            Dimensionality of output of RNN
        """

        self.dense1 = dense(dim_input,
                            dim_output,
                            weight_initializer=he_normal)
Ejemplo n.º 21
0
 def __init__(self):
     self.dense1 = dense(512, 50)
 def __init__(self, dim_in, num_hidden, dim_out):
   self.d1 = dense(dim_in, num_hidden, weight_initializer=glorot_normal)
   self.d2 = dense(num_hidden, dim_out, weight_initializer=glorot_normal)
Ejemplo n.º 23
0
    def __init__(self):
        """ This initializes all of the layers in our model, and sets them
        as attributes of the model.

        """
        self.dense1 = dense(512, 50)
Ejemplo n.º 24
0
 def __init__(self, dim_input, dim_output):
     """ Initialize the model. """
     self.layer = dense(dim_input, dim_output, weight_initializer=normal)
Ejemplo n.º 25
0
    def __init__(self, D_full, D_out):

        self.dense1 = dense(D_full,
                            D_out,
                            weight_initializer=he_normal,
                            bias=True)
Ejemplo n.º 26
0
 def __init__(self,num_in, num_out):
     self.dense=dense(num_in, num_out, weight_initializer=glorot_normal)
Ejemplo n.º 27
0
 def __init__(self):
     self.dense1 = dense(1, 20, weight_initializer=normal)
     self.dense2 = dense(20, 30, weight_initializer=normal)
     self.dense3 = dense(30, 20, weight_initializer=normal)
     self.dense4 = dense(20, 1, weight_initializer=normal)