Upload metrics.py with huggingface_hub
Browse files219 unmodified lines220221222223224225226227228229229230231232233140 unmodified lines3743753763773783793803813823833843853863871 unmodified line38939039139238438539339439539639740 unmodified lines438439440441442443444445446447448449219 unmodified lines metric_name: str = None main_score: str = None scale: float = 1.0 hf_compute_args: dict = {}
def prepare(self): super().prepare() self.metric = evaluate.load(self.metric_name)
def compute(self, references: List[List[str]], predictions: List[str]) -> dict: result = self.metric.compute(predictions=predictions, references=references) result = self.metric.compute(predictions=predictions, references=references, **self.hf_compute_args) if self.scale != 1.0: for key in result: if isinstance(result[key], float):140 unmodified lines main_score = "rougeL" scale = 1.0
use_aggregator: bool = True rouge_types: List[str] = ["rouge1", "rouge2", "rougeL", "rougeLsum"]
sent_split_newline: bool = True
def prepare(self): self.hf_compute_args = {"use_aggregator": self.use_aggregator, "rouge_types": self.rouge_types}
super().prepare() import nltk
1 unmodified line self.sent_tokenize = nltk.sent_tokenize
def compute(self, references, predictions): if self.sent_split_newline: predictions = ["\n".join(self.sent_tokenize(prediction.strip())) for prediction in predictions] references = [["\n".join(self.sent_tokenize(r.strip())) for r in reference] for reference in references] predictions = ["\n".join(self.sent_tokenize(prediction.strip())) for prediction in predictions] references = [["\n".join(self.sent_tokenize(r.strip())) for r in reference] for reference in references] return super().compute(references, predictions)
40 unmodified lines scale = 1.0
class SacreBleu(HuggingfaceMetric): metric_name = "sacrebleu" main_score = "score" scale = 1.0
class MatthewsCorrelation(HuggingfaceMetric): metric_name = "matthews_correlation" main_score = "matthews_correlation"metrics.py+18-3