Skip to content

Commit

Permalink
more logging to training process (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
Szer authored Oct 21, 2024
1 parent 1b846b9 commit 585ff98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/VahterBanBot/ML.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type MachineLearning(
let trainDate = DateTime.UtcNow - botConf.MlTrainInterval
let! rawData = DB.mlData botConf.MlTrainCriticalMsgCount trainDate

logger.LogInformation $"Training data count: {rawData.Length}"

let data =
rawData
|> Array.map (fun x ->
Expand Down Expand Up @@ -94,19 +96,27 @@ type MachineLearning(
featureColumnName = "Features",
maximumNumberOfIterations = botConf.MlMaxNumberOfIterations
))

logger.LogInformation "Fitting model..."

let trainedModel = dataProcessPipeline.Fit(trainingData)

logger.LogInformation "Evaluating model..."

predictionEngine <- Some(mlContext.Model.CreatePredictionEngine<SpamOrHam, Prediction>(trainedModel))

let predictions = trainedModel.Transform(testData)
let metrics = mlContext.BinaryClassification.Evaluate(data = predictions, labelColumnName = "spam", scoreColumnName = "Score")

logger.LogInformation "Model transformation complete"

sw.Stop()

let metricsStr = metricsToString metrics sw.Elapsed
logger.LogInformation metricsStr
do! telegramClient.SendTextMessageAsync(ChatId(botConf.LogsChannelId), metricsStr, parseMode = ParseMode.Markdown)
|> taskIgnore
logger.LogInformation "Model trained"
with ex ->
logger.LogError(ex, "Error training model")
}
Expand Down
2 changes: 1 addition & 1 deletion src/VahterBanBot/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ let botConf =
MlTrainingSetFraction = getEnvOr "ML_TRAINING_SET_FRACTION" "0.2" |> float
MlSpamThreshold = getEnvOr "ML_SPAM_THRESHOLD" "0.5" |> single
MlWarningThreshold = getEnvOr "ML_WARNING_THRESHOLD" "0.0" |> single
MlMaxNumberOfIterations = getEnvOr "ML_MAX_NUMBER_OF_ITERATIONS" "100" |> int
MlMaxNumberOfIterations = getEnvOr "ML_MAX_NUMBER_OF_ITERATIONS" "50" |> int
MlStopWordsInChats = getEnvOr "ML_STOP_WORDS_IN_CHATS" "{}" |> fromJson }

let validateApiKey (ctx : HttpContext) =
Expand Down

0 comments on commit 585ff98

Please sign in to comment.