import pandas as pd import streamlit as st from jiwer import process_words from visual_eval.evaluator import extract_substitution_samples, HebrewTextNormalizer subs_table_styles = """ """ @st.cache_data def visualize_substitutions(ref, hyp): norm = HebrewTextNormalizer() wer_word_output = process_words(norm(ref), norm(hyp)) subs_rows = [] for sample in extract_substitution_samples(wer_word_output): subs_rows.append( { "ref": " ".join(sample.ref), "hyp": " ".join(sample.hyp), "hyp_ctx": " ".join( wer_word_output.hypotheses[0][slice(*sample.hyp_context_span)] ), "ref_ctx": " ".join( wer_word_output.references[0][slice(*sample.ref_context_span)] ), } ) sub_rows_html = [] for row in subs_rows: sub_rows_html.append( f""" {row['ref_ctx']} {row['ref']} {row['hyp']} {row['hyp_ctx']} """ ) st.subheader("Substitutions List") table_html = f""" {subs_table_styles} {"".join(sub_rows_html)}
Ref Context Ref/Hyp Hyp Context
""" st.html(table_html)