Exemple #1
0
 def get(self):
     wv = VizSeqWebView(
         args.data_root, self.get_task_arg(), models=self.get_models_arg(),
         page_sz=self.get_page_sz_arg(), page_no=self.get_page_no_arg(),
         query=self.get_query_arg(), sorting=self.get_sorting_arg()
     )
     page_data_json = wv.get_page_data_with_pagination()
     self.write(page_data_json)
Exemple #2
0
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)
Exemple #3
0
 def post(self):
     task = self.get_task_arg()
     cfg = VizSeqWebView(args.data_root, task).cfg
     task_name = self.get_query_argument('n', task)
     cfg.set_task_name(task_name)
     description = self.get_query_argument('d', '')
     cfg.set_description(description)
     cfg_metrics = self.get_query_argument('m', '')
     cfg_metrics = cfg_metrics.split(',') if len(cfg_metrics) > 0 else []
     cfg.set_metrics(cfg_metrics)
     tokenization = self.get_query_argument('tkn', '')
     cfg.set_tokenization(tokenization)
     self.finish(f'Task "{task}" Config updated.')
Exemple #4
0
 def get(self):
     enum_tasks_and_names_and_enum_models = \
         VizSeqWebView.get_enum_tasks_and_names_and_enum_models(args.data_root)
     html = env.get_template('tasks.html').render(
         enum_tasks_and_names_and_enum_models=enum_tasks_and_names_and_enum_models
     )
     self.write(html)
Exemple #5
0
 def get(self):
     url_args = self.get_url_args()
     models = self.get_models_arg()
     task = self.get_task_arg()
     page_sz, page_no = self.get_page_sz_arg(), self.get_page_no_arg()
     query = self.get_query_arg()
     sorting = self.get_sorting_arg()
     s_metric = self.get_sorting_metric_arg()
     wv = VizSeqWebView(
         args.data_root, task, models=models, page_sz=page_sz,
         page_no=page_no, query=query, sorting=sorting,
         sorting_metric=s_metric
     )
     pd = wv.get_page_data()
     html = env.get_template('view.html').render(
         url_args=url_args, task=task, models=models, page_sz=page_sz,
         page_no=page_no, sorting=sorting, query=query, metrics=wv.metrics,
         src_has_text=wv.src_has_text, task_name=wv.task_name,
         enum_src_names_and_types=wv.enum_src_names_and_types,
         enum_ref_names=wv.enum_ref_names, trg_lang=pd.trg_lang,
         span_highlight_js=SPAN_HIGHTLIGHT_JS, page_sizes=wv.page_sizes,
         enum_metrics_and_names=wv.get_enum_metrics_and_names(),
         tag_set=wv.get_tag_set(), tags=wv.get_tags(),
         auto_tags=[[e] for e in pd.trg_lang],
         all_metrics_and_names=wv.all_metrics_and_names, s_metric=s_metric,
         pagination=wv.get_pagination(pd.total_examples, page_sz, page_no),
         cur_idx=pd.cur_idx, viz_src=pd.viz_src, src=pd.cur_src,
         ref=pd.viz_ref, hypo=pd.viz_hypo, n_samples=pd.n_samples,
         cur_sent_scores=pd.viz_sent_scores, description=wv.description,
         tokenization=wv.tokenization, all_tokenization=wv.all_tokenization,
         total_examples=pd.total_examples, n_cur_samples=pd.n_cur_samples
     )
     self.write(html)
Exemple #6
0
 def get(self):
     task = self.get_task_arg()
     response = VizSeqWebView(args.data_root, task).get_n_grams()
     self.write(response)
Exemple #7
0
 def get(self):
     response = VizSeqWebView(
         args.data_root, self.get_task_arg(), self.get_models_arg()
     ).get_scores()
     self.write(response)