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)
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)
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)
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)
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)
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])
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)
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)
def test_max_output_len(self): dparams = copy.deepcopy(DECODER_PARAMS) dparams["max_output_len"] = -10 with self.assertRaises(ValueError): Decoder(**dparams)
def test_init(self): decoder = Decoder(**DECODER_PARAMS) self.assertIsNotNone(decoder)
def test_max_output_len(self): dparams = self.decoder_params dparams["max_output_len"] = -10 with self.assertRaises(ValueError): Decoder(**dparams)
def test_init(self): decoder = Decoder(**self.decoder_params) self.assertIsNotNone(decoder)
def test_init(self): decoder = Decoder([], Vocabulary(), "foo", "test-decoder") self.assertIsNotNone(decoder)