Skip to content

Commit

Permalink
Refactoring in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Nov 21, 2023
1 parent 7a94a40 commit ae2056f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/machine_learning/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, folder: str, tags: str, *, object_saver: ObjectSaver = None,
if app_config:
self.object_saver = ObjectSaver(app_config)
else:
self.object_saver = ObjectSaver({CONFIG_KEY: 'filesystem', 'filesystemDefaultPath': folder})
self.object_saver = ObjectSaver({CONFIG_KEY: 'filesystem', 'filesystemDefaultPath': ''})

def load_models(self, model_files: list[str]) -> list[Any]:
result = []
Expand Down
4 changes: 2 additions & 2 deletions app/machine_learning/models/boosting_decision_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

class BoostingDecisionMaker(MlModel):

def __init__(self, folder: str, n_estimators: int = 75, max_depth: int = 5, monotonous_features: str = '',
tags: str = 'global boosting model', object_saver: ObjectSaver = None,
def __init__(self, folder: str, tags: str = 'global boosting model', *, n_estimators: int = 75, max_depth: int = 5,
monotonous_features: str = '', object_saver: ObjectSaver = None,
app_config: dict[str, Any] = None) -> None:
super().__init__(folder, tags, object_saver=object_saver, app_config=app_config)
self.n_estimators = n_estimators
Expand Down
6 changes: 3 additions & 3 deletions app/machine_learning/models/custom_boosting_decision_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

class CustomBoostingDecisionMaker(BoostingDecisionMaker):

def __init__(self, folder: str, app_config: dict[str, Any], project_id: int | str):
super().__init__(folder=folder, tags='custom boosting model', app_config=app_config,
object_saver=ObjectSaver(app_config, project_id))
def __init__(self, folder: str, *, app_config: dict[str, Any], project_id: int | str):
super().__init__(folder, 'custom boosting model',
object_saver=ObjectSaver(app_config, project_id), app_config=app_config)
14 changes: 6 additions & 8 deletions app/machine_learning/models/weighted_similarity_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
# limitations under the License.

import math
from typing import Any

import numpy as np

from app.machine_learning.models import MlModel
from app.utils import text_processing

MODEL_FILES: list[str] = ['weights.pickle', 'config.pickle']
MODEL_FILES: list[str] = ['weights.pickle']


class WeightedSimilarityCalculator(MlModel):
Expand All @@ -28,19 +29,16 @@ def __init__(self, folder, block_to_split=10, min_log_number_in_block=1):
super().__init__(folder, 'global similarity model')
self.block_to_split = block_to_split
self.min_log_number_in_block = min_log_number_in_block
weights, self.config = self.load_model()
self.block_to_split, self.min_log_number_in_block, self.weights, self.softmax_weights = weights
weights = self.load_model()
self.block_to_split, self.min_log_number_in_block, self.weights, self.softmax_weights = tuple(*weights)

def load_model(self):
def load_model(self) -> list[Any]:
return self.load_models(MODEL_FILES)

def add_config_info(self, config):
self.config = config

def save_model(self):
self.save_models(zip(
MODEL_FILES,
[[self.block_to_split, self.min_log_number_in_block, self.weights, self.softmax_weights], self.config]))
[[self.block_to_split, self.min_log_number_in_block, self.weights, self.softmax_weights]]))

def message_to_array(self, detected_message_res, stacktrace_res):
all_lines = [" ".join(text_processing.split_words(detected_message_res))]
Expand Down

0 comments on commit ae2056f

Please sign in to comment.