File size: 2,605 Bytes
4928f34
 
a4ef927
 
4928f34
 
 
 
 
 
 
 
a4ef927
4928f34
a4ef927
4928f34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4ef927
4928f34
 
a4ef927
4928f34
 
a4ef927
4928f34
 
a4ef927
4928f34
 
a4ef927
4928f34
 
 
 
 
 
 
a4ef927
4928f34
 
 
 
 
 
 
 
a4ef927
4928f34
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import gradio as gr
from typing import Tuple


def render_score_card(
    ttr_output: float,
    ttr_train: float,
    similarity: float,
    mad_score: float,
    risk_level: str,
) -> Tuple[str, str, str]:
    """Renders the evaluation summary and score details."""

    color = {"High": "#e57373", "Medium": "#ffb74d", "Low": "#81c784"}[risk_level]

    risk_explanations = {
        "High": """
🚨 **High Risk Detected** Your model outputs are **very similar** to your planned training data.  
This suggests a **strong feedback loop**, meaning the model is likely to reinforce existing patterns rather than learning new behaviors.  
**What You Can Do**:  
- Replace synthetic data with more **diverse real user input** - Use **paraphrasing techniques** before reuse  
- Add **augmentation or filtering** before retraining
""",
        "Medium": """
🟠 **Moderate Risk Identified** There is some overlap between your outputs and training content.  
Your model may partially reinforce existing phrasing patterns.  
**Suggestions**:  
- Mix synthetic and real inputs carefully  
- Monitor training logs for semantic redundancy
""",
        "Low": """
🟒 **Low Risk Score** Your model output and training data appear **diverse** and distinct.  
This is a good sign that your model is learning from **new and varied sources**.  
**You’re on the right track!**
""",
    }

    summary = f"""
### πŸ” Evaluation Summary

**Lexical Diversity (Output):** {ttr_output:.2f}  
TTR = unique words / total words

**Lexical Diversity (Training Set):** {ttr_train:.2f}  
Broader content = higher TTR

**Semantic Similarity (Cosine):** {similarity:.2f}  
Cosine similarity between embeddings

<div style="padding: 1rem; background-color: #fdfdfd; border-left: 6px solid {color}; border-radius: 6px;">
    <strong>MAD Risk Score:</strong> {mad_score:.2f} β†’ <span style='color: {color}; font-weight: bold;'>{risk_level} Risk</span>
</div>
<div style='margin-top: 0.5rem; width: 100%; background: #e0e0e0; border-radius: 10px; height: 16px;'>
    <div style='width: {mad_score * 100:.0f}%; background: {color}; height: 100%; border-radius: 10px;'></div>
</div>
"""

    details = f"""
<details>
<summary>πŸ“Š Score Breakdown</summary>
TTR Component (0.3 Γ— (1 - TTR)): {(1 - ttr_output) * 0.3:.2f}  
Similarity Component (0.7 Γ— Cosine): {similarity * 0.7:.2f}  
MAD Score = 0.3 Γ— (1 - TTR) + 0.7 Γ— Semantic Similarity
</details>
"""

    explanation = f"""
<details>
<summary>πŸ” What does this score mean?</summary>
{risk_explanations[risk_level]}
</details>
"""

    return summary, details, explanation