def sample()

in fairseq/models/bart/hub_interface.py [0:0]


    def sample(self, sentences: List[str], beam: int = 1, verbose: bool = False, return_all: bool = False,
               input_is_bpe: bool = False, return_token_scores: bool = False, **kwargs) -> str:
        input = [self.encode(sentence, no_bos=True, input_is_bpe=input_is_bpe) for sentence in sentences]
        hypos = self.generate(input, beam, verbose, return_all, **kwargs)
        if return_all and beam > 1:
            result = []
            scores = []
            unnormalized_scores = []
            if return_token_scores:
                pos_scores = []
                tokens = []
                for xx in hypos:
                    result.append([self.decode(x['tokens']) for x in xx])
                    scores.append([x['score'] for x in xx])
                    unnormalized_scores.append([x['unnormalized_score'] for x in xx])
                    pos_scores.append([x['positional_scores'] for x in xx])
                    tokens.append([x['tokens'] for x in xx])
                return result, scores, unnormalized_scores, pos_scores, tokens
            else:
                for xx in hypos:
                    result.append([self.decode(x['tokens']) for x in xx])
                    scores.append([x['score'] for x in xx])
                    unnormalized_scores.append([x['unnormalized_score'] for x in xx])
                return result, scores, unnormalized_scores

        else:
            if return_token_scores:
                return [self.decode(x['tokens']) for x in hypos], [x['score'] for x in hypos], \
                       [x['unnormalized_score'] for x in hypos], [x['positional_scores'] for x in hypos], \
                       [x['tokens'] for x in hypos]
            else:
                return [self.decode(x['tokens']) for x in hypos], [x['score'] for x in hypos], \
                       [x['unnormalized_score'] for x in hypos]