Coders Packet

Personal assistant chatbot using NLTK and Keras libraries for NLP and machine learning.

By Prathiksha K

Personal assistant chatbot used in our day-to-day life to remind our appointments, pending works and so on. With these reminders, we can complete our tasks before deadlines.

Our personal assistant chatbot offers a number of features and functionalities that are intended to improve and simplify your daily life.

1. Reminders for appointments and schedule items: The chatbot can alert you to future appointments, meetings, or significant events. The chatbot will send you timely reminders via your favourite communication channel, such as email or text message, once you have provided it with the relevant information, such as the date, time, and description.

2. Recipe Suggestions: Looking for ideas for your upcoming meal? Contact the chatbot and ask! It can provide you a variety of recipe recommendations based on your dietary choices, the ingredients you have on hand, or certain cuisines. You can even request item replacements or step-by-step cooking instructions.

3.Payment Reminders: Keeping track of bill payments can be challenging. With the chatbot, you can easily set up reminders for recurring payments, such as utility bills, rent, or credit card dues. The chatbot will send you reminders prior to the due dates, ensuring you never miss a payment again.

4.Medication Reminders: Staying on top of your medication schedule is crucial for your well-being. By providing the chatbot with your medication details, including dosage and timing, it will send you reminders to take your medication at the specified times. You can also track your medication history and set up refill reminders for prescriptions.

5.Personalized Health and Fitness Tips: Based on your health goals and preferences, the chatbot can provide you with personalized health and fitness tips. It can suggest workout routines, and healthy recipes, and even track your daily steps or calorie intake if you integrate it with fitness-tracking apps or devices.

6.Note-Taking and Voice Memos: You can use the chatbot as a convenient tool for taking notes or recording voice memos. Whether it's jotting down important information, capturing ideas on the go, or creating a shopping list, the chatbot will store and organize your notes for future reference.

7.Integration with Existing Systems: The chatbot can integrate with your existing calendar, email, or task management tools, allowing you to synchronize and manage your appointments and tasks seamlessly.

Firstly, importing necessary libraries such as NLTK, WordNetLemmatizer, json, pickle, numpy, keras, and random. These libraries will be used for various purposes throughout the code. The code reads the contents of the "intents.json" file, which contains the training data for the chatbot. It then iterates over the intents and patterns, tokenizes the words in each pattern, and adds them to the respective lists. It also keeps track of unique words and classes (intents). The training data is shuffled and converted into arrays for further processing and model training.

This code defines and trains a sequential model for the chatbot. Here's an explanation of the steps involved:

1. Model Definition: A Sequential model is created using `Sequential()`.

2. Layers: Dense layers with the specified number of units and 'relu' activation are added to the model. Dropout layers with a dropout rate of 0.5 are inserted after each dense layer to prevent overfitting. The final dense layer has a number of units equal to the length of `train_y` (number of classes) and uses 'softmax' activation.

3. Compilation: The model is compiled with the categorical cross-entropy loss function, stochastic gradient descent (SGD) optimizer with Nesterov accelerated gradient, and 'accuracy' metric.

4. Model Training: The model is trained using the `fit()` function. The training data (`train_x` and `train_y`) is passed along with the number of epochs (200) and batch size (5).

5. Saving the Model: After training, the model is saved as 'chatbot_model.h5' using the `save()` function.

6. Loading Required Libraries: The code imports the necessary libraries, including NLTK, WordNetLemmatizer, pickle, numpy, and load_model from Keras.

7. Loading the Pre-trained Model: The model is loaded from the saved file using `load_model()`.

8. Loading Data: The 'intents.json' file is loaded, which contains the intents and responses for the chatbot. The 'words.pkl' and 'classes.pkl' files, which store the processed words and classes, respectively, are also loaded using Pickle.

9. Helper Functions: Two helper functions are defined:
- `clean_up_sentence(sentence)`: Tokenizes and lemmatizes the input sentence.
- `bow(sentence, words, show_details=True)`: Creates a bag of words representation for the input sentence.

10. `predict_class(sentence, model)`: Takes a sentence and the loaded model as input and predicts the class/intent of the sentence using the bag of words representation.

11. `getResponse(ints, intents_json)`: Takes the predicted intents and the intents JSON object as input and returns a random response from the corresponding intent.

12. `chatbot_response(text)`: Takes user input as text, predicts the intent using `predict_class()`, and returns a random response using `getResponse()`.

This code sets up the chatbot model, trains it, and defines helper functions to process user input and provide appropriate responses based on the train

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Prathiksha K (Prathi0625)

Download packets of source code on Coders Packet