當前位置: 首頁>>代碼示例>>Python>>正文


Python dynet.cmult方法代碼示例

本文整理匯總了Python中dynet.cmult方法的典型用法代碼示例。如果您正苦於以下問題:Python dynet.cmult方法的具體用法?Python dynet.cmult怎麽用?Python dynet.cmult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dynet的用法示例。


在下文中一共展示了dynet.cmult方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _upsample_old

# 需要導入模塊: import dynet [as 別名]
# 或者: from dynet import cmult [as 別名]
def _upsample_old(self, mgc, start, stop):
        mgc_index = start / len(self.upsample_w_t)
        ups_index = start % len(self.upsample_w_t)
        upsampled = []
        mgc_vect = dy.inputVector(mgc[mgc_index])
        for x in range(stop - start):
            # sigm = dy.logistic(self.upsample_w_s[ups_index].expr(update=True) * mgc_vect + self.upsample_b_s[ups_index].expr(update=True))
            tnh = dy.tanh(self.upsample_w_t[ups_index].expr(update=True) * mgc_vect + self.upsample_b_t[ups_index].expr(
                update=True))
            # r = dy.cmult(sigm, tnh)
            upsampled.append(tnh)
            ups_index += 1
            if ups_index == len(self.upsample_w_t):
                ups_index = 0
                mgc_index += 1
                if mgc_index == len(
                        mgc):  # last frame is sometimes not processed, but it should have similar parameters
                    mgc_index -= 1
                else:
                    mgc_vect = dy.inputVector(mgc[mgc_index])
        return upsampled 
開發者ID:tiberiu44,項目名稱:TTS-Cube,代碼行數:23,代碼來源:vocoder_old.py

示例2: _upsample

# 需要導入模塊: import dynet [as 別名]
# 或者: from dynet import cmult [as 別名]
def _upsample(self, mgc, start, stop):
        mgc_index = start / len(self.upsample_w_s)
        ups_index = start % len(self.upsample_w_s)
        upsampled = []
        mgc_vect = dy.inputVector(mgc[mgc_index])
        for x in range(stop - start):
            sigm = dy.logistic(
                self.upsample_w_s[ups_index].expr(update=True) * mgc_vect + self.upsample_b_s[ups_index].expr(
                    update=True))
            tnh = dy.tanh(self.upsample_w_t[ups_index].expr(update=True) * mgc_vect + self.upsample_b_t[ups_index].expr(
                update=True))
            r = dy.cmult(sigm, tnh)
            upsampled.append(r)
            ups_index += 1
            if ups_index == len(self.upsample_w_s):
                ups_index = 0
                mgc_index += 1
                if mgc_index == len(
                        mgc):  # last frame is sometimes not processed, but it should have similar parameters
                    mgc_index -= 1
                else:
                    mgc_vect = dy.inputVector(mgc[mgc_index])
        return upsampled 
開發者ID:tiberiu44,項目名稱:TTS-Cube,代碼行數:25,代碼來源:vocoder_old.py

示例3: word_repr

# 需要導入模塊: import dynet [as 別名]
# 或者: from dynet import cmult [as 別名]
def word_repr(self, char_seq, cembs):
        # obtain the word representation when given its character sequence

        wlen = len(char_seq)
        if 'rgW%d'%wlen not in self.param_exprs:
            self.param_exprs['rgW%d'%wlen] = dy.parameter(self.params['reset_gate_W'][wlen-1])
            self.param_exprs['rgb%d'%wlen] = dy.parameter(self.params['reset_gate_b'][wlen-1])
            self.param_exprs['cW%d'%wlen] = dy.parameter(self.params['com_W'][wlen-1])
            self.param_exprs['cb%d'%wlen] = dy.parameter(self.params['com_b'][wlen-1])

        chars = dy.concatenate(cembs)
        reset_gate = dy.logistic(self.param_exprs['rgW%d'%wlen] * chars + self.param_exprs['rgb%d'%wlen])
        word = dy.tanh(self.param_exprs['cW%d'%wlen] * dy.cmult(reset_gate,chars) + self.param_exprs['cb%d'%wlen])
        if self.known_words is not None and tuple(char_seq) in self.known_words:
            return (word + dy.lookup(self.params['word_embed'],self.known_words[tuple(char_seq)]))/2.
        return word 
開發者ID:jcyk,項目名稱:greedyCWS,代碼行數:18,代碼來源:model.py

示例4: add_input

# 需要導入模塊: import dynet [as 別名]
# 或者: from dynet import cmult [as 別名]
def add_input(self, input_vec):
            """
            Note that this function updates the existing State object!
            """
            x = dynet.concatenate([input_vec, self.h])

            i = dynet.logistic(self.W_i * x + self.b_i)
            f = dynet.logistic(self.W_f * x + self.b_f)
            g = dynet.tanh(self.W_c * x + self.b_c)
            o = dynet.logistic(self.W_o * x + self.b_o)

            c = dynet.cmult(f, self.c) + dynet.cmult(i, g)
            h = dynet.cmult(o, dynet.tanh(c))

            self.c = c
            self.h = h
            self.outputs.append(h)

            return self 
開發者ID:jhcross,項目名稱:span-parser,代碼行數:21,代碼來源:network.py

示例5: loss

# 需要導入模塊: import dynet [as 別名]
# 或者: from dynet import cmult [as 別名]
def loss(self, sentence, word_chars, tags_set):
        '''
        For use in training phase.
        Tag sentence (all attributes) and compute loss based on probability of expected tags.
        '''
        observations_set = self.build_tagging_graph(sentence, word_chars)
        errors = {}
        for att, tags in tags_set.items():
            err = []
            for obs, tag in zip(observations_set[att], tags):
                err_t = dy.pickneglogsoftmax(obs, tag)
                err.append(err_t)
            errors[att] = dy.esum(err)
        if self.att_props is not None:
            for att, err in errors.items():
                prop_vec = dy.inputVector([self.att_props[att]] * err.dim()[0])
                err = dy.cmult(err, prop_vec)
        return errors 
開發者ID:yuvalpinter,項目名稱:Mimick,代碼行數:20,代碼來源:model.py

示例6: dyagonalize

# 需要導入模塊: import dynet [as 別名]
# 或者: from dynet import cmult [as 別名]
def dyagonalize(col):
    """
    A convoluted way to make a dynet vector into a dynet matrix where it's the diagonal
    God I hope there's a better way.
    :param col: column vector in dynet format
    """
    col_dim = col.dim()[0][0]
    nump_eye = np.eye(col_dim)
    return dy.cmult(col, dy.inputTensor(nump_eye)) 
開發者ID:yuvalpinter,項目名稱:m3gm,代碼行數:11,代碼來源:math_utils.py

示例7: word_assoc_score

# 需要導入模塊: import dynet [as 別名]
# 或者: from dynet import cmult [as 別名]
def word_assoc_score(self, source_idx, target_idx, relation):
        """
        NOTE THAT DROPOUT IS BEING APPLIED HERE
        :param source_idx: embedding index of source atom
        :param target_idx: embedding index of target atom
        :param relation: relation type
        :return: score
        """
        # prepare
        s = self.embeddings[source_idx]
        if self.no_assoc:
            A = dy.const_parameter(self.word_assoc_weights[relation])
        else:
            A = dy.parameter(self.word_assoc_weights[relation])
        dy.dropout(A, self.dropout)
        t = self.embeddings[target_idx]
        
        # compute
        if self.mode == BILINEAR_MODE:
            return dy.transpose(s) * A * t
        elif self.mode == DIAG_RANK1_MODE:
            diag_A = dyagonalize(A[0])
            rank1_BC = A[1] * dy.transpose(A[2])
            ABC = diag_A + rank1_BC
            return dy.transpose(s) * ABC * t
        elif self.mode == TRANSLATIONAL_EMBED_MODE:
            return -dy.l2_norm(s - t + A)
        elif self.mode == DISTMULT:
            return dy.sum_elems(dy.cmult(dy.cmult(s, A), t)) 
開發者ID:yuvalpinter,項目名稱:m3gm,代碼行數:31,代碼來源:pretrain_assoc.py

示例8: _predict_one

# 需要導入模塊: import dynet [as 別名]
# 或者: from dynet import cmult [as 別名]
def _predict_one(self, mgc, noise):
        mgc = dy.inputVector(mgc)
        outputs = []

        noise_vec = dy.inputVector(noise[0:self.UPSAMPLE_COUNT])
        [hidden_w, hidden_b] = self.mlp_excitation
        hidden_input = mgc  # dy.concatenate([mgc, noise_vec])
        for w, b in zip(hidden_w, hidden_b):
            hidden_input = dy.tanh(w.expr(update=True) * hidden_input + b.expr(update=True))
        excitation = dy.logistic(
            self.excitation_w.expr(update=True) * hidden_input + self.excitation_b.expr(update=True))

        [hidden_w, hidden_b] = self.mlp_filter
        hidden_input = mgc  # dy.concatenate([mgc, noise_vec])
        for w, b in zip(hidden_w, hidden_b):
            hidden_input = dy.tanh(w.expr(update=True) * hidden_input + b.expr(update=True))
        filter = dy.tanh(self.filter_w.expr(update=True) * hidden_input + self.filter_b.expr(update=True))

        [hidden_w, hidden_b] = self.mlp_vuv
        hidden_input = mgc  # dy.concatenate([mgc, noise_vec])
        for w, b in zip(hidden_w, hidden_b):
            hidden_input = dy.tanh(w.expr(update=True) * hidden_input + b.expr(update=True))
        vuv = dy.logistic(self.vuv_w.expr(update=True) * hidden_input + self.vuv_b.expr(update=True))

        # sample_vec = dy.inputVector(noise[self.UPSAMPLE_COUNT:self.UPSAMPLE_COUNT * 2])

        # noise_vec = dy.inputVector(noise[0:self.UPSAMPLE_COUNT + self.FILTER_SIZE - 1])
        mixed = excitation  # * vuv + noise_vec * (1.0 - vuv)
        for ii in range(self.UPSAMPLE_COUNT):
            tmp = dy.cmult(filter, dy.pickrange(mixed, ii, ii + self.FILTER_SIZE))
            outputs.append(dy.sum_elems(tmp))
        outputs = dy.concatenate(outputs)
        # from ipdb import set_trace
        # set_trace()
        # mixed = dy.reshape(mixed, (self.UPSAMPLE_COUNT + self.FILTER_SIZE - 1, 1, 1))
        # filter = dy.reshape(filter, (self.FILTER_SIZE, 1, 1, 1))
        # outputs = dy.conv2d(mixed, filter, stride=(1, 1), is_valid=True)
        # outputs = dy.reshape(outputs, (self.UPSAMPLE_COUNT,))
        # outputs = outputs + noise_vec * vuv

        return outputs, excitation, filter, vuv 
開發者ID:tiberiu44,項目名稱:TTS-Cube,代碼行數:43,代碼來源:vocoder_old.py

示例9: _fast_sample

# 需要導入模塊: import dynet [as 別名]
# 或者: from dynet import cmult [as 別名]
def _fast_sample(self, prob, temperature=1):
        temperature = temperature / 2
        bern = dy.random_bernoulli(256, 0.5, scale=temperature) + (1.0 - temperature)
        prob = dy.cmult(prob, bern)
        # print prob.npvalue().argmax()
        return prob.npvalue().argmax() 
開發者ID:tiberiu44,項目名稱:TTS-Cube,代碼行數:8,代碼來源:vocoder_old.py

示例10: __call__

# 需要導入模塊: import dynet [as 別名]
# 或者: from dynet import cmult [as 別名]
def __call__(self, *args):
        U = [dy.parameter(U_) for U_ in self.U]

        out = U[0] * args[0]
        for x, u in zip(args[1:], U[1:]):
            out = dy.cmult(out, u * x)

        out = dy.sum_cols(dy.transpose(out))
        return out

    # dynet is confused by lists of params, have to drop it manually 
開發者ID:vene,項目名稱:marseille,代碼行數:13,代碼來源:dynet_utils.py

示例11: __call__

# 需要導入模塊: import dynet [as 別名]
# 或者: from dynet import cmult [as 別名]
def __call__(self, query, options, gold, lengths, query_no):
        if len(options) == 1:
            return None, 0

        final = []
        if args.word_vectors:
            qvecs = [dy.lookup(self.pEmbedding, w) for w in query]
            qvec_max = dy.emax(qvecs)
            qvec_mean = dy.average(qvecs)
        for otext, features in options:
            inputs = dy.inputTensor(features)
            if args.word_vectors:
                ovecs = [dy.lookup(self.pEmbedding, w) for w in otext]
                ovec_max = dy.emax(ovecs)
                ovec_mean = dy.average(ovecs)
                inputs = dy.concatenate([inputs, qvec_max, qvec_mean, ovec_max, ovec_mean])
            if args.drop > 0:
                inputs = dy.dropout(inputs, args.drop)
            h = inputs
            for pH, pB in zip(self.hidden, self.bias):
                h = dy.affine_transform([pB, pH, h])
                if args.nonlin == "linear":
                    pass
                elif args.nonlin == "tanh":
                    h = dy.tanh(h)
                elif args.nonlin == "cube":
                    h = dy.cube(h)
                elif args.nonlin == "logistic":
                    h = dy.logistic(h)
                elif args.nonlin == "relu":
                    h = dy.rectify(h)
                elif args.nonlin == "elu":
                    h = dy.elu(h)
                elif args.nonlin == "selu":
                    h = dy.selu(h)
                elif args.nonlin == "softsign":
                    h = dy.softsign(h)
                elif args.nonlin == "swish":
                    h = dy.cmult(h, dy.logistic(h))
            final.append(dy.sum_dim(h, [0]))

        final = dy.concatenate(final)
        nll = -dy.log_softmax(final)
        dense_gold = []
        for i in range(len(options)):
            dense_gold.append(1.0 / len(gold) if i in gold else 0.0)
        answer = dy.inputTensor(dense_gold)
        loss = dy.transpose(answer) * nll
        predicted_link = np.argmax(final.npvalue())

        return loss, predicted_link 
開發者ID:dstc8-track2,項目名稱:NOESIS-II,代碼行數:53,代碼來源:disentangle.py


注:本文中的dynet.cmult方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。