Ani-404 commited on
Commit
05c46bd
·
1 Parent(s): ec64475

updated training script

Browse files
Files changed (1) hide show
  1. finance/train_finbert.py +5 -5
finance/train_finbert.py CHANGED
@@ -29,7 +29,7 @@ def compute_metrics(p):
29
 
30
  def main():
31
  """Main function to load data, fine-tune the FinBERT model, and save it."""
32
- # --- 1. Load and Prepare the Dataset ---
33
  print("Loading and preparing the dataset...")
34
  try:
35
  # Build the correct path to the data file
@@ -58,7 +58,7 @@ def main():
58
  train_dataset = Dataset.from_pandas(train_df)
59
  val_dataset = Dataset.from_pandas(val_df)
60
 
61
- # --- 2. Load Tokenizer and Preprocess Data ---
62
  print("Loading tokenizer and preprocessing data...")
63
  model_name = "ProsusAI/finbert"
64
  tokenizer = AutoTokenizer.from_pretrained(model_name)
@@ -71,7 +71,7 @@ def main():
71
  tokenized_train_dataset = train_dataset.map(tokenize_function, batched=True)
72
  tokenized_val_dataset = val_dataset.map(tokenize_function, batched=True)
73
 
74
- # --- 3. Load and Configure the Model ---
75
  print("Loading pre-trained model...")
76
  model = AutoModelForSequenceClassification.from_pretrained(
77
  model_name,
@@ -81,7 +81,7 @@ def main():
81
  ignore_mismatched_sizes=True, # The pre-trained model has a different number of labels
82
  )
83
 
84
- # --- 4. Fine-Tune the Model ---
85
  print("Starting model fine-tuning...")
86
  output_dir = os.path.join(script_dir, "finbert_emotion_model")
87
  print(f"Model will be saved to: {output_dir}")
@@ -107,7 +107,7 @@ def main():
107
 
108
  trainer.train()
109
 
110
- # --- 5. Save and Verify the Model ---
111
  print(f"Training complete. Saving model and tokenizer to '{output_dir}'...")
112
  trainer.save_model(output_dir)
113
  tokenizer.save_pretrained(output_dir)
 
29
 
30
  def main():
31
  """Main function to load data, fine-tune the FinBERT model, and save it."""
32
+ # 1. Load and Prepare the Dataset
33
  print("Loading and preparing the dataset...")
34
  try:
35
  # Build the correct path to the data file
 
58
  train_dataset = Dataset.from_pandas(train_df)
59
  val_dataset = Dataset.from_pandas(val_df)
60
 
61
+ # 2. Load Tokenizer and Preprocess Data
62
  print("Loading tokenizer and preprocessing data...")
63
  model_name = "ProsusAI/finbert"
64
  tokenizer = AutoTokenizer.from_pretrained(model_name)
 
71
  tokenized_train_dataset = train_dataset.map(tokenize_function, batched=True)
72
  tokenized_val_dataset = val_dataset.map(tokenize_function, batched=True)
73
 
74
+ # 3. Load and Configure the Model
75
  print("Loading pre-trained model...")
76
  model = AutoModelForSequenceClassification.from_pretrained(
77
  model_name,
 
81
  ignore_mismatched_sizes=True, # The pre-trained model has a different number of labels
82
  )
83
 
84
+ # 4. Fine-Tune the Model
85
  print("Starting model fine-tuning...")
86
  output_dir = os.path.join(script_dir, "finbert_emotion_model")
87
  print(f"Model will be saved to: {output_dir}")
 
107
 
108
  trainer.train()
109
 
110
+ # 5. Save and Verify the Model
111
  print(f"Training complete. Saving model and tokenizer to '{output_dir}'...")
112
  trainer.save_model(output_dir)
113
  tokenizer.save_pretrained(output_dir)