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


Python nanguardmode.NanGuardMode方法代碼示例

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


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

示例1: test_NanGuardMode

# 需要導入模塊: from theano.compile import nanguardmode [as 別名]
# 或者: from theano.compile.nanguardmode import NanGuardMode [as 別名]
def test_NanGuardMode():
    """
    Tests if NanGuardMode is working by feeding in numpy.inf and numpy.nans
    intentionally. A working implementation should be able to capture all
    the abnormalties.
    """
    x = T.matrix()
    w = theano.shared(numpy.random.randn(5, 7).astype(theano.config.floatX))
    y = T.dot(x, w)

    fun = theano.function(
        [x], y,
        mode=NanGuardMode(nan_is_error=True, inf_is_error=True)
    )
    a = numpy.random.randn(3, 5).astype(theano.config.floatX)
    infa = numpy.tile(
        (numpy.asarray(100.) ** 1000000).astype(theano.config.floatX), (3, 5))
    nana = numpy.tile(
        numpy.asarray(numpy.nan).astype(theano.config.floatX), (3, 5))
    biga = numpy.tile(
        numpy.asarray(1e20).astype(theano.config.floatX), (3, 5))

    fun(a)  # normal values

    # Temporarily silence logger
    _logger = logging.getLogger("theano.compile.nanguardmode")
    try:
        _logger.propagate = False
        assert_raises(AssertionError, fun, infa)  # INFs
        assert_raises(AssertionError, fun, nana)  # NANs
        assert_raises(AssertionError, fun, biga)  # big values
    finally:
        _logger.propagate = True 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:35,代碼來源:test_nanguardmode.py

示例2: _get_theano_monitor_mode

# 需要導入模塊: from theano.compile import nanguardmode [as 別名]
# 或者: from theano.compile.nanguardmode import NanGuardMode [as 別名]
def _get_theano_monitor_mode(self):
        mode = None

        if self.__DETECT_EXCEPTIONS__ == 'cpu':
            mode = theano.compile.MonitorMode(
                post_func=detect_floating_point_exceptions)
        elif self.__DETECT_EXCEPTIONS__ == 'theano':
            mode = nanguardmode.NanGuardMode(
                nan_is_error=True,
                inf_is_error=True,
                big_is_error=False)

        logging.debug('Injection mode: %s.', repr(mode))

        return mode 
開發者ID:cvangysel,項目名稱:SERT,代碼行數:17,代碼來源:models.py

示例3: compile_train

# 需要導入模塊: from theano.compile import nanguardmode [as 別名]
# 或者: from theano.compile.nanguardmode import NanGuardMode [as 別名]
def compile_train(self):

        # questions (theano variables)
        inputs  = T.imatrix()  # padded input word sequence (for training)
        target  = T.imatrix()  # padded target word sequence (for training)

        # encoding & decoding
        if not self.attend:
            code               = self.encoder.build_encoder(inputs, None)
            logPxz, logPPL     = self.decoder.build_decoder(target, code)
        else:
            code, _, c_mask, _ = self.encoder.build_encoder(inputs, None, return_sequence=True, return_embed=True)
            logPxz, logPPL     = self.decoder.build_decoder(target, code, c_mask)

        # responding loss
        loss_rec = T.mean(-logPxz)
        loss_ppl = T.exp(T.mean(-logPPL))
        loss     = loss_rec

        updates  = self.optimizer.get_updates(self.params, loss)

        logger.info("compiling the compuational graph ::training function::")
        train_inputs = [inputs, target]

        self.train_ = theano.function(train_inputs,
                                      [loss_rec, loss_ppl],
                                      updates=updates,
                                      name='train_fun')
                                      # mode=NanGuardMode(nan_is_error=True, inf_is_error=True, big_is_error=True))
        logger.info("training functions compile done.")

        # # add monitoring:
        # self.monitor['context'] = context
        # self._monitoring()
        #
        # # compiling monitoring
        # self.compile_monitoring(train_inputs) 
開發者ID:MultiPath,項目名稱:CopyNet,代碼行數:39,代碼來源:encdec.py

示例4: compile_train

# 需要導入模塊: from theano.compile import nanguardmode [as 別名]
# 或者: from theano.compile.nanguardmode import NanGuardMode [as 別名]
def compile_train(self):

        # questions (theano variables)
        inputs    = T.imatrix()  # padded input word sequence (for training)
        target    = T.imatrix()  # padded target word sequence (for training)
        cc_matrix = T.tensor3()

        # encoding & decoding

        code, _, c_mask, _ = self.encoder.build_encoder(inputs, None, return_sequence=True, return_embed=True)
        # code: (nb_samples, max_len, contxt_dim)
        if 'explicit_loc' in self.config:
            if self.config['explicit_loc']:
                print 'use explicit location!!'
                max_len = code.shape[1]
                expLoc  = T.eye(max_len, self.config['encode_max_len'], dtype='float32')[None, :, :]
                expLoc  = T.repeat(expLoc, code.shape[0], axis=0)
                code    = T.concatenate([code, expLoc], axis=2)

        logPxz, logPPL     = self.decoder.build_decoder(target, cc_matrix,
                                                        code, c_mask)

        # responding loss
        loss_rec = T.mean(-logPxz)
        loss_ppl = T.exp(T.mean(-logPPL))
        loss     = loss_rec

        updates  = self.optimizer.get_updates(self.params, loss)

        logger.info("compiling the compuational graph ::training function::")
        train_inputs = [inputs, target, cc_matrix]

        self.train_ = theano.function(train_inputs,
                                      [loss_rec, loss_ppl],
                                      updates=updates,
                                      name='train_fun')
        self.train_guard = theano.function(train_inputs,
                                      [loss_rec, loss_ppl],
                                      updates=updates,
                                      name='train_fun',
                                      mode=NanGuardMode(nan_is_error=True, inf_is_error=True, big_is_error=True))
        logger.info("training functions compile done.")

        # # add monitoring:
        # self.monitor['context'] = context
        # self._monitoring()
        #
        # # compiling monitoring
        # self.compile_monitoring(train_inputs) 
開發者ID:MultiPath,項目名稱:CopyNet,代碼行數:51,代碼來源:covc_encdec.py


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