Example #1
0
    def __init__(self, model, fields, opts, final_prediction_score_multiper, alternate_model_score_multiplier, cuda=False):
        self.model = model
        self.fields = fields
        self.copy_attn = opts.copy_attn
        self.copy_attn = False
        self.src_field = self.fields["src"].base_field
        self.tgt_field = self.fields["tgt"].base_field
        self.src_vocab = self.fields["src"].base_field.vocab
        self.tgt_vocab = self.fields["tgt"].base_field.vocab
        self._tgt_pad_idx = self.tgt_vocab.stoi[self.tgt_field.pad_token]
        self.tt = torch.cuda if cuda else torch
        self.prediction_score_multiper = final_prediction_score_multiper
        self.alternate_model_score_multiplier = alternate_model_score_multiplier # S|T score multiplier
        # print("final_prediction_score_multiper:", self.prediction_score_multiper)
        # print("alternate_model_score_multiplier:", self.alternate_model_score_multiplier)
        # self.gamma = 0.0 # Length penalty multipler

        ## Some additional parameters from golbal scorer just to preserve consistency
        self.alpha = 0.0
        self.beta = 0.0
        penalty_builder = penalties.PenaltyBuilder('none', 'none')
        self.has_cov_pen = penalty_builder.has_cov_pen
        # Term will be subtracted from probability
        self.cov_penalty = penalty_builder.coverage_penalty

        self.has_len_pen = penalty_builder.has_len_pen
        # Probability will be divided by this
        self.length_penalty = penalty_builder.length_penalty
 def __init__(self, alpha, beta, cov_penalty, length_penalty):
     self.alpha = alpha
     self.beta = beta
     penalty_builder = penalties.PenaltyBuilder(cov_penalty, length_penalty)
     # Term will be subtracted from probability
     self.cov_penalty = penalty_builder.coverage_penalty()
     # Probability will be divided by this
     self.length_penalty = penalty_builder.length_penalty()