(self, beam)
Keeps the coverage vector as sum of attentions
Keeps the coverage vector as sum of attentions
Keeps the coverage vector as sum of attentions
def update_global_state(self, beam):
        "Keeps the coverage vector as sum of attentions"
        if len(beam.prev_ks) == 1:
            beam.global_state["prev_penalty"] = beam.scores.clone().fill_(0.0)
            beam.global_state["coverage"] = beam.attn[-1]
            self.cov_total = beam.attn[-1].sum(1)
        else:
            self.cov_total += torch.min(beam.attn[-1],
                                        beam.global_state['coverage']).sum(1)
            beam.global_state["coverage"] = beam.global_state["coverage"] \
                .index_select(0, beam.prev_ks[-1]).add(beam.attn[-1])

            prev_penalty = self.cov_penalty(beam,
                                            beam.global_state["coverage"],
                                            self.beta)
            beam.global_state["prev_penalty"] = prev_penalty
def update_global_state ( self , beam ) : if len ( beam . prev_ks ) == 1 : beam . global_state [ "prev_penalty" ] = beam . scores . clone ( ) . fill_ ( 0.0 ) beam . global_state [ "coverage" ] = beam . attn [ - 1 ] self . cov_total = beam . attn [ - 1 ] . sum ( 1 ) else : self . cov_total += torch . min ( beam . attn [ - 1 ] , beam . global_state [ 'coverage' ] ) . sum ( 1 ) beam . global_state [ "coverage" ] = beam . global_state [ "coverage" ] . index_select ( 0 , beam . prev_ks [ - 1 ] ) . add ( beam . attn [ - 1 ] ) prev_penalty = self . cov_penalty ( beam , beam . global_state [ "coverage" ] , self . beta ) beam . global_state [ "prev_penalty" ] = prev_penalty