Hyacinthax commited on
Commit
91952ec
·
verified ·
1 Parent(s): 91e4aed

Fixed ValueError

Browse files

Added a try except block for the functions to see if a value error is brought up since it's only for that instance.

Files changed (1) hide show
  1. runCorpus.py +20 -12
runCorpus.py CHANGED
@@ -133,19 +133,25 @@ class CorpusTrainer:
133
 
134
  data = [input_text, target_text]
135
 
136
- # User Choices
137
- if user_choice in self.choices_yes and play_notification in self.choices_yes:
138
- self.user_yes(speaker=speaker, data=data, limit=limit, play_notification=play_notification)
 
139
 
140
 
141
- elif user_choice in self.choices_yes and play_notification not in self.choices_yes:
142
- self.user_yes(speaker=speaker, data=data, limit=limit, play_notification=play_notification)
143
 
144
 
145
- elif user_choice not in self.choices_yes and play_notification not in self.choices_yes:
146
- self.user_no(speaker=speaker, data=data, limit=limit, play_notification=play_notification)
147
 
 
 
 
148
 
 
 
149
 
150
  def user_yes(self, data, speaker, limit, play_notification):
151
  self.chatbot_trainer.train_model(data[0], data[1], str(self.conversation_id), speaker)
@@ -355,11 +361,13 @@ class CorpusTrainer:
355
 
356
  print(f"Logged {num_failures} failures.")
357
 
 
 
 
 
 
 
358
 
359
  if __name__ == "__main__":
360
  while True:
361
- app = CorpusTrainer()
362
- user_choice = input(f"Run Supervised?({app.chatbot_trainer.model_filename})\n>")
363
- play_notification = input(f"Would you like to play a notification after each training?\nHelps with manual stopping before max_vocabulary reached... \n>")
364
- app.main(chatbot_trainer=app.chatbot_trainer, user_choice=user_choice, dialog_data=dialog_data, play_notification=play_notification)
365
-
 
133
 
134
  data = [input_text, target_text]
135
 
136
+ try:
137
+ # User Choices
138
+ if user_choice in self.choices_yes and play_notification in self.choices_yes:
139
+ self.user_yes(speaker=speaker, data=data, limit=limit, play_notification=play_notification)
140
 
141
 
142
+ elif user_choice in self.choices_yes and play_notification not in self.choices_yes:
143
+ self.user_yes(speaker=speaker, data=data, limit=limit, play_notification=play_notification)
144
 
145
 
146
+ elif user_choice not in self.choices_yes and play_notification not in self.choices_yes:
147
+ self.user_no(speaker=speaker, data=data, limit=limit, play_notification=play_notification)
148
 
149
+ except ValueError:
150
+ print("Skipped Conversation {speaker}... Trying again...")
151
+ continue
152
 
153
+ except Exception as e:
154
+ print(e)
155
 
156
  def user_yes(self, data, speaker, limit, play_notification):
157
  self.chatbot_trainer.train_model(data[0], data[1], str(self.conversation_id), speaker)
 
361
 
362
  print(f"Logged {num_failures} failures.")
363
 
364
+ def run():
365
+ app = CorpusTrainer()
366
+ user_choice = input(f"Run Supervised?({app.chatbot_trainer.model_filename})\n>")
367
+ play_notification = input(f"Would you like to play a notification after each training?\nHelps with manual stopping before max_vocabulary reached... \n>")
368
+ app.main(chatbot_trainer=app.chatbot_trainer, user_choice=user_choice, dialog_data=dialog_data, play_notification=play_notification)
369
+
370
 
371
  if __name__ == "__main__":
372
  while True:
373
+ run()