def __init__(self, corpus, config): super(SysPerfectBD2Gauss, self).__init__(config) self.vocab = corpus.vocab self.vocab_dict = corpus.vocab_dict self.vocab_size = len(self.vocab) self.bos_id = self.vocab_dict[BOS] self.eos_id = self.vocab_dict[EOS] self.pad_id = self.vocab_dict[PAD] self.bs_size = corpus.bs_size self.db_size = corpus.db_size self.y_size = config.y_size self.simple_posterior = config.simple_posterior self.embedding = None self.utt_encoder = RnnUttEncoder(vocab_size=self.vocab_size, embedding_dim=config.embed_size, feat_size=0, goal_nhid=0, rnn_cell=config.utt_rnn_cell, utt_cell_size=config.utt_cell_size, num_layers=config.num_layers, input_dropout_p=config.dropout, output_dropout_p=config.dropout, bidirectional=config.bi_utt_cell, variable_lengths=False, use_attn=config.enc_use_attn, embedding=self.embedding) self.c2z = nn_lib.Hidden2Gaussian(self.utt_encoder.output_size + self.db_size + self.bs_size, config.y_size, is_lstm=False) self.gauss_connector = nn_lib.GaussianConnector(self.use_gpu) self.z_embedding = nn.Linear(self.y_size, config.dec_cell_size) if not self.simple_posterior: self.xc2z = nn_lib.Hidden2Gaussian( self.utt_encoder.output_size * 2 + self.db_size + self.bs_size, config.y_size, is_lstm=False) self.decoder = DecoderRNN(input_dropout_p=config.dropout, rnn_cell=config.dec_rnn_cell, input_size=config.embed_size, hidden_size=config.dec_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=False, vocab_size=self.vocab_size, use_attn=config.dec_use_attn, ctx_cell_size=config.dec_cell_size, attn_mode=config.dec_attn_mode, sys_id=self.bos_id, eos_id=self.eos_id, use_gpu=config.use_gpu, max_dec_len=config.max_dec_len, embedding=self.embedding) self.nll = NLLEntropy(self.pad_id, config.avg_type) self.gauss_kl = NormKLLoss(unit_average=True) self.zero = cast_type(th.zeros(1), FLOAT, self.use_gpu)
def __init__(self, corpus, config): super(SysPerfectBD2Word, self).__init__(config) self.vocab = corpus.vocab self.vocab_dict = corpus.vocab_dict self.vocab_size = len(self.vocab) self.bos_id = self.vocab_dict[BOS] self.eos_id = self.vocab_dict[EOS] self.pad_id = self.vocab_dict[PAD] self.bs_size = corpus.bs_size self.db_size = corpus.db_size self.embedding = None self.utt_encoder = RnnUttEncoder(vocab_size=self.vocab_size, embedding_dim=config.embed_size, feat_size=0, goal_nhid=0, rnn_cell=config.utt_rnn_cell, utt_cell_size=config.utt_cell_size, num_layers=config.num_layers, input_dropout_p=config.dropout, output_dropout_p=config.dropout, bidirectional=config.bi_utt_cell, variable_lengths=False, use_attn=config.enc_use_attn, embedding=self.embedding) self.policy = nn.Sequential( nn.Linear( self.utt_encoder.output_size + self.db_size + self.bs_size, config.dec_cell_size), nn.Tanh(), nn.Dropout(config.dropout)) self.decoder = DecoderRNN(input_dropout_p=config.dropout, rnn_cell=config.dec_rnn_cell, input_size=config.embed_size, hidden_size=config.dec_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=False, vocab_size=self.vocab_size, use_attn=config.dec_use_attn, ctx_cell_size=self.utt_encoder.output_size, attn_mode=config.dec_attn_mode, sys_id=self.bos_id, eos_id=self.eos_id, use_gpu=config.use_gpu, max_dec_len=config.max_dec_len, embedding=self.embedding) self.nll = NLLEntropy(self.pad_id, config.avg_type)
def __init__(self, corpus, config): super(HRED, self).__init__(config) self.vocab = corpus.vocab self.vocab_dict = corpus.vocab_dict self.vocab_size = len(self.vocab) self.goal_vocab = corpus.goal_vocab self.goal_vocab_dict = corpus.goal_vocab_dict self.goal_vocab_size = len(self.goal_vocab) self.outcome_vocab = corpus.outcome_vocab self.outcome_vocab_dict = corpus.outcome_vocab_dict self.outcome_vocab_size = len(self.outcome_vocab) self.sys_id = self.vocab_dict[SYS] self.eos_id = self.vocab_dict[EOS] self.pad_id = self.vocab_dict[PAD] self.goal_encoder = MlpGoalEncoder( goal_vocab_size=self.goal_vocab_size, k=config.k, nembed=config.goal_embed_size, nhid=config.goal_nhid, init_range=config.init_range) self.embedding = nn.Embedding(self.vocab_size, config.embed_size, padding_idx=self.pad_id) self.utt_encoder = RnnUttEncoder(vocab_size=self.vocab_size, embedding_dim=config.embed_size, feat_size=1, goal_nhid=config.goal_nhid, rnn_cell=config.utt_rnn_cell, utt_cell_size=config.utt_cell_size, num_layers=config.num_layers, input_dropout_p=config.dropout, output_dropout_p=config.dropout, bidirectional=config.bi_utt_cell, variable_lengths=False, use_attn=config.enc_use_attn, embedding=self.embedding) self.ctx_encoder = EncoderRNN( input_dropout_p=0.0, rnn_cell=config.ctx_rnn_cell, # input_size=self.utt_encoder.output_size+config.goal_nhid, input_size=self.utt_encoder.output_size, hidden_size=config.ctx_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=config.bi_ctx_cell, variable_lengths=False) # TODO connector if config.bi_ctx_cell: self.connector = Bi2UniConnector(rnn_cell=config.ctx_rnn_cell, num_layer=1, hidden_size=config.ctx_cell_size, output_size=config.dec_cell_size) else: self.connector = IdentityConnector() self.decoder = DecoderRNN(input_dropout_p=config.dropout, rnn_cell=config.dec_rnn_cell, input_size=config.embed_size + 2 * config.goal_nhid, hidden_size=config.dec_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=False, vocab_size=self.vocab_size, use_attn=config.dec_use_attn, ctx_cell_size=self.ctx_encoder.output_size, attn_mode=config.dec_attn_mode, sys_id=self.sys_id, eos_id=self.eos_id, use_gpu=config.use_gpu, max_dec_len=config.max_dec_len, embedding=self.embedding) self.nll = NLLEntropy(self.pad_id, config.avg_type) self.out_backward_size = config.out_backward_size self.z_size = config.z_size self.z_dim = config.z_dim self.z_emb = nn.Parameter(th.FloatTensor(config.z_size, config.z_dim)) # oracle modules self.book_emb = nn.Embedding(16, 32) self.hat_emb = nn.Embedding(16, 32) self.ball_emb = nn.Embedding(16, 32) self.res_layer = nn_lib.ResidualLayer(3 * 32, 128) self.book_emb_out = nn.Embedding(16, 32) self.hat_emb_out = nn.Embedding(16, 32) self.ball_emb_out = nn.Embedding(16, 32) self.res_layer_out = nn_lib.ResidualLayer(3 * 32, 128) self.prop_utt_encoder = RnnUttEncoder( vocab_size=self.vocab_size, embedding_dim=config.embed_size, feat_size=1, goal_nhid=config.goal_nhid, rnn_cell=config.utt_rnn_cell, utt_cell_size=config.utt_cell_size, num_layers=config.num_layers, input_dropout_p=config.dropout, output_dropout_p=config.dropout, bidirectional=config.bi_utt_cell, variable_lengths=False, use_attn=config.enc_use_attn, embedding=self.embedding, ) self.prop_ctx_encoder = EncoderRNN( input_dropout_p=0.0, rnn_cell=config.ctx_rnn_cell, # input_size=self.utt_encoder.output_size+config.goal_nhid, input_size=self.utt_encoder.output_size + 64 if config.oracle_context else self.utt_encoder.output_size, hidden_size=config.ctx_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=config.bi_ctx_cell, variable_lengths=False, ) self.w_pz0 = nn.Linear(64, 64, bias=False) self.prior_res_layer = nn_lib.ResidualLayer(config.ctx_cell_size, 64) self.res_goal_mlp = nn_lib.ResidualLayer(256 + config.goal_nhid, 128)
def __init__(self, corpus, config): super(CatHRED, self).__init__(config) self.vocab = corpus.vocab self.vocab_dict = corpus.vocab_dict self.vocab_size = len(self.vocab) self.goal_vocab = corpus.goal_vocab self.goal_vocab_dict = corpus.goal_vocab_dict self.goal_vocab_size = len(self.goal_vocab) self.outcome_vocab = corpus.outcome_vocab self.outcome_vocab_dict = corpus.outcome_vocab_dict self.outcome_vocab_size = len(self.outcome_vocab) self.sys_id = self.vocab_dict[SYS] self.eos_id = self.vocab_dict[EOS] self.pad_id = self.vocab_dict[PAD] self.simple_posterior = config.simple_posterior self.goal_encoder = MlpGoalEncoder(goal_vocab_size=self.goal_vocab_size, k=config.k, nembed=config.goal_embed_size, nhid=config.goal_nhid, init_range=config.init_range) self.embedding = nn.Embedding(self.vocab_size, config.embed_size, padding_idx=self.pad_id) self.utt_encoder = RnnUttEncoder(vocab_size=self.vocab_size, embedding_dim=config.embed_size, feat_size=0, goal_nhid=config.goal_nhid, rnn_cell=config.utt_rnn_cell, utt_cell_size=config.utt_cell_size, num_layers=config.num_layers, input_dropout_p=config.dropout, output_dropout_p=config.dropout, bidirectional=config.bi_utt_cell, variable_lengths=False, use_attn=config.enc_use_attn, embedding=self.embedding) self.ctx_encoder = EncoderRNN(input_dropout_p=0.0, rnn_cell=config.ctx_rnn_cell, # input_size=self.utt_encoder.output_size+config.goal_nhid, input_size=self.utt_encoder.output_size, hidden_size=config.ctx_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=config.bi_ctx_cell, variable_lengths=False) # mu and logvar projector self.c2z = nn_lib.Hidden2Discrete(self.ctx_encoder.output_size, config.y_size, config.k_size, is_lstm=config.ctx_rnn_cell == 'lstm') if not self.simple_posterior: self.xc2z = nn_lib.Hidden2Discrete(self.ctx_encoder.output_size + self.utt_encoder.output_size, config.y_size, config.k_size, is_lstm=False) self.gumbel_connector = nn_lib.GumbelConnector(config.use_gpu) self.z_embedding = nn.Linear(config.y_size * config.k_size, config.dec_cell_size, bias=False) self.decoder = DecoderRNN(input_dropout_p=config.dropout, rnn_cell=config.dec_rnn_cell, input_size=config.embed_size + config.goal_nhid, hidden_size=config.dec_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=False, vocab_size=self.vocab_size, use_attn=config.dec_use_attn, ctx_cell_size=self.ctx_encoder.output_size, attn_mode=config.dec_attn_mode, sys_id=self.sys_id, eos_id=self.eos_id, use_gpu=config.use_gpu, max_dec_len=config.max_dec_len, embedding=self.embedding) self.nll = NLLEntropy(self.pad_id, config.avg_type) self.cat_kl_loss = criterions.CatKLLoss() self.entropy_loss = criterions.Entropy() self.log_uniform_y = Variable(th.log(th.ones(1) / config.k_size)) if self.use_gpu: self.log_uniform_y = self.log_uniform_y.cuda()
def __init__(self, corpus, config): super(HRED, self).__init__(config) self.vocab = corpus.vocab self.vocab_dict = corpus.vocab_dict self.vocab_size = len(self.vocab) self.goal_vocab = corpus.goal_vocab self.goal_vocab_dict = corpus.goal_vocab_dict self.goal_vocab_size = len(self.goal_vocab) self.outcome_vocab = corpus.outcome_vocab self.outcome_vocab_dict = corpus.outcome_vocab_dict self.outcome_vocab_size = len(self.outcome_vocab) self.sys_id = self.vocab_dict[SYS] self.eos_id = self.vocab_dict[EOS] self.pad_id = self.vocab_dict[PAD] self.goal_encoder = MlpGoalEncoder(goal_vocab_size=self.goal_vocab_size, k=config.k, nembed=config.goal_embed_size, nhid=config.goal_nhid, init_range=config.init_range) self.embedding = nn.Embedding(self.vocab_size, config.embed_size, padding_idx=self.pad_id) self.utt_encoder = RnnUttEncoder(vocab_size=self.vocab_size, embedding_dim=config.embed_size, feat_size=1, goal_nhid=config.goal_nhid, rnn_cell=config.utt_rnn_cell, utt_cell_size=config.utt_cell_size, num_layers=config.num_layers, input_dropout_p=config.dropout, output_dropout_p=config.dropout, bidirectional=config.bi_utt_cell, variable_lengths=False, use_attn=config.enc_use_attn, embedding=self.embedding) self.ctx_encoder = EncoderRNN(input_dropout_p=0.0, rnn_cell=config.ctx_rnn_cell, # input_size=self.utt_encoder.output_size+config.goal_nhid, input_size=self.utt_encoder.output_size, hidden_size=config.ctx_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=config.bi_ctx_cell, variable_lengths=False) # TODO connector if config.bi_ctx_cell: self.connector = Bi2UniConnector(rnn_cell=config.ctx_rnn_cell, num_layer=1, hidden_size=config.ctx_cell_size, output_size=config.dec_cell_size) else: self.connector = IdentityConnector() self.decoder = DecoderRNN(input_dropout_p=config.dropout, rnn_cell=config.dec_rnn_cell, input_size=config.embed_size + config.goal_nhid, hidden_size=config.dec_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=False, vocab_size=self.vocab_size, use_attn=config.dec_use_attn, ctx_cell_size=self.ctx_encoder.output_size, attn_mode=config.dec_attn_mode, sys_id=self.sys_id, eos_id=self.eos_id, use_gpu=config.use_gpu, max_dec_len=config.max_dec_len, embedding=self.embedding) self.nll = NLLEntropy(self.pad_id, config.avg_type)
def __init__(self, corpus, config): super(GaussHRED, self).__init__(config) self.vocab = corpus.vocab self.vocab_dict = corpus.vocab_dict self.vocab_size = len(self.vocab) self.goal_vocab = corpus.goal_vocab self.goal_vocab_dict = corpus.goal_vocab_dict self.goal_vocab_size = len(self.goal_vocab) self.outcome_vocab = corpus.outcome_vocab self.outcome_vocab_dict = corpus.outcome_vocab_dict self.outcome_vocab_size = len(self.outcome_vocab) self.sys_id = self.vocab_dict[SYS] self.eos_id = self.vocab_dict[EOS] self.pad_id = self.vocab_dict[PAD] self.simple_posterior = config.simple_posterior self.goal_encoder = MlpGoalEncoder(goal_vocab_size=self.goal_vocab_size, k=config.k, nembed=config.goal_embed_size, nhid=config.goal_nhid, init_range=config.init_range) self.embedding = nn.Embedding(self.vocab_size, config.embed_size, padding_idx=self.pad_id) self.utt_encoder = RnnUttEncoder(vocab_size=self.vocab_size, embedding_dim=config.embed_size, feat_size=0, goal_nhid=config.goal_nhid, rnn_cell=config.utt_rnn_cell, utt_cell_size=config.utt_cell_size, num_layers=config.num_layers, input_dropout_p=config.dropout, output_dropout_p=config.dropout, bidirectional=config.bi_utt_cell, variable_lengths=False, use_attn=config.enc_use_attn, embedding=self.embedding) self.ctx_encoder = EncoderRNN(input_dropout_p=0.0, rnn_cell=config.ctx_rnn_cell, # input_size=self.utt_encoder.output_size+config.goal_nhid, input_size=self.utt_encoder.output_size, hidden_size=config.ctx_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=config.bi_ctx_cell, variable_lengths=False) # mu and logvar projector self.c2z = nn_lib.Hidden2Gaussian(self.utt_encoder.output_size, config.y_size, is_lstm=False) self.gauss_connector = nn_lib.GaussianConnector(self.use_gpu) self.z_embedding = nn.Linear(config.y_size, config.dec_cell_size) if not self.simple_posterior: self.xc2z = nn_lib.Hidden2Gaussian(self.utt_encoder.output_size+self.ctx_encoder.output_size, config.y_size, is_lstm=False) self.decoder = DecoderRNN(input_dropout_p=config.dropout, rnn_cell=config.dec_rnn_cell, input_size=config.embed_size + config.goal_nhid, hidden_size=config.dec_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=False, vocab_size=self.vocab_size, use_attn=config.dec_use_attn, ctx_cell_size=self.ctx_encoder.output_size, attn_mode=config.dec_attn_mode, sys_id=self.sys_id, eos_id=self.eos_id, use_gpu=config.use_gpu, max_dec_len=config.max_dec_len, embedding=self.embedding) self.nll = NLLEntropy(self.pad_id, config.avg_type) self.gauss_kl = criterions.NormKLLoss(unit_average=True) self.zero = utils.cast_type(th.zeros(1), FLOAT, self.use_gpu)
def __init__(self, corpus, config): super(Checklist, self).__init__(config) self.vocab = corpus.vocab self.vocab_dict = corpus.vocab_dict self.vocab_size = len(self.vocab) self.goal_vocab = corpus.goal_vocab self.goal_vocab_dict = corpus.goal_vocab_dict self.goal_vocab_size = len(self.goal_vocab) self.outcome_vocab = corpus.outcome_vocab self.outcome_vocab_dict = corpus.outcome_vocab_dict self.outcome_vocab_size = len(self.outcome_vocab) self.sys_id = self.vocab_dict[SYS] self.eos_id = self.vocab_dict[EOS] self.pad_id = self.vocab_dict[PAD] self.simple_posterior = False assert not config.simple_posterior self.goal_encoder = MlpGoalEncoder( goal_vocab_size=self.goal_vocab_size, k=config.k, nembed=config.goal_embed_size, nhid=config.goal_nhid, init_range=config.init_range) self.z_size = config.z_size self.item_emb = nn.Embedding(11, 32) self.res_layer = nn_lib.ResidualLayer(3 * 32, 64) self.w_pz0 = nn.Linear(64, 64, bias=False) self.embedding = nn.Embedding(self.vocab_size, config.embed_size, padding_idx=self.pad_id) self.utt_encoder = RnnUttEncoder( vocab_size=self.vocab_size, embedding_dim=config.embed_size, feat_size=0, goal_nhid=config.goal_nhid, rnn_cell=config.utt_rnn_cell, utt_cell_size=config.utt_cell_size, num_layers=config.num_layers, input_dropout_p=config.dropout, output_dropout_p=config.dropout, bidirectional=config.bi_utt_cell, variable_lengths= False, # means it looks at padding and 20 tokens every time use_attn=config.enc_use_attn, embedding=self.embedding) self.ctx_encoder = EncoderRNN( input_dropout_p=0.0, rnn_cell=config.ctx_rnn_cell, # input_size=self.utt_encoder.output_size+config.goal_nhid, input_size=self.utt_encoder.output_size, hidden_size=config.ctx_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=config.bi_ctx_cell, variable_lengths=False) # mu and logvar projector self.c2z = nn_lib.Hidden2DiscreteDeal( self.ctx_encoder.output_size, config.z_size, is_lstm=config.ctx_rnn_cell == 'lstm', ) self.xc2z = nn_lib.Hidden2DiscreteDeal( self.ctx_encoder.output_size + self.utt_encoder.output_size, config.z_size, is_lstm=False, ) self.gumbel_connector = nn_lib.GumbelConnector(config.use_gpu) #self.z_embedding = nn.Linear(config.z_size, config.dec_cell_size, bias=False) self.z_embedding = nn.Embedding(config.z_size, config.dec_cell_size) self.decoder = DecoderRNN(input_dropout_p=config.dropout, rnn_cell=config.dec_rnn_cell, input_size=config.embed_size + config.goal_nhid, hidden_size=config.dec_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=False, vocab_size=self.vocab_size, use_attn=config.dec_use_attn, ctx_cell_size=self.ctx_encoder.output_size, attn_mode=config.dec_attn_mode, sys_id=self.sys_id, eos_id=self.eos_id, use_gpu=config.use_gpu, max_dec_len=config.max_dec_len, embedding=self.embedding) self.nll = NLLEntropy(self.pad_id, config.avg_type) self.cat_kl_loss = criterions.CatKLLoss() self.entropy_loss = criterions.Entropy() # ? self.log_uniform_z = th.log(th.ones(1) / config.z_size) if self.use_gpu: self.log_uniform_z = self.log_uniform_z.cuda()
def __init__(self, corpus, config): super(Hmm, self).__init__(config) self.vocab = corpus.vocab self.vocab_dict = corpus.vocab_dict self.vocab_size = len(self.vocab) self.goal_vocab = corpus.goal_vocab self.goal_vocab_dict = corpus.goal_vocab_dict self.goal_vocab_size = len(self.goal_vocab) self.outcome_vocab = corpus.outcome_vocab self.outcome_vocab_dict = corpus.outcome_vocab_dict self.outcome_vocab_size = len(self.outcome_vocab) self.sys_id = self.vocab_dict[SYS] self.eos_id = self.vocab_dict[EOS] self.pad_id = self.vocab_dict[PAD] self.goal_encoder = MlpGoalEncoder( goal_vocab_size=self.goal_vocab_size, k=config.k, nembed=config.goal_embed_size, nhid=config.goal_nhid, init_range=config.init_range) self.embedding = nn.Embedding(self.vocab_size, config.embed_size, padding_idx=self.pad_id) self.utt_encoder = RnnUttEncoder(vocab_size=self.vocab_size, embedding_dim=config.embed_size, feat_size=1, goal_nhid=config.goal_nhid, rnn_cell=config.utt_rnn_cell, utt_cell_size=config.utt_cell_size, num_layers=config.num_layers, input_dropout_p=config.dropout, output_dropout_p=config.dropout, bidirectional=config.bi_utt_cell, variable_lengths=False, use_attn=config.enc_use_attn, embedding=self.embedding) self.ctx_encoder = EncoderRNN( input_dropout_p=0.0, rnn_cell=config.ctx_rnn_cell, # input_size=self.utt_encoder.output_size+config.goal_nhid, input_size=self.utt_encoder.output_size, hidden_size=config.ctx_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=config.bi_ctx_cell, variable_lengths=False) # TODO connector if config.bi_ctx_cell: self.connector = Bi2UniConnector(rnn_cell=config.ctx_rnn_cell, num_layer=1, hidden_size=config.ctx_cell_size, output_size=config.dec_cell_size) else: self.connector = IdentityConnector() self.decoder = DecoderRNN(input_dropout_p=config.dropout, rnn_cell=config.dec_rnn_cell, input_size=config.embed_size + config.goal_nhid + 64, hidden_size=config.dec_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=False, vocab_size=self.vocab_size, use_attn=config.dec_use_attn, ctx_cell_size=self.ctx_encoder.output_size, attn_mode=config.dec_attn_mode, sys_id=self.sys_id, eos_id=self.eos_id, use_gpu=config.use_gpu, max_dec_len=config.max_dec_len, embedding=self.embedding) self.nll = NLLEntropy(self.pad_id, config.avg_type) # new hmm stuff self.noisy_proposal_labels = config.noisy_proposal_labels self.z_size = config.z_size # for the transition matrix self.book_emb = nn.Embedding(16, 32) self.hat_emb = nn.Embedding(16, 32) self.ball_emb = nn.Embedding(16, 32) self.res_layer = nn_lib.ResidualLayer(3 * 32, 64) self.book_emb_out = nn.Embedding(16, 32) self.hat_emb_out = nn.Embedding(16, 32) self.ball_emb_out = nn.Embedding(16, 32) self.res_layer_out = nn_lib.ResidualLayer(3 * 32, 64) self.res_goal_mlp = nn_lib.ResidualLayer(64 * 3, 64 * 2) self.w_pz0 = nn.Linear(64, 64, bias=False) self.prior_res_layer = nn_lib.ResidualLayer(config.ctx_cell_size, 2 * 64)
def __init__(self, corpus, config): super(SysPerfectBD2Cat, self).__init__(config) self.vocab = corpus.vocab self.vocab_dict = corpus.vocab_dict self.vocab_size = len(self.vocab) self.bos_id = self.vocab_dict[BOS] self.eos_id = self.vocab_dict[EOS] self.pad_id = self.vocab_dict[PAD] self.bs_size = corpus.bs_size self.db_size = corpus.db_size self.k_size = config.k_size self.y_size = config.y_size self.simple_posterior = config.simple_posterior self.contextual_posterior = config.contextual_posterior self.embedding = None self.utt_encoder = RnnUttEncoder(vocab_size=self.vocab_size, embedding_dim=config.embed_size, feat_size=0, goal_nhid=0, rnn_cell=config.utt_rnn_cell, utt_cell_size=config.utt_cell_size, num_layers=config.num_layers, input_dropout_p=config.dropout, output_dropout_p=config.dropout, bidirectional=config.bi_utt_cell, variable_lengths=False, use_attn=config.enc_use_attn, embedding=self.embedding) self.c2z = nn_lib.Hidden2Discrete(self.utt_encoder.output_size + self.db_size + self.bs_size, config.y_size, config.k_size, is_lstm=False) self.z_embedding = nn.Linear(self.y_size * self.k_size, config.dec_cell_size, bias=False) self.gumbel_connector = nn_lib.GumbelConnector(config.use_gpu) if not self.simple_posterior: if self.contextual_posterior: self.xc2z = nn_lib.Hidden2Discrete(self.utt_encoder.output_size * 2 + self.db_size + self.bs_size, config.y_size, config.k_size, is_lstm=False) else: self.xc2z = nn_lib.Hidden2Discrete(self.utt_encoder.output_size, config.y_size, config.k_size, is_lstm=False) self.decoder = DecoderRNN(input_dropout_p=config.dropout, rnn_cell=config.dec_rnn_cell, input_size=config.embed_size, hidden_size=config.dec_cell_size, num_layers=config.num_layers, output_dropout_p=config.dropout, bidirectional=False, vocab_size=self.vocab_size, use_attn=config.dec_use_attn, ctx_cell_size=config.dec_cell_size, attn_mode=config.dec_attn_mode, sys_id=self.bos_id, eos_id=self.eos_id, use_gpu=config.use_gpu, max_dec_len=config.max_dec_len, embedding=self.embedding) self.nll = NLLEntropy(self.pad_id, config.avg_type) self.cat_kl_loss = CatKLLoss() self.entropy_loss = Entropy() self.log_uniform_y = Variable(th.log(th.ones(1) / config.k_size)) self.eye = Variable(th.eye(self.config.y_size).unsqueeze(0)) self.beta = self.config.beta if hasattr(self.config, 'beta') else 0.0 if self.use_gpu: self.log_uniform_y = self.log_uniform_y.cuda() self.eye = self.eye.cuda()