Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more logging to training process #61

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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