summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-10-04 20:27:01 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-10-04 20:27:01 +0100
commitf6f4ebfbdfe578fe03ad540e8da0f67cf52d9b9a (patch)
tree3db9352bbe642d40918072f957c0c30ae25a12b6
parentce95889425c855e0810eceae6edb9e228cbc2072 (diff)
downloadrspamd-f6f4ebfbdfe578fe03ad540e8da0f67cf52d9b9a.tar.gz
rspamd-f6f4ebfbdfe578fe03ad540e8da0f67cf52d9b9a.zip
[Minor] Filter NaN values when storing training data
-rw-r--r--src/plugins/lua/fann_redis.lua27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/plugins/lua/fann_redis.lua b/src/plugins/lua/fann_redis.lua
index 42e05f1ac..cf6555558 100644
--- a/src/plugins/lua/fann_redis.lua
+++ b/src/plugins/lua/fann_redis.lua
@@ -566,17 +566,24 @@ local function fann_train_callback(rule, task, score, required_score, id)
local mt = meta_functions.rspamd_gen_metatokens(task)
-- Add filtered meta tokens
fun.each(function(e) table.insert(fann_data, e) end, mt)
- local str = rspamd_util.zstd_compress(table.concat(fann_data, ';'))
- vec_len = #str
+ -- Check NaNs in train data
+ if fun.all(function(e) return e == e end, fann_data) then
+ local str = rspamd_util.zstd_compress(table.concat(fann_data, ';'))
+ vec_len = #str
+
+ rspamd_redis.redis_make_request(task,
+ rule.redis,
+ nil,
+ true, -- is write
+ learn_vec_cb, --callback
+ 'LPUSH', -- command
+ {fname .. '_' .. k, str} -- arguments
+ )
+ else
+ rspamd_logger.errx(task, "do not store learn vector as it contains %s NaN values",
+ fun.length(fun.filter(function(e) return e ~= e end, fann_data)))
+ end
- rspamd_redis.redis_make_request(task,
- rule.redis,
- nil,
- true, -- is write
- learn_vec_cb, --callback
- 'LPUSH', -- command
- {fname .. '_' .. k, str} -- arguments
- )
else
if err then
rspamd_logger.errx(task, 'cannot check if we can train %s: %s', fname, err)