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


Python rnn.LSTM属性代码示例

本文整理汇总了Python中mxnet.gluon.rnn.LSTM属性的典型用法代码示例。如果您正苦于以下问题:Python rnn.LSTM属性的具体用法?Python rnn.LSTM怎么用?Python rnn.LSTM使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在mxnet.gluon.rnn的用法示例。


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

示例1: __init__

# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import LSTM [as 别名]
def __init__(self, vocab_size, tag2idx, embedding_dim, hidden_dim):
        super(BiLSTM_CRF, self).__init__()
        with self.name_scope():
            self.embedding_dim = embedding_dim
            self.hidden_dim = hidden_dim
            self.vocab_size = vocab_size
            self.tag2idx = tag2idx
            self.tagset_size = len(tag2idx)

            self.word_embeds = nn.Embedding(vocab_size, embedding_dim)
            self.lstm = rnn.LSTM(hidden_dim // 2, num_layers=1, bidirectional=True)

            # Maps the output of the LSTM into tag space.
            self.hidden2tag = nn.Dense(self.tagset_size)

            # Matrix of transition parameters.  Entry i,j is the score of
            # transitioning *to* i *from* j.
            self.transitions = self.params.get("crf_transition_matrix", 
                                               shape=(self.tagset_size, self.tagset_size))
            
            self.hidden = self.init_hidden() 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:23,代码来源:lstm_crf.py

示例2: hybrid_forward

# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import LSTM [as 别名]
def hybrid_forward(self,
                       F: ModuleType,
                       x: nd_sym_type,
                       *args, **kwargs) -> nd_sym_type:
        """
        Used for forward pass through LSTM middleware network.
        Applies dense layers from selected scheme before passing result to LSTM layer.

        :param F: backend api, either `mxnet.nd` or `mxnet.sym` (if block has been hybridized).
        :param x: state embedding, of shape (batch_size, in_channels).
        :return: state middleware embedding, where shape is (batch_size, channels).
        """
        x_ntc = x.reshape(shape=(0, 0, -1))
        emb_ntc = super(LSTMMiddleware, self).hybrid_forward(F, x_ntc, *args, **kwargs)
        emb_tnc = emb_ntc.transpose(axes=(1, 0, 2))
        return self.lstm(emb_tnc) 
开发者ID:NervanaSystems,项目名称:coach,代码行数:18,代码来源:lstm_middleware.py

示例3: __init__

# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import LSTM [as 别名]
def __init__(self, vocab_size, tag2idx, embedding_dim, hidden_dim,START_TAG = "<START>",STOP_TAG = "<STOP>",ctx=mx.cpu()):
        super(BiLSTM_CRF, self).__init__()
        with self.name_scope():
            self.embedding_dim = embedding_dim
            self.hidden_dim = hidden_dim
            self.vocab_size = vocab_size
            self.tag2idx = tag2idx
            self.START_TAG = START_TAG
            self.STOP_TAG = STOP_TAG
            self.tagset_size = len(tag2idx)
            
            self.ctx = ctx

            self.word_embeds = nn.Embedding(vocab_size, embedding_dim)
            self.lstm = rnn.LSTM(hidden_dim // 2, num_layers=1, bidirectional=True)

            self.hidden2tag = nn.Dense(self.tagset_size)

            self.transitions = nd.random.normal(shape=(self.tagset_size, self.tagset_size),ctx=ctx)

            self.hidden = self.init_hidden() 
开发者ID:fierceX,项目名称:NER_BiLSTM_CRF_Chinese,代码行数:23,代码来源:model.py

示例4: __init__

# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import LSTM [as 别名]
def __init__(self, vocab_size, tag2idx, embedding_dim, hidden_dim):
        super(BiLSTM_CRF, self).__init__()
        with self.name_scope():
            self.embedding_dim = embedding_dim
            self.hidden_dim = hidden_dim
            self.vocab_size = vocab_size
            self.tag2idx = tag2idx
            self.tagset_size = len(tag2idx)

            self.word_embeds = nn.Embedding(vocab_size, embedding_dim)
            self.lstm = rnn.LSTM(hidden_dim // 2, num_layers=1, bidirectional=True)

            # Maps the output of the LSTM into tag space.
            self.hidden2tag = nn.Dense(self.tagset_size)

            # Matrix of transition parameters.  Entry i,j is the score of
            # transitioning *to* i *from* j.
            self.transitions = nd.random.normal(shape=(self.tagset_size, self.tagset_size))

            self.hidden = self.init_hidden() 
开发者ID:mahyarnajibi,项目名称:SNIPER-mxnet,代码行数:22,代码来源:lstm_crf.py

示例5: __init__

# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import LSTM [as 别名]
def __init__(self, mode, vocab_size, num_embed, num_hidden,
                 num_layers, dropout=0.5, tie_weights=False, **kwargs):
        super(RNNModel, self).__init__(**kwargs)
        with self.name_scope():
            self.drop = nn.Dropout(dropout)
            self.encoder = nn.Embedding(vocab_size, num_embed,
                                        weight_initializer=mx.init.Uniform(0.1))
            if mode == 'rnn_relu':
                self.rnn = rnn.RNN(num_hidden, num_layers, dropout=dropout,
                                   input_size=num_embed)
            elif mode == 'rnn_tanh':
                self.rnn = rnn.RNN(num_hidden, num_layers, 'tanh', dropout=dropout,
                                   input_size=num_embed)
            elif mode == 'lstm':
                self.rnn = rnn.LSTM(num_hidden, num_layers, dropout=dropout,
                                    input_size=num_embed)
            elif mode == 'gru':
                self.rnn = rnn.GRU(num_hidden, num_layers, dropout=dropout,
                                   input_size=num_embed)
            else:
                raise ValueError("Invalid mode %s. Options are rnn_relu, "
                                 "rnn_tanh, lstm, and gru"%mode)

            if tie_weights:
                self.decoder = nn.Dense(vocab_size, in_units=num_hidden,
                                        params=self.encoder.params)
            else:
                self.decoder = nn.Dense(vocab_size, in_units=num_hidden)

            self.num_hidden = num_hidden 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:32,代码来源:model.py

示例6: __init__

# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import LSTM [as 别名]
def __init__(self, vocab_size=VOCAB_SIZE, embedding_size=32,
                 rnn_size=128, num_layers=2, drop_rate=0.0, **kwargs):
        super(Model, self).__init__(**kwargs)
        self.args = {"vocab_size": vocab_size, "embedding_size": embedding_size,
                     "rnn_size": rnn_size, "num_layers": num_layers,
                     "drop_rate": drop_rate}
        with self.name_scope():
            self.encoder = nn.Embedding(vocab_size, embedding_size)
            self.dropout = nn.Dropout(drop_rate)
            self.rnn = rnn.LSTM(rnn_size, num_layers, dropout=drop_rate,
                                input_size=embedding_size)
            self.decoder = nn.Dense(vocab_size, in_units=rnn_size) 
开发者ID:yxtay,项目名称:char-rnn-text-generation,代码行数:14,代码来源:mxnet_model.py

示例7: __init__

# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import LSTM [as 别名]
def __init__(self, mode, vocab_size, num_embed, num_hidden,
                 num_layers, dropout=0.5, tie_weights=False, **kwargs):
        super(RNNModel, self).__init__(**kwargs)
        with self.name_scope():
            self.drop = nn.Dropout(dropout)
            self.encoder = nn.Embedding(vocab_size, num_embed,
                                        weight_initializer=mx.init.Uniform(0.1))
            if mode == 'rnn_relu':
                self.rnn = rnn.RNN(num_hidden, 'relu', num_layers, dropout=dropout,
                                   input_size=num_embed)
            elif mode == 'rnn_tanh':
                self.rnn = rnn.RNN(num_hidden, num_layers, dropout=dropout,
                                   input_size=num_embed)
            elif mode == 'lstm':
                self.rnn = rnn.LSTM(num_hidden, num_layers, dropout=dropout,
                                    input_size=num_embed)
            elif mode == 'gru':
                self.rnn = rnn.GRU(num_hidden, num_layers, dropout=dropout,
                                   input_size=num_embed)
            else:
                raise ValueError("Invalid mode %s. Options are rnn_relu, "
                                 "rnn_tanh, lstm, and gru"%mode)

            if tie_weights:
                self.decoder = nn.Dense(vocab_size, in_units=num_hidden,
                                        params=self.encoder.params)
            else:
                self.decoder = nn.Dense(vocab_size, in_units=num_hidden)

            self.num_hidden = num_hidden 
开发者ID:awslabs,项目名称:deeplearning-benchmark,代码行数:32,代码来源:model.py

示例8: __init__

# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import LSTM [as 别名]
def __init__(self, params: LSTMMiddlewareParameters):
        """
        LSTMMiddleware or Long Short Term Memory Middleware can be used in the middle part of the network. It takes the
        embeddings from the input embedders, after they were aggregated in some method (for example, concatenation)
        and passes it through a neural network  which can be customizable but shared between the heads of the network.

        :param params: parameters object containing batchnorm, activation_function, dropout and
            number_of_lstm_cells properties.
        """
        super(LSTMMiddleware, self).__init__(params)
        self.number_of_lstm_cells = params.number_of_lstm_cells
        with self.name_scope():
            self.lstm = rnn.LSTM(hidden_size=self.number_of_lstm_cells) 
开发者ID:NervanaSystems,项目名称:coach,代码行数:15,代码来源:lstm_middleware.py

示例9: schemes

# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import LSTM [as 别名]
def schemes(self) -> dict:
        """
        Schemes are the pre-defined network architectures of various depths and complexities that can be used for the
        Middleware. Are used to create Block when LSTMMiddleware is initialised, and are applied before the LSTM.

        :return: dictionary of schemes, with key of type MiddlewareScheme enum and value being list of mxnet.gluon.Block.
        """
        return {
            MiddlewareScheme.Empty:
                [],

            # Use for PPO
            MiddlewareScheme.Shallow:
                [
                    Dense(units=64)
                ],

            # Use for DQN
            MiddlewareScheme.Medium:
                [
                    Dense(units=512)
                ],

            MiddlewareScheme.Deep:
                [
                    Dense(units=128),
                    Dense(units=128),
                    Dense(units=128)
                ]
        } 
开发者ID:NervanaSystems,项目名称:coach,代码行数:32,代码来源:lstm_middleware.py

示例10: __init__

# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import LSTM [as 别名]
def __init__(
        self,
        mode: str,
        num_hidden: int,
        num_layers: int,
        bidirectional: bool = False,
        **kwargs,
    ):
        super(RNN, self).__init__(**kwargs)

        with self.name_scope():
            if mode == "rnn_relu":
                self.rnn = rnn.RNN(
                    num_hidden,
                    num_layers,
                    bidirectional=bidirectional,
                    activation="relu",
                    layout="NTC",
                )
            elif mode == "rnn_tanh":
                self.rnn = rnn.RNN(
                    num_hidden,
                    num_layers,
                    bidirectional=bidirectional,
                    layout="NTC",
                )
            elif mode == "lstm":
                self.rnn = rnn.LSTM(
                    num_hidden,
                    num_layers,
                    bidirectional=bidirectional,
                    layout="NTC",
                )
            elif mode == "gru":
                self.rnn = rnn.GRU(
                    num_hidden,
                    num_layers,
                    bidirectional=bidirectional,
                    layout="NTC",
                )
            else:
                raise ValueError(
                    "Invalid mode %s. Options are rnn_relu, rnn_tanh, lstm, and gru "
                    % mode
                ) 
开发者ID:awslabs,项目名称:gluon-ts,代码行数:47,代码来源:rnn.py


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