コード例 #1
0
    def test_dropout(self):
        dparams = self.decoder_params
        dparams["dropout_keep_prob"] = -0.5
        with self.assertRaises(ValueError):
            Decoder(**dparams)

        dparams["dropout_keep_prob"] = 1.5
        with self.assertRaises(ValueError):
            Decoder(**dparams)
コード例 #2
0
    def test_embedding_size(self):
        dparams = copy.deepcopy(DECODER_PARAMS)

        dparams["embedding_size"] = None
        with self.assertRaises(ValueError):
            Decoder(**dparams)

        dparams["embedding_size"] = -10
        with self.assertRaises(ValueError):
            Decoder(**dparams)
コード例 #3
0
    def test_dropout(self):
        dparams = copy.deepcopy(DECODER_PARAMS)

        dparams["dropout_keep_prob"] = -0.5
        with self.assertRaises(ValueError):
            Decoder(**dparams)

        dparams["dropout_keep_prob"] = 1.5
        with self.assertRaises(ValueError):
            Decoder(**dparams)
コード例 #4
0
    def test_embedding_size(self):
        dparams = self.decoder_params
        dparams["embedding_size"] = None
        with self.assertRaises(ValueError):
            dec = Decoder(**dparams)
            print(dec.embedding_size)

        dparams["embedding_size"] = -10
        with self.assertRaises(ValueError):
            Decoder(**dparams)
コード例 #5
0
    def test_cell_type(self):
        dparams = copy.deepcopy(DECODER_PARAMS)

        dparams.update({"rnn_cell": "bogus_cell"})
        with self.assertRaises(ValueError):
            Decoder(**dparams)

        for cell_type in ("GRU", "LSTM", "NematusGRU"):
            print(dparams)
            dparams["rnn_cell"] = cell_type
            dparams["name"] = "test-decoder-{}".format(cell_type)
            Decoder(**dparams)
コード例 #6
0
def build_decoder(config: Dict, attention: Attention,
                  encoder: RecurrentEncoder) -> Tuple[Decoder, str]:
    vocabulary = from_nematus_json(config["tgt_vocabulary"],
                                   max_size=config["n_words_tgt"],
                                   pad_to_max_size=True)

    vocabulary_ini = VOCABULARY_TEMPLATE.format("tgt",
                                                config["tgt_vocabulary"],
                                                config["n_words_tgt"])

    decoder = Decoder(
        name=DECODER_NAME,
        vocabulary=vocabulary,
        data_id="target",
        max_output_len=config["max_length"],
        embedding_size=config["embedding_size"],
        rnn_size=config["rnn_size"],
        encoders=[encoder],
        attentions=[attention],
        attention_on_input=False,
        conditional_gru=True,
        encoder_projection=nematus_projection(dropout_keep_prob=1.0),
        output_projection=nematus_output(config["embedding_size"]),
        rnn_cell="NematusGRU")

    decoder_ini = DECODER_TEMPLATE.format(DECODER_NAME,
                                          config["embedding_size"],
                                          config["rnn_size"],
                                          config["max_length"],
                                          config["embedding_size"])

    return decoder, "\n".join([vocabulary_ini, decoder_ini])
コード例 #7
0
    def test_tie_embeddings(self):
        dparams = copy.deepcopy(DECODER_PARAMS)

        dparams["tie_embeddings"] = True
        dparams["rnn_size"] = 20
        dparams["embedding_size"] = 10
        with self.assertRaises(ValueError):
            Decoder(**dparams)
コード例 #8
0
ファイル: test_decoder.py プロジェクト: zabin10/neuralmonkey
 def test_init(self):
     decoder = Decoder(encoders=[],
                       vocabulary=Vocabulary(),
                       data_id="foo",
                       name="test-decoder",
                       max_output_len=5,
                       dropout_keep_prob=1.0,
                       embedding_size=10,
                       rnn_size=10)
     self.assertIsNotNone(decoder)
コード例 #9
0
    def test_max_output_len(self):
        dparams = copy.deepcopy(DECODER_PARAMS)

        dparams["max_output_len"] = -10
        with self.assertRaises(ValueError):
            Decoder(**dparams)
コード例 #10
0
 def test_init(self):
     decoder = Decoder(**DECODER_PARAMS)
     self.assertIsNotNone(decoder)
コード例 #11
0
 def test_max_output_len(self):
     dparams = self.decoder_params
     dparams["max_output_len"] = -10
     with self.assertRaises(ValueError):
         Decoder(**dparams)
コード例 #12
0
 def test_init(self):
     decoder = Decoder(**self.decoder_params)
     self.assertIsNotNone(decoder)
コード例 #13
0
 def test_init(self):
     decoder = Decoder([], Vocabulary(), "foo", "test-decoder")
     self.assertIsNotNone(decoder)