Spaces:
Running
Running
Refactor and fix unbiasing
Browse files
app.py
CHANGED
@@ -30,12 +30,17 @@ def get_interesting_probs(probs, intr_threshold):
|
|
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 = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
interesting_probs = get_interesting_probs(probs, intr_threshold)
|
40 |
return combine(interesting_probs)
|
41 |
|
|
|
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 = []
|
36 |
+
for w in words:
|
37 |
+
try:
|
38 |
+
p = model_probs[w]
|
39 |
+
if unbiased:
|
40 |
+
p = unbias(p)
|
41 |
+
except KeyError:
|
42 |
+
p = model_probs[UNK]
|
43 |
+
probs.append(p)
|
44 |
interesting_probs = get_interesting_probs(probs, intr_threshold)
|
45 |
return combine(interesting_probs)
|
46 |
|