def score(self, sentence: str, **kwargs):
// NOTE: this doesn"t support translation tasks currently
input = self.encode(sentence)
return self.generate(input, score_reference=True, **kwargs)[0]
def generate(self, tokens: torch.LongTensor, beam: int = 5, verbose: bool = False, **kwargs) -> torch.LongTensor:
sample = self._build_sample(tokens)
After Change
def score(self, sentences: List[str], **kwargs):
if isinstance(sentences, str):
return self.score([sentences], **kwargs)[0]
// NOTE: this doesn"t support translation tasks currently
tokenized_sentences = [self.encode(sentence) for sentence in sentences]
return [hypos[0] for hypos in self.generate(tokenized_sentences, score_reference=True, **kwargs)]