File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,16 @@ def classify(message_text)
89
89
ham_score += Math . log ( ham_count . to_f / ( @classifier_state . total_ham_words + vocab_size ) )
90
90
end
91
91
92
- is_spam = spam_score > ham_score
92
+ diff = spam_score - ham_score
93
+ # stable logistic conversion
94
+ p_spam = if diff . abs > 700
95
+ diff > 0 ? 1.0 : 0.0
96
+ else
97
+ 1.0 / ( 1.0 + Math . exp ( -diff ) )
98
+ end
99
+
100
+ confidence_threshold = Rails . application . config . probability_threshold
101
+ is_spam = p_spam >= confidence_threshold
93
102
[ is_spam , spam_score , ham_score ]
94
103
end
95
104
Original file line number Diff line number Diff line change @@ -29,5 +29,7 @@ class Application < Rails::Application
29
29
config . spam_ban_threshold = 3
30
30
# Delete the warning message in x minutes to keep chat clean
31
31
config . delete_message_delay = 5
32
+ # Spam blocked probability threshold
33
+ config . probability_threshold = 0.95
32
34
end
33
35
end
You can’t perform that action at this time.
0 commit comments