Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Training progressbar #899

Merged
merged 3 commits into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions chatterbot/trainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys
from .conversation import Statement, Response
from .utils import print_progress_bar


class Trainer(object):
Expand Down Expand Up @@ -79,7 +80,9 @@ def train(self, conversation):
"""
previous_statement_text = None

for text in conversation:
for conversation_count, text in enumerate(conversation):
print_progress_bar("List Trainer", conversation_count + 1, len(conversation))

statement = self.get_or_create(text)

if previous_statement_text:
Expand Down Expand Up @@ -115,8 +118,15 @@ def train(self, *corpus_paths):

corpora = self.corpus.load_corpus(corpus_path)

for corpus in corpora:
for conversation in corpus:
corpus_files = self.corpus.list_corpus_files(corpus_path)
for corpus_count, corpus in enumerate(corpora):
for conversation_count, conversation in enumerate(corpus):
print_progress_bar(
str(os.path.basename(corpus_files[corpus_count])) + " Training",
conversation_count + 1,
len(corpus)
)

previous_statement_text = None

for text in conversation:
Expand Down
29 changes: 29 additions & 0 deletions chatterbot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,32 @@ def generate_strings(total_strings, string_length=20):
)
statements.append(text)
return statements


def print_progress_bar(description, iteration_counter, total_items, progress_bar_length=20):
"""
Print progress bar
:param description: Training description
:type description: str

:param iteration_counter: Incremental counter
:type iteration_counter: int

:param total_items: total number items
:type total_items: int

:param progress_bar_length: Progress bar length
:type progress_bar_length: int

:returns: void
:rtype: void
"""
import sys

percent = float(iteration_counter) / total_items
hashes = '#' * int(round(percent * progress_bar_length))
spaces = ' ' * (progress_bar_length - len(hashes))
sys.stdout.write("\r{0}: [{1}] {2}%".format(description, hashes + spaces, int(round(percent * 100))))
sys.stdout.flush()
if total_items == iteration_counter:
print("\r")