def view_scores(references: PathOrPathsOrDictOfStrList, hypothesis: Optional[PathOrPathsOrDictOfStrList], metrics: List[str], tags: Optional[PathOrPathsOrDictOfStrList] = None): _ref = VizSeqDataSources(references) _hypo = VizSeqDataSources(hypothesis) _tags, tag_set = None, [] if tags is not None: _tags = VizSeqDataSources(tags, text_merged=True) tag_set = sorted(_tags.unique()) _tags = _tags.text models = _hypo.names all_metrics = get_scorer_ids() _metrics = [] for s in metrics: if s in all_metrics: _metrics.append(s) else: logger.warn(f'"{s}" is not a valid metric.') scores = { s: { m: get_scorer(s)(corpus_level=True, sent_level=False).score(_hypo.data[i].text, _ref.text, tags=_tags) for i, m in enumerate(models) } for s in _metrics } corpus_scores = { s: {m: scores[s][m].corpus_score for m in models} for s in _metrics } group_scores = { s: { t: {m: scores[s][m].group_scores[t] for m in models} for t in tag_set } for s in _metrics } metrics_and_names = [[s, get_scorer_name(s)] for s in _metrics] html = env.get_template('ipynb_scores.html').render( metrics_and_names=metrics_and_names, models=models, tag_set=tag_set, corpus_scores=corpus_scores, group_scores=group_scores, corpus_and_group_score_latex=VizSeqWebView.latex_corpus_group_scores( corpus_scores, group_scores), corpus_and_group_score_csv=VizSeqWebView.csv_corpus_group_scores( corpus_scores, group_scores), ) return HTML(html)
def get_enum_metrics_and_names(self): return [[i, s, get_scorer_name(s)] for i, s in enumerate(self.metrics)]
def scores_to_latex(scores: Dict) -> str: return VizSeqTableExporter.to_latex( {get_scorer_name(s): scores for s, scores in scores.items()} )