tbitai commited on
Commit
6441204
1 Parent(s): e33f7e6

Refactor and fix unbiasing

Browse files
Files changed (1) hide show
  1. app.py +9 -4
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 = [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
 
 
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