Ubuntu commited on
Commit
bc48736
·
1 Parent(s): aa8e01f
Files changed (3) hide show
  1. run.sh +1 -0
  2. src/training_pipeline.py +15 -16
  3. test_model.py +10 -9
run.sh CHANGED
@@ -94,5 +94,6 @@ echo ""
94
  echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
95
  echo -e "${BLUE}║ Testing Model ║${NC}"
96
  echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
 
97
 
98
  python3 test_model.py ./model
 
94
  echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
95
  echo -e "${BLUE}║ Testing Model ║${NC}"
96
  echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
97
+ echo ""
98
 
99
  python3 test_model.py ./model
src/training_pipeline.py CHANGED
@@ -21,7 +21,6 @@ from transformers import (
21
  DataCollatorWithPadding,
22
  )
23
  from transformers.trainer_callback import TrainerCallback
24
- import evaluate
25
  import numpy as np
26
  from tqdm import tqdm
27
 
@@ -30,6 +29,8 @@ logging.getLogger("filelock").setLevel(logging.ERROR)
30
  logging.getLogger("urllib3").setLevel(logging.ERROR)
31
  logging.getLogger("huggingface_hub").setLevel(logging.ERROR)
32
  logging.getLogger("datasets").setLevel(logging.ERROR)
 
 
33
 
34
  load_dotenv()
35
 
@@ -71,17 +72,10 @@ def load_config(config_name: str = 'config'):
71
  return OmegaConf.to_container(conf, resolve=True)
72
 
73
 
74
- def print_model_load_report(model, pretrained_name):
75
- """Clean model loading status"""
76
- print(f"\n📦 Model: {model.__class__.__name__}")
77
- print(f" Source: {pretrained_name}")
78
- print(f" Params: {sum(p.numel() for p in model.parameters()):,}")
79
- print(f" ✓ Base weights loaded")
80
- print(f" ✓ New regression head added\n")
81
-
82
-
83
  def compute_metrics(eval_pred, metric_names=['mse', 'mae', 'r2']):
84
- """Compute regression metrics"""
 
 
85
  predictions, labels = eval_pred
86
 
87
  if isinstance(predictions, tuple):
@@ -90,10 +84,11 @@ def compute_metrics(eval_pred, metric_names=['mse', 'mae', 'r2']):
90
  predictions = predictions.squeeze(-1)
91
  labels = labels.squeeze(-1)
92
 
93
- results = {}
94
- for name in metric_names:
95
- metric = evaluate.load(name)
96
- results[name] = metric.compute(predictions=predictions, references=labels)
 
97
 
98
  return results
99
 
@@ -270,7 +265,10 @@ def train(config_name: str = 'config', epochs: int = None, batch_size: int = Non
270
  )
271
  pbar.update(100)
272
 
273
- print_model_load_report(model, model_cfg['name'])
 
 
 
274
 
275
  # Tokenize - combine text features and normalize audio features
276
  print("🔧 Preprocessing data...")
@@ -358,6 +356,7 @@ def train(config_name: str = 'config', epochs: int = None, batch_size: int = Non
358
  greater_is_better=False,
359
  report_to='none',
360
  disable_tqdm=False,
 
361
  )
362
 
363
  # Train
 
21
  DataCollatorWithPadding,
22
  )
23
  from transformers.trainer_callback import TrainerCallback
 
24
  import numpy as np
25
  from tqdm import tqdm
26
 
 
29
  logging.getLogger("urllib3").setLevel(logging.ERROR)
30
  logging.getLogger("huggingface_hub").setLevel(logging.ERROR)
31
  logging.getLogger("datasets").setLevel(logging.ERROR)
32
+ logging.getLogger("transformers").setLevel(logging.ERROR)
33
+ logging.getLogger("torch").setLevel(logging.ERROR)
34
 
35
  load_dotenv()
36
 
 
72
  return OmegaConf.to_container(conf, resolve=True)
73
 
74
 
 
 
 
 
 
 
 
 
 
75
  def compute_metrics(eval_pred, metric_names=['mse', 'mae', 'r2']):
76
+ """Compute regression metrics using scikit-learn"""
77
+ from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
78
+
79
  predictions, labels = eval_pred
80
 
81
  if isinstance(predictions, tuple):
 
84
  predictions = predictions.squeeze(-1)
85
  labels = labels.squeeze(-1)
86
 
87
+ results = {
88
+ 'mse': mean_squared_error(labels, predictions),
89
+ 'mae': mean_absolute_error(labels, predictions),
90
+ 'r2': r2_score(labels, predictions),
91
+ }
92
 
93
  return results
94
 
 
265
  )
266
  pbar.update(100)
267
 
268
+ print(f"\n📦 Model: {model.__class__.__name__}")
269
+ print(f" Source: {model_cfg['name']}")
270
+ print(f" Params: {sum(p.numel() for p in model.parameters()):,}")
271
+ print(f" ✓ Ready for training\n")
272
 
273
  # Tokenize - combine text features and normalize audio features
274
  print("🔧 Preprocessing data...")
 
356
  greater_is_better=False,
357
  report_to='none',
358
  disable_tqdm=False,
359
+ dataloader_pin_memory=False,
360
  )
361
 
362
  # Train
test_model.py CHANGED
@@ -4,17 +4,23 @@ Usage: python test_model.py <model_path>
4
  """
5
 
6
  import sys
 
7
  import torch
8
  from pathlib import Path
9
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
10
 
 
 
 
 
11
 
12
  def load_model(model_path):
13
  """Load trained model"""
14
- print(f"Loading model from: {model_path}")
15
  tokenizer = AutoTokenizer.from_pretrained(model_path)
16
  model = AutoModelForSequenceClassification.from_pretrained(model_path)
17
  model.eval()
 
18
  return model, tokenizer
19
 
20
 
@@ -282,11 +288,6 @@ if __name__ == '__main__':
282
  sys.exit(1)
283
 
284
  model, tokenizer = load_model(model_path)
285
-
286
- # Ask if user wants interactive mode
287
- mode = input("\n🔧 Test mode: (1) Default tracks (2) Interactive [1]: ").strip()
288
-
289
- if mode == '2' or mode.lower() == 'i':
290
- interactive_mode(model, tokenizer)
291
- else:
292
- test_model(model_path)
 
4
  """
5
 
6
  import sys
7
+ import logging
8
  import torch
9
  from pathlib import Path
10
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
11
 
12
+ # Suppress logs
13
+ logging.getLogger("transformers").setLevel(logging.ERROR)
14
+ logging.getLogger("torch").setLevel(logging.ERROR)
15
+
16
 
17
  def load_model(model_path):
18
  """Load trained model"""
19
+ print(f"Loading model from: {model_path}")
20
  tokenizer = AutoTokenizer.from_pretrained(model_path)
21
  model = AutoModelForSequenceClassification.from_pretrained(model_path)
22
  model.eval()
23
+ print(f"✓ Model loaded\n")
24
  return model, tokenizer
25
 
26
 
 
288
  sys.exit(1)
289
 
290
  model, tokenizer = load_model(model_path)
291
+
292
+ # Run default test tracks automatically
293
+ test_model(model_path)