Update app.py
Browse files
app.py
CHANGED
@@ -10,8 +10,12 @@ model.eval()
|
|
10 |
|
11 |
# Sigmoid-based threshold adjustment function
|
12 |
def calculate_threshold(base_relevance, min_threshold=0.02, max_threshold=0.5, k=10):
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
# Function to compute relevance score and dynamically adjust threshold
|
16 |
def get_relevance_score_and_excerpt(query, paragraph, threshold_weight):
|
17 |
if not query.strip() or not paragraph.strip():
|
|
|
10 |
|
11 |
# Sigmoid-based threshold adjustment function
|
12 |
def calculate_threshold(base_relevance, min_threshold=0.02, max_threshold=0.5, k=10):
|
13 |
+
base_relevance_tensor = torch.tensor(base_relevance) # Ensure input is a tensor
|
14 |
+
threshold = min_threshold + (max_threshold - min_threshold) * (
|
15 |
+
1 / (1 + torch.exp(-k * (base_relevance_tensor - 0.5)))
|
16 |
+
)
|
17 |
+
return threshold.item() # Convert tensor back to float for use in other functions
|
18 |
+
|
19 |
# Function to compute relevance score and dynamically adjust threshold
|
20 |
def get_relevance_score_and_excerpt(query, paragraph, threshold_weight):
|
21 |
if not query.strip() or not paragraph.strip():
|