Spaces:
Sleeping
Sleeping
Fix unbiasing
Browse files
app.py
CHANGED
|
@@ -30,11 +30,12 @@ def get_interesting_probs(probs, intr_threshold):
|
|
| 30 |
def unbias(p):
|
| 31 |
return (2 * p) / (p + 1)
|
| 32 |
|
|
|
|
|
|
|
|
|
|
| 33 |
def predict_bayes(text, intr_threshold, unbiased=False):
|
| 34 |
words = tokenize(text)
|
| 35 |
-
probs = [model_probs.get(w, model_probs[UNK]) for w in words]
|
| 36 |
-
if unbiased:
|
| 37 |
-
probs = [unbias(p) for p in probs]
|
| 38 |
interesting_probs = get_interesting_probs(probs, intr_threshold)
|
| 39 |
return combine(interesting_probs)
|
| 40 |
|
|
|
|
| 30 |
def unbias(p):
|
| 31 |
return (2 * p) / (p + 1)
|
| 32 |
|
| 33 |
+
def unbias_or_noop(p, noop=False):
|
| 34 |
+
return unbias(p) if not noop else p
|
| 35 |
+
|
| 36 |
def predict_bayes(text, intr_threshold, unbiased=False):
|
| 37 |
words = tokenize(text)
|
| 38 |
+
probs = [unbias_or_noop(model_probs.get(w, model_probs[UNK]), noop=not unbiased) for w in words]
|
|
|
|
|
|
|
| 39 |
interesting_probs = get_interesting_probs(probs, intr_threshold)
|
| 40 |
return combine(interesting_probs)
|
| 41 |
|