wilwork commited on
Commit
4bc3668
·
verified ·
1 Parent(s): a1e51f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -23,8 +23,9 @@ def get_relevance_score_and_excerpt(query, paragraph, threshold_weight):
23
  logit = output.logits.squeeze().item()
24
  base_relevance_score = torch.sigmoid(torch.tensor(logit)).item()
25
 
26
- # Dynamically adjust the attention threshold based on user weight
27
- dynamic_threshold = max(0.02, threshold_weight)
 
28
 
29
  # Extract attention scores (last layer)
30
  attention = output.attentions[-1]
@@ -66,7 +67,7 @@ interface = gr.Interface(
66
  inputs=[
67
  gr.Textbox(label="Query", placeholder="Enter your search query..."),
68
  gr.Textbox(label="Document Paragraph", placeholder="Enter a paragraph to match..."),
69
- gr.Slider(minimum=0.02, maximum=0.5, value=0.1, step=0.01, label="Attention Threshold")
70
  ],
71
  outputs=[
72
  gr.Textbox(label="Relevance Score"),
@@ -74,7 +75,7 @@ interface = gr.Interface(
74
  gr.HTML(label="Highlighted Document Paragraph")
75
  ],
76
  title="Cross-Encoder Attention Highlighting",
77
- description="Adjust the attention threshold to control token highlighting sensitivity.",
78
  allow_flagging="never",
79
  live=True
80
  )
 
23
  logit = output.logits.squeeze().item()
24
  base_relevance_score = torch.sigmoid(torch.tensor(logit)).item()
25
 
26
+ # Calculate dynamic threshold using sigmoid-based formula
27
+ sigmoid_factor = 1 / (1 + torch.exp(-5 * (base_relevance_score - 0.5))).item()
28
+ dynamic_threshold = max(0.02, threshold_weight * sigmoid_factor)
29
 
30
  # Extract attention scores (last layer)
31
  attention = output.attentions[-1]
 
67
  inputs=[
68
  gr.Textbox(label="Query", placeholder="Enter your search query..."),
69
  gr.Textbox(label="Document Paragraph", placeholder="Enter a paragraph to match..."),
70
+ gr.Slider(minimum=0.02, maximum=0.5, value=0.1, step=0.01, label="Threshold Weight")
71
  ],
72
  outputs=[
73
  gr.Textbox(label="Relevance Score"),
 
75
  gr.HTML(label="Highlighted Document Paragraph")
76
  ],
77
  title="Cross-Encoder Attention Highlighting",
78
+ description="Adjust the threshold weight to influence dynamic token highlighting based on relevance.",
79
  allow_flagging="never",
80
  live=True
81
  )