当前位置: 首页>>代码示例>>Python>>正文


Python misc.random_weight_matrix函数代码示例

本文整理汇总了Python中misc.random_weight_matrix函数的典型用法代码示例。如果您正苦于以下问题:Python random_weight_matrix函数的具体用法?Python random_weight_matrix怎么用?Python random_weight_matrix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了random_weight_matrix函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, L0, D0, U0=None,
                 alpha=0.005, rseed=10, bptt=1):

        self.hdim = L0.shape[1] # word vector dimensions
        self.vdim = L0.shape[0] # vocab size
        self.ddim = D0.shape[0] # doc size
        param_dims = dict(H = (self.hdim, self.hdim),
                          U = L0.shape, G = L0.shape)
        # note that only L gets sparse updates
        param_dims_sparse = dict(L = L0.shape, D = D0.shape)
        NNBase.__init__(self, param_dims, param_dims_sparse)

        #### YOUR CODE HERE ####

        self.bptt = bptt
        self.alpha = alpha

        # Initialize word vectors
        self.sparams.L = L0.copy()
        self.sparams.D = D0.copy()

        self.params.U = random.randn(self.vdim, self.hdim)*0.1

        # Initialize H matrix, as with W and U in part 1
        self.params.H = random_weight_matrix(self.hdim, self.hdim)
        self.params.G = random_weight_matrix(self.vdim, self.hdim)
开发者ID:afgiel,项目名称:docvec,代码行数:26,代码来源:drnnlm.py

示例2: __init__

    def __init__(self, hdim, outdim, alpha=.005, rho=.0001, rseed=10):
        
        # Dimensions
        self.hdim = hdim
        self.outdim = outdim
        self.out_end = outdim # the end token

        # Parameters
        np.random.seed(rseed)

        # Learning rate
        self.alpha = alpha

        # Regularization
        self.rho = rho


        ## Theano stuff

        # Params as theano.shared matrices
        self.Wh = shared(random_weight_matrix(hdim, hdim), name='Wh')
        self.U  = shared(random_weight_matrix(outdim, hdim), name='U')
        self.b  = shared(np.zeros([outdim, 1]), name='b', broadcastable=(False, True))

        self.params = [self.Wh, self.U, self.b]
        self.vparams = [0.0*param.get_value() for param in self.params]
开发者ID:arthur-tsang,项目名称:EqnMaster,代码行数:26,代码来源:rnn_dec.py

示例3: __init__

    def __init__(self, hdim, outdim,
                 alpha=0.005, rho = 0.0001, rseed=10):

        # Dimensions
        self.hdim = hdim
        self.outdim = outdim

        # Parameters
        np.random.seed(rseed)
        sigma = .1

        self.params = {}
        #self.params['L'] = np.random.normal(0, sigma, (wdim, vdim)) # "wide" array
        self.params['Wh'] = random_weight_matrix(hdim, hdim)
        #self.params['Wx'] = random_weight_matrix(hdim, wdim)
        # for now, not using xs
        self.params['b1'] = np.zeros(hdim)
        self.params['U'] = random_weight_matrix(outdim, hdim)
        self.params['b2'] = np.zeros(outdim)

        # Learning rate
        self.alpha = alpha

        # Regularization
        self.rho = rho

        # Store hs and yhats
        self.hs = None
        self.yhats = None

        # grads
        self.grads = {}
开发者ID:arthur-tsang,项目名称:EqnMaster,代码行数:32,代码来源:dec.py

示例4: __init__

    def __init__(self, hdim, outdim, alpha=.005, rho=.0001, rseed=10):
        
        # Dimensions
        self.hdim = hdim
        self.outdim = outdim
        self.out_end = outdim # the end token

        # Parameters
        np.random.seed(rseed)

        # Learning rate
        self.alpha = alpha

        # Regularization
        self.rho = rho


        ## Theano stuff

        # Params as theano.shared matrices
        # W: times character-vector, U: times previous-hidden-vector
        # i: input, f: forget, o: output, c: new-cell
        self.Uz = shared(random_weight_matrix(hdim, hdim), name='Uz')
        self.Ur = shared(random_weight_matrix(hdim, hdim), name='Ur')
        self.Uh = shared(random_weight_matrix(hdim, hdim), name='Uh')
        self.U  = shared(random_weight_matrix(outdim, hdim), name='U')
        self.b  = shared(np.zeros([outdim, 1]), name='b', broadcastable=(False, True))

        self.params = [self.Uz, self.Ur, self.Uh, self.U, self.b]
        self.vparams = [0.0*param.get_value() for param in self.params]
开发者ID:arthur-tsang,项目名称:EqnMaster,代码行数:30,代码来源:new_dec.py

示例5: __init__

    def __init__(self, L0, U0=None,alpha=0.005, lreg = 0.00001, rseed=10, bptt=1):

        self.hdim = L0.shape[1] # word vector dimensions
        self.vdim = L0.shape[0] # vocab size
        param_dims = dict(H = (self.hdim, self.hdim), W = (self.hdim,self.hdim))
                          #,U = L0.shape)
        # note that only L gets sparse updates
        param_dims_sparse = dict(L = L0.shape)
        NNBase.__init__(self, param_dims, param_dims_sparse)

        self.alpha = alpha
        self.lreg = lreg
        #### YOUR CODE HERE ####
        
        # Initialize word vectors
        # either copy the passed L0 and U0 (and initialize in your notebook)
        # or initialize with gaussian noise here

        # Initialize H matrix, as with W and U in part 1
        self.bptt = bptt
        random.seed(rseed)
        self.params.H = random_weight_matrix(*self.params.H.shape)
        self.params.W = random_weight_matrix(*self.params.W.shape)
        #self.params.U = 0.1*np.random.randn(*L0.shape)
        self.sparams.L = L0.copy()
开发者ID:alphadl,项目名称:cs224d,代码行数:25,代码来源:rnnlmWithHierarchicalSoftmax.py

示例6: __init__

    def __init__(self, vdim, hdim, wdim, alpha=.005, rho=.0001, rseed=10):
        
        # Dimensions
        self.vdim = vdim
        self.hdim = hdim
        self.wdim = wdim

        # Parameters
        np.random.seed(rseed)

        # Learning rate
        self.alpha = alpha

        # Regularization
        self.rho = rho


        ## Theano stuff

        # Params as theano.shared matrices
        self.L = shared(random_weight_matrix(wdim, vdim), name='L')
        self.Wx = shared(random_weight_matrix(hdim, wdim), name='Wx')
        self.Wh = shared(random_weight_matrix(hdim, hdim), name='Wh')


        self.params = [self.L, self.Wx, self.Wh]
        self.vparams = [0.0*param.get_value() for param in self.params]
开发者ID:arthur-tsang,项目名称:EqnMaster,代码行数:27,代码来源:rnn_enc.py

示例7: __init__

    def __init__(self, L0, U0=None,
                 alpha=0.005, rseed=10):

        self.hdim = L0.shape[1] # word vector dimensions
        self.vdim = L0.shape[0] # vocab size
        param_dims = dict(LH = (self.hdim, self.hdim),
                          RH = (self.hdim, self.hdim),
                          U = (self.vdim, self.hdim * 2))
        # note that only L gets sparse updates
        param_dims_sparse = dict(LL = L0.shape, RL = L0.shape)
        NNBase.__init__(self, param_dims, param_dims_sparse)

        #### YOUR CODE HERE ####
        np.random.seed(rseed) # be sure to seed this for repeatability!
        self.alpha = alpha

        # Initialize word vectors
        # either copy the passed L0 and U0 (and initialize in your notebook)
        # or initialize with gaussian noise here
        #self.sparams.LL = np.random.randn(*L0.shape) * np.sqrt(0.1)
        #self.sparams.RL = np.random.randn(*L0.shape) * np.sqrt(0.1)
        self.sparams.LL = L0
        self.sparams.RL = L0
        self.params.U = np.random.randn(self.vdim, self.hdim*2) * np.sqrt(0.1)

        # Initialize H matrix, as with W and U in part 1
        self.params.LH = random_weight_matrix(self.hdim, self.hdim)
        self.params.RH = random_weight_matrix(self.hdim, self.hdim)
开发者ID:nishithbsk,项目名称:SentenceGeneration,代码行数:28,代码来源:brnnlm.py

示例8: __init__

    def __init__(self, L0, Dy=N_ASPECTS*SENT_DIM, U0=None,
                 alpha=0.005, rseed=10, bptt=5):

        self.hdim = L0.shape[1] # word vector dimensions
        self.vdim = L0.shape[0] # vocab size
        self.ydim = Dy
        param_dims = dict(H = (self.hdim, self.hdim),
                          U = (self.ydim, self.hdim),
                          b1 = (self.hdim,),
                          b2 =(self.ydim,))
        # note that only L gets sparse updates
        param_dims_sparse = dict(L = L0.shape)
        NNBase.__init__(self, param_dims, param_dims_sparse)

        #### YOUR CODE HERE ####
        var = .1
        sigma = sqrt(var)
        from misc import random_weight_matrix
        random.seed(rseed)
        # Initialize word vectors
        self.bptt = bptt
        self.alpha = alpha
        self.params.H=random_weight_matrix(*self.params.H.shape)
        if U0 is not None:
            self.params.U= U0.copy()
        else:
            self.params.U= random_weight_matrix(*self.params.U.shape)
        self.sparams.L = L0.copy()
        self.params.b1 = zeros((self.hdim,))
        self.params.b2 = zeros((self.ydim,))
开发者ID:laisun,项目名称:EntitySentiment,代码行数:30,代码来源:rnn_simple.py

示例9: __init__

    def __init__(self, vdim, hdim, wdim, outdim=2, alpha=.005, rho=.0001, mu=0.75, rseed=10):
        
        # Dimensions
        self.vdim = vdim
        self.hdim = hdim
        self.wdim = wdim
        self.outdim = outdim

        # Parameters
        np.random.seed(rseed)

        # Learning rate
        self.alpha = alpha
        self.mu = mu
        self.rho = rho
        self.rseed = rseed


        ## Theano stuff

        # Params as theano.shared matrices
        self.L = shared(random_weight_matrix(wdim, vdim), name='L')
        # W: times character-vector, U: times previous-hidden-vector
        self.Wx = shared(random_weight_matrix(hdim, wdim), name='Wx')
        self.Wh = shared(random_weight_matrix(wdim, wdim), name='Wh')
        self.U = shared(random_weight_matrix(outdim, hdim), name='U')
        self.b  = shared(np.zeros([outdim, 1]), name='b', broadcastable=(False, True))

        self.params = [self.L, self.Wx, self.Wh, self.U, self.b]
        self.vparams = [0.0*param.get_value() for param in self.params]

        self.prop_compiled = self.compile_self()
        self.generate_compiled = self.compile_generate()
开发者ID:arthur-tsang,项目名称:EqnMaster,代码行数:33,代码来源:d_rnn.py

示例10: __init__

    def __init__(self, vdim, hdim, wdim, alpha=.005, rho=.0001, rseed=10):
        
        # Dimensions
        self.vdim = vdim
        self.hdim = hdim
        self.wdim = wdim

        # Parameters
        np.random.seed(rseed)

        # Learning rate
        self.alpha = alpha

        # Regularization
        self.rho = rho


        ## Theano stuff

        # Params as theano.shared matrices
        self.L = shared(random_weight_matrix(wdim, vdim), name='L')
        # W: times character-vector, U: times previous-hidden-vector
        # i: input, f: forget, o: output, c: new-cell
        self.Wi = shared(random_weight_matrix(hdim, wdim), name='Wi')
        self.Ui = shared(random_weight_matrix(hdim, hdim), name='Ui')
        self.Wf = shared(random_weight_matrix(hdim, wdim), name='Wf')
        self.Uf = shared(random_weight_matrix(hdim, hdim), name='Uf')
        self.Wo = shared(random_weight_matrix(hdim, wdim), name='Wo')
        self.Uo = shared(random_weight_matrix(hdim, hdim), name='Uo')
        self.Wc = shared(random_weight_matrix(hdim, wdim), name='Wc')
        self.Uc = shared(random_weight_matrix(hdim, hdim), name='Uc')

        self.params = [self.L, self.Wi, self.Ui, self.Wf, self.Uf, self.Wo, self.Uo, self.Wc, self.Uc]
        self.vparams = [0.0*param.get_value() for param in self.params]
开发者ID:arthur-tsang,项目名称:EqnMaster,代码行数:34,代码来源:lstm_enc.py

示例11: __init__

    def __init__(self, wv, windowsize=3,
                 dims=[None, 100, 5],
                 reg=0.001, alpha=0.01, rseed=10):
        """
        Initialize classifier model.

        Arguments:
        wv : initial word vectors (array |V| x n)
            note that this is the transpose of the n x |V| matrix L
            described in the handout; you'll want to keep it in
            this |V| x n form for efficiency reasons, since numpy
            stores matrix rows continguously.
        windowsize : int, size of context window
        dims : dimensions of [input, hidden, output]
            input dimension can be computed from wv.shape
        reg : regularization strength (lambda)
        alpha : default learning rate
        rseed : random initialization seed
        """

        # Set regularization
        self.lreg = float(reg)
        self.alpha = alpha # default training rate

        dims[0] = windowsize * wv.shape[1] # input dimension
        param_dims = dict(W=(dims[1], dims[0]),
                          b1=(dims[1],),
                          U=(dims[2], dims[1]),
                          b2=(dims[2],),
                          )
        param_dims_sparse = dict(L=wv.shape)

        # initialize parameters: don't change this line
        NNBase.__init__(self, param_dims, param_dims_sparse)

        random.seed(rseed) # be sure to seed this for repeatability!
        #### YOUR CODE HERE ####

        # any other initialization you need
        #self.sparams, self.grads, self.param, self.sgrads
        #where are they defined?
        #为什么可以直接可以使用?
        self.sparams.L = wv.copy()
        #self.sparam.L = wv.copy()
        self.params.U = random_weight_matrix(*param_dims["U"])
        #self.param.U = random_weight_matrix(param_dims["U"])
        self.params.W = random_weight_matrix(*param_dims["W"])
        #self.param.b1 = zeros(param_dims["b1"])
        #self.param.b2 = zeros(param_dims["b2"])
        self.windowSize = windowsize
        self.wordVecLen = wv.shape[1]
        self.wordVecNum = wv.shape[0]
开发者ID:NeighborhoodWang,项目名称:CS224D-problem-set2,代码行数:52,代码来源:nerwindow.py

示例12: __init__

    def __init__(self, wv, windowsize=3,
                 dims=[None, 100, 5],
                 reg=0.001, alpha=0.01, rseed=10):
        """
        Initialize classifier model.

        Arguments:
        wv : initial word vectors (array |V| x n)
            note that this is the transpose of the n x |V| matrix L
            described in the handout; you'll want to keep it in
            this |V| x n form for efficiency reasons, since numpy
            stores matrix rows continguously.
        windowsize : int, size of context window
        dims : dimensions of [input, hidden, output]
            input dimension can be computed from wv.shape
        reg : regularization strength (lambda)
        alpha : default learning rate
        rseed : random initialization seed
        """

        # Set regularization
        self.lreg = float(reg)
        self.alpha = alpha # default training rate

        dims[0] = windowsize * wv.shape[1]         # input dimension
        param_dims = dict(W1=(dims[1], dims[0]),   # 100 x 150
                          b2=(dims[1],),           # 100 x 1
                          W2=(dims[2], dims[1]),   # 5 X 100
                          b3=(dims[2],),           # 5 x 1
                          )

        param_dims_sparse = dict(L=wv.shape)       # |V| x 50

        # initialize parameters: don't change this line
        NNBase.__init__(self, param_dims, param_dims_sparse)

        random.seed(rseed) # be sure to seed this for repeatability!
        #### YOUR CODE HERE ####
        self.sparams.L = wv.copy();

        self.params.W1 = random_weight_matrix(param_dims['W1'][0], param_dims['W1'][1])

        self.params.b2 = append([], random_weight_matrix(param_dims['b2'][0], 1))
        self.params.b3 = append([], random_weight_matrix(param_dims['b3'][0], 1))
        self.params.W2 = random_weight_matrix(param_dims['W2'][0], param_dims['W2'][1])
        self.n = wv.shape[1]

        # informational
        self.windowsize = windowsize
        self.hidden_units = dims[1]
开发者ID:kireet,项目名称:cs224d,代码行数:50,代码来源:nerwindow.py

示例13: __init__

    def __init__(self, L0, U0=None,
                 alpha=0.005, rseed=10, bptt=1):

        self.hdim = L0.shape[1] # word vector dimensions      |D|
        self.vdim = L0.shape[0] # vocab size                  |V|
        param_dims = dict(H = (self.hdim, self.hdim),
                          U = L0.shape)
        # note that only L gets sparse updates
        param_dims_sparse = dict(L = L0.shape)
        NNBase.__init__(self, param_dims, param_dims_sparse)

        #### YOUR CODE HERE ####


        # Initialize word vectors
        # either copy the passed L0 and U0 (and initialize in your notebook)
        # or initialize with gaussian noise here
        self.sparams.L = 0.1 * random.standard_normal(self.sparams.L.shape)
        # self.params.U
        self.params.U = 0.1 * random.standard_normal(self.params.U.shape)
        # Initialize H matrix, as with W and U in part 1
        # self.params.H = random_weight_matrix(*self.params.H.shape)
        self.params.H = random_weight_matrix(*self.params.H.shape)

        self.bptt = bptt
        self.alpha = alpha
开发者ID:icodingc,项目名称:CS224d,代码行数:26,代码来源:rnnlm.py

示例14: __init__

    def __init__(self, L0, U0=None,
                 alpha=0.005, rseed=10, bptt=1):

        self.hdim = L0.shape[1] # word vector dimensions
        self.vdim = L0.shape[0] # vocab size
        param_dims = dict(H = (self.hdim, self.hdim),
                          U = L0.shape)
        # note that only L gets sparse updates
        param_dims_sparse = dict(L = L0.shape)
        NNBase.__init__(self, param_dims, param_dims_sparse)

        #### YOUR CODE HERE ####


        # Initialize word vectors
        # either copy the passed L0 and U0 (and initialize in your notebook)
        # or initialize with gaussian noise here
        # Initialize H matrix, as with W and U in part 1
        self.sparams.L = L0.copy()
        if U0 is None:
            self.params.U = random.normal(0, 0.1, param_dims['U'])
        else:
            self.params.U = U0.copy()
        self.params.H = random_weight_matrix(*param_dims['H'])
        self.alpha = alpha
#        self.rseed = rseed
        self.bptt = bptt
开发者ID:ZhengXuxiao,项目名称:DLforNLP,代码行数:27,代码来源:rnnlm.py

示例15: __init__

    def __init__(self, L0, U0=None,
                 alpha=0.005, rseed=10, bptt=1):
        random.seed(rseed)
        self.hdim = L0.shape[1] # word vector dimensions
        self.vdim = L0.shape[0] # vocab size
        param_dims = dict(H = (self.hdim, self.hdim),
                          U = L0.shape)
        # note that only L gets sparse updates
        param_dims_sparse = dict(L = L0.shape)
        NNBase.__init__(self, param_dims, param_dims_sparse)

        #### YOUR CODE HERE ####
        self.sparams.L = L0.copy()
        self.params.H = random_weight_matrix(self.hdim, self.hdim)
        self.alpha = alpha
        self.bptt = bptt


        # Initialize word vectors
        # either copy the passed L0 and U0 (and initialize in your notebook)
        # or initialize with gaussian noise here
        if U0 is not None:
            self.params.U = U0.copy()
        else:
            sigma = 0.1
            mu = 0
            #self.params.U = random.normal(mu, sigma, (self.vdim, self.hdim))
            self.params.U = sigma*random.randn(self.vdim, self.hdim) + mu
开发者ID:janenie,项目名称:rnn_research,代码行数:28,代码来源:rnnlm.py


注:本文中的misc.random_weight_matrix函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。