当前位置: 首页>>代码示例>>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;未经允许,请勿转载。