Utility Methods

ChatterBot has a utility module that contains a collection of miscellaneous but useful functions.

Module imports


Imports the specified module based on the dot notated import path for the module.

Class initialization

chatterbot.utils.initialize_class(data, **kwargs)[source]
Parameters:data – A string or dictionary containing a import_path attribute.

Terminal input


Normalizes reading input between python 2 and 3. The function ‘raw_input’ becomes ‘input’ in Python 3.

NLTK corpus downloader


Download the specified NLTK corpus file unless it has already been downloaded.

Returns True if the corpus needed to be downloaded.

Stopword removal

chatterbot.utils.remove_stopwords(tokens, language)[source]

Takes a language (i.e. ‘english’), and a set of word tokens. Returns the tokenized text with any stopwords removed. Stop words are words like “is, the, a, …”

Be sure to download the required NLTK corpus before calling this function: - from chatterbot.utils import nltk_download_corpus - nltk_download_corpus(‘corpora/stopwords’)

ChatBot response time


Returns the amount of time taken for a given chat bot to return a response.

Parameters:chatbot (ChatBot) – A chat bot instance.
Returns:The response time in seconds.
Return type:float

Parsing datetime information

chatterbot.parsing.datetime_parsing(text, base_date=datetime.datetime(2019, 1, 25, 12, 58, 9, 79147))[source]

Extract datetime objects from a string of text.