Pujan-Dev commited on
Commit
49fe170
·
1 Parent(s): 4d6298c

fixed :fixed the testing error

Browse files
features/nepali_text_classifier/model_loader.py CHANGED
@@ -8,6 +8,7 @@ from pathlib import Path
8
  import numpy as np
9
  import pandas as pd
10
  from huggingface_hub import snapshot_download
 
11
 
12
  from config import Config
13
 
@@ -45,6 +46,13 @@ DEFAULT_MODEL_RANKING = [
45
  ]
46
 
47
 
 
 
 
 
 
 
 
48
  class NepaliRichFeatures:
49
  """Burstiness + stylometry feature extractor used during model training."""
50
 
@@ -176,7 +184,7 @@ def load_artifacts():
176
  unavailable[model_name] = "Missing model file"
177
  continue
178
  with open(file_path, "rb") as fp:
179
- models[model_name] = pickle.load(fp)
180
 
181
  with open(model_dir / "word_vectorizer.pkl", "rb") as fp:
182
  word_vectorizer = pickle.load(fp)
 
8
  import numpy as np
9
  import pandas as pd
10
  from huggingface_hub import snapshot_download
11
+ from sklearn.linear_model import LogisticRegression, LogisticRegressionCV
12
 
13
  from config import Config
14
 
 
46
  ]
47
 
48
 
49
+ def _patch_legacy_logistic_model(model):
50
+ """Backfill attributes expected by newer sklearn versions."""
51
+ if isinstance(model, (LogisticRegression, LogisticRegressionCV)) and not hasattr(model, "multi_class"):
52
+ model.multi_class = "auto"
53
+ return model
54
+
55
+
56
  class NepaliRichFeatures:
57
  """Burstiness + stylometry feature extractor used during model training."""
58
 
 
184
  unavailable[model_name] = "Missing model file"
185
  continue
186
  with open(file_path, "rb") as fp:
187
+ models[model_name] = _patch_legacy_logistic_model(pickle.load(fp))
188
 
189
  with open(model_dir / "word_vectorizer.pkl", "rb") as fp:
190
  word_vectorizer = pickle.load(fp)
features/text_classifier/model_loader.py CHANGED
@@ -6,6 +6,7 @@ from pathlib import Path
6
 
7
  import torch
8
  from huggingface_hub import snapshot_download
 
9
 
10
  from config import Config
11
 
@@ -26,6 +27,13 @@ REQUIRED_FILES = (
26
  )
27
 
28
 
 
 
 
 
 
 
 
29
  def _has_required_artifacts(model_dir: Path) -> bool:
30
  if not model_dir.exists() or not model_dir.is_dir():
31
  return False
@@ -79,6 +87,7 @@ def load_model():
79
 
80
  with open(artifact_dir / "classifier.pkl", "rb") as f:
81
  loaded_classifier = pickle.load(f)
 
82
 
83
  with open(artifact_dir / "scaler.pkl", "rb") as f:
84
  loaded_scaler = pickle.load(f)
 
6
 
7
  import torch
8
  from huggingface_hub import snapshot_download
9
+ from sklearn.linear_model import LogisticRegression, LogisticRegressionCV
10
 
11
  from config import Config
12
 
 
27
  )
28
 
29
 
30
+ def _patch_legacy_logistic_model(model):
31
+ """Backfill attributes expected by newer sklearn versions."""
32
+ if isinstance(model, (LogisticRegression, LogisticRegressionCV)) and not hasattr(model, "multi_class"):
33
+ model.multi_class = "auto"
34
+ return model
35
+
36
+
37
  def _has_required_artifacts(model_dir: Path) -> bool:
38
  if not model_dir.exists() or not model_dir.is_dir():
39
  return False
 
87
 
88
  with open(artifact_dir / "classifier.pkl", "rb") as f:
89
  loaded_classifier = pickle.load(f)
90
+ loaded_classifier = _patch_legacy_logistic_model(loaded_classifier)
91
 
92
  with open(artifact_dir / "scaler.pkl", "rb") as f:
93
  loaded_scaler = pickle.load(f)