# Copyright (c) Facebook, Inc. and its affiliates.## This source code is licensed under the MIT license found in the# LICENSE file in the root directory of this source tree.fromfairseq.scoringimportBaseScorer,register_scorer@register_scorer("chrf")classChrFScorer(BaseScorer):def__init__(self,args):super(ChrFScorer,self).__init__(args)importsacrebleuself.sacrebleu=sacrebleudefadd_string(self,ref,pred):self.ref.append(ref)self.pred.append(pred)defscore(self,order=4):returnself.result_string(order).scoredefresult_string(self,order=4):iforder!=4:raiseNotImplementedErrorreturnself.sacrebleu.corpus_chrf(self.pred,[self.ref]).format()