Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,18 +71,10 @@ if (should_train_model=='1'): #train model
|
|
| 71 |
bias_non_fleet = 1.0
|
| 72 |
epochs_to_run = 15
|
| 73 |
|
| 74 |
-
#file_path_train = train_file + ".csv"
|
| 75 |
-
#file_path_test = test_file + ".csv"
|
| 76 |
-
|
| 77 |
-
# Read the CSV files into pandas DataFrames they will later by converted to DataTables and used to train and evaluate the model
|
| 78 |
-
#file_train_df = pd.read_csv(file_path_train)
|
| 79 |
-
#file_test_df = pd.read_csv(file_path_test)
|
| 80 |
-
|
| 81 |
file_path_train = train_file + ".csv"
|
| 82 |
file_path_test = test_file + ".csv"
|
| 83 |
|
| 84 |
# Read the CSV files into pandas DataFrames they will later by converted to DataTables and used to train and evaluate the model
|
| 85 |
-
#file_train_df = pd.read_csv(file_path_train)
|
| 86 |
|
| 87 |
file_train_df = fetch_and_update_training_data(file_path_train)
|
| 88 |
file_test_df = pd.read_csv(file_path_test)
|
|
@@ -181,7 +173,6 @@ if (should_train_model=='1'): #train model
|
|
| 181 |
accuracy = (preds == labels).astype(float).mean()
|
| 182 |
return {"accuracy": accuracy}
|
| 183 |
|
| 184 |
-
|
| 185 |
training_args = TrainingArguments(
|
| 186 |
output_dir='./results',
|
| 187 |
num_train_epochs=epochs_to_run,
|
|
@@ -195,10 +186,6 @@ if (should_train_model=='1'): #train model
|
|
| 195 |
evaluation_strategy="epoch",
|
| 196 |
)
|
| 197 |
|
| 198 |
-
# notice the bias_non_float in next line (it is given a value at top of code)
|
| 199 |
-
# class_weights = torch.tensor([1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,bias_non_fleet,1.0,1.0]) # Replace with your actual class weights
|
| 200 |
-
# class_weights = class_weights.to('cuda' if torch.cuda.is_available() else 'cpu')
|
| 201 |
-
|
| 202 |
# This is needed b/c loss_fn is swapped out in order to use weighted loss
|
| 203 |
# Any class weights that are not equal to one will make the model more (if greater than one) or less (if less than one)sensitive to given label
|
| 204 |
class CustomTrainer(Trainer):
|
|
@@ -222,14 +209,6 @@ if (should_train_model=='1'): #train model
|
|
| 222 |
tokenizer=tokenizer
|
| 223 |
)
|
| 224 |
|
| 225 |
-
# Train the model and set timer to measure the training time
|
| 226 |
-
start_time = time.time()
|
| 227 |
-
trainer.train()
|
| 228 |
-
end_time = time.time()
|
| 229 |
-
execution_time = end_time - start_time
|
| 230 |
-
|
| 231 |
-
print(f"Execution Time: {execution_time:.2f} seconds")
|
| 232 |
-
|
| 233 |
# send validation prompts through the model - will be used in error-analysis matrix below
|
| 234 |
preds_output = trainer.predict(emotions_encoded["validation"])
|
| 235 |
|
|
@@ -311,14 +290,12 @@ if (should_train_model=='1'): #train model
|
|
| 311 |
create_repo(repo_id=repo_name, token=api_token, exist_ok=True)
|
| 312 |
|
| 313 |
# Upload the model and tokenizer to the Hugging Face repository
|
| 314 |
-
|
| 315 |
upload_folder(
|
| 316 |
folder_path=f"{model_save_path}",
|
| 317 |
path_in_repo=f"{model_save_path}",
|
| 318 |
repo_id=repo_name,
|
| 319 |
token=api_token,
|
| 320 |
-
commit_message="Push model",
|
| 321 |
-
#overwrite=True # Force overwrite existing files
|
| 322 |
)
|
| 323 |
|
| 324 |
else:
|
|
|
|
| 71 |
bias_non_fleet = 1.0
|
| 72 |
epochs_to_run = 15
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
file_path_train = train_file + ".csv"
|
| 75 |
file_path_test = test_file + ".csv"
|
| 76 |
|
| 77 |
# Read the CSV files into pandas DataFrames they will later by converted to DataTables and used to train and evaluate the model
|
|
|
|
| 78 |
|
| 79 |
file_train_df = fetch_and_update_training_data(file_path_train)
|
| 80 |
file_test_df = pd.read_csv(file_path_test)
|
|
|
|
| 173 |
accuracy = (preds == labels).astype(float).mean()
|
| 174 |
return {"accuracy": accuracy}
|
| 175 |
|
|
|
|
| 176 |
training_args = TrainingArguments(
|
| 177 |
output_dir='./results',
|
| 178 |
num_train_epochs=epochs_to_run,
|
|
|
|
| 186 |
evaluation_strategy="epoch",
|
| 187 |
)
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
# This is needed b/c loss_fn is swapped out in order to use weighted loss
|
| 190 |
# Any class weights that are not equal to one will make the model more (if greater than one) or less (if less than one)sensitive to given label
|
| 191 |
class CustomTrainer(Trainer):
|
|
|
|
| 209 |
tokenizer=tokenizer
|
| 210 |
)
|
| 211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
# send validation prompts through the model - will be used in error-analysis matrix below
|
| 213 |
preds_output = trainer.predict(emotions_encoded["validation"])
|
| 214 |
|
|
|
|
| 290 |
create_repo(repo_id=repo_name, token=api_token, exist_ok=True)
|
| 291 |
|
| 292 |
# Upload the model and tokenizer to the Hugging Face repository
|
|
|
|
| 293 |
upload_folder(
|
| 294 |
folder_path=f"{model_save_path}",
|
| 295 |
path_in_repo=f"{model_save_path}",
|
| 296 |
repo_id=repo_name,
|
| 297 |
token=api_token,
|
| 298 |
+
commit_message="Push model and tokenizer",
|
|
|
|
| 299 |
)
|
| 300 |
|
| 301 |
else:
|