Skip to content

Commit

Permalink
limited learning iteration number (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Szer authored Oct 21, 2024
1 parent fbcbf60 commit 1b846b9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ ML_TRAINING_SET_FRACTION=0.2
ML_SPAM_THRESHOLD=0.5
ML_WARNING_THRESHOLD=0.0
ML_STOP_WORDS_IN_CHATS={"-123":["word1","word2"]}
ML_MAX_NUMBER_OF_ITERATIONS=100
UPDATE_CHAT_ADMINS_INTERVAL_SEC=86400
UPDATE_CHAT_ADMINS=true
6 changes: 5 additions & 1 deletion src/VahterBanBot/ML.fs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ type MachineLearning(
mlContext.Transforms.Text
.FeaturizeText(outputColumnName = "TextFeaturized", inputColumnName = "text")
.Append(mlContext.Transforms.Concatenate(outputColumnName = "Features", inputColumnNames = [|"TextFeaturized"; "lessThanNMessagesF";|]))
.Append(mlContext.BinaryClassification.Trainers.LbfgsLogisticRegression(labelColumnName = "spam", featureColumnName = "Features"))
.Append(mlContext.BinaryClassification.Trainers.SdcaLogisticRegression(
labelColumnName = "spam",
featureColumnName = "Features",
maximumNumberOfIterations = botConf.MlMaxNumberOfIterations
))

let trainedModel = dataProcessPipeline.Fit(trainingData)
predictionEngine <- Some(mlContext.Model.CreatePredictionEngine<SpamOrHam, Prediction>(trainedModel))
Expand Down
1 change: 1 addition & 0 deletions src/VahterBanBot/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +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
MlStopWordsInChats = getEnvOr "ML_STOP_WORDS_IN_CHATS" "{}" |> fromJson }

let validateApiKey (ctx : HttpContext) =
Expand Down
1 change: 1 addition & 0 deletions src/VahterBanBot/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type BotConfiguration =
MlTrainingSetFraction: float
MlSpamThreshold: single
MlWarningThreshold: single
MlMaxNumberOfIterations: int
MlStopWordsInChats: Dictionary<int64, string list> }

[<CLIMutable>]
Expand Down

0 comments on commit 1b846b9

Please sign in to comment.