Spam filter: Fix training sample size checks
This commit is contained in:
@@ -262,8 +262,12 @@ impl SpamClassifier for Server {
|
|||||||
Spam(SpamEvent::ModelNotReady),
|
Spam(SpamEvent::ModelNotReady),
|
||||||
Reason = "Not enough samples for training",
|
Reason = "Not enough samples for training",
|
||||||
Details = vec![
|
Details = vec![
|
||||||
trc::Value::from(ham_count + trainer.reservoir.ham.total_seen),
|
trc::Value::from(trainer.reservoir.ham.total_seen),
|
||||||
trc::Value::from(spam_count + trainer.reservoir.spam.total_seen)
|
trc::Value::from(trainer.reservoir.spam.total_seen)
|
||||||
|
],
|
||||||
|
Limit = vec![
|
||||||
|
trc::Value::from(config.min_ham_samples),
|
||||||
|
trc::Value::from(config.min_spam_samples)
|
||||||
],
|
],
|
||||||
Elapsed = started.elapsed()
|
Elapsed = started.elapsed()
|
||||||
);
|
);
|
||||||
@@ -273,7 +277,7 @@ impl SpamClassifier for Server {
|
|||||||
|
|
||||||
// Balance classes if needed
|
// Balance classes if needed
|
||||||
if spam_count > ham_count {
|
if spam_count > ham_count {
|
||||||
// We have too much spam today. We need to replay old HAM.
|
// We have too much spam this time. We need to replay old HAM.
|
||||||
samples.extend(
|
samples.extend(
|
||||||
trainer
|
trainer
|
||||||
.reservoir
|
.reservoir
|
||||||
@@ -286,7 +290,7 @@ impl SpamClassifier for Server {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} else if ham_count > spam_count {
|
} else if ham_count > spam_count {
|
||||||
// We have too much ham today. We need to replay old SPAM.
|
// We have too much ham this time. We need to replay old SPAM.
|
||||||
samples.extend(
|
samples.extend(
|
||||||
trainer
|
trainer
|
||||||
.reservoir
|
.reservoir
|
||||||
@@ -491,32 +495,20 @@ impl SpamClassifier for Server {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.caused_by(trc::location!())?;
|
.caused_by(trc::location!())?;
|
||||||
if ham_count >= config.min_ham_samples && spam_count >= config.min_spam_samples {
|
self.blob_store()
|
||||||
self.blob_store()
|
.put_blob(
|
||||||
.put_blob(
|
SPAM_CLASSIFIER_KEY,
|
||||||
SPAM_CLASSIFIER_KEY,
|
&classifier.serialize().caused_by(trc::location!())?,
|
||||||
&classifier.serialize().caused_by(trc::location!())?,
|
)
|
||||||
)
|
.await
|
||||||
.await
|
.caused_by(trc::location!())?;
|
||||||
.caused_by(trc::location!())?;
|
|
||||||
|
|
||||||
self.inner
|
self.inner
|
||||||
.data
|
.data
|
||||||
.spam_classifier
|
.spam_classifier
|
||||||
.store(Arc::new(classifier.inner));
|
.store(Arc::new(classifier.inner));
|
||||||
self.cluster_broadcast(BroadcastEvent::ReloadSpamFilter)
|
self.cluster_broadcast(BroadcastEvent::ReloadSpamFilter)
|
||||||
.await;
|
.await;
|
||||||
} else {
|
|
||||||
self.blob_store()
|
|
||||||
.delete_blob(SPAM_CLASSIFIER_KEY)
|
|
||||||
.await
|
|
||||||
.caused_by(trc::location!())?;
|
|
||||||
|
|
||||||
trc::event!(
|
|
||||||
Spam(SpamEvent::ModelNotReady),
|
|
||||||
Details = vec![trc::Value::from(ham_count), trc::Value::from(spam_count)],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
trc::event!(
|
trc::event!(
|
||||||
Spam(SpamEvent::TrainCompleted),
|
Spam(SpamEvent::TrainCompleted),
|
||||||
|
|||||||
Reference in New Issue
Block a user