Imports and Configurations The code imports various libraries like TensorFlow, PyTorch, Transformers, Tkinter, and CLIP to handle tasks related to neural networks, text classification, and image processing. Logging and Warnings: Configures a logger to display debug and info messages while suppressing warnings (especially for TensorFlow and Transformers warnings). Global Variables emotion_to_vector: Maps emotions (e.g., joy, sadness, anger) to predefined vectors that the chatbot uses as input for decision-making. conversation_memory: Stores previous conversations with the chatbot for context.
- Emotion Detection Model Initialization initialize_emotion_detector(): Loads a text-classification model from HuggingFace that detects emotions in user input.
- CLIP Image Model Initialization initialize_clip_model(): Initializes the CLIP model, which processes images by generating embeddings that can be used for conversation context.
- Hebbian Learning and Global Workspace Layer hebbian_update(): Implements Hebbian learning, which adjusts neural network weights based on activations. GlobalWorkspaceLayer: A neural network layer that processes input and output activations using fully connected layers.
- Deep Q-Network (DQN) Model with Meta-Learning MetaLearningDQNModel: A reinforcement learning agent that learns which action to take based on the state (emotion, knowledge context, image embedding). It uses a neural network (built with TensorFlow) to predict Q-values and selects actions based on an epsilon-greedy strategy.
- GUI Application (ChatBotApp) ChatBotApp: Main Tkinter-based class that builds the chatbot's GUI. It contains: Text and image input fields for user interactions. A retrain button that allows the user to retrain the LSTM model with a new dataset. Functions like send_message() and upload_image() to handle text and image inputs from users. Functions like process_conversation() and process_image_with_clip() to process user inputs and images, analyze emotion, predict actions using DQN, and generate responses using LSTM.
- Chatbot's Core Functionality process_conversation(): The core function that processes user input by analyzing the context, detecting emotion, generating knowledge context vectors, and using DQN to decide an appropriate action. The chatbot response is generated based on a combination of emotional analysis and an LSTM-based language model. generate_response_with_lstm(): Generates a response to the user input using a trained LSTM model. detect_emotion(): Uses the HuggingFace model to detect the user's emotional state from the input. create_and_reason_over_knowledge_graph(): Placeholder function that simulates creating a knowledge graph and reasoning over it to provide additional context for decision-making.
- LSTM Model Training train_lstm_model(): Function that either loads or trains the LSTM model based on the dataset provided. The tokenizer is used to encode text inputs, and the model predicts the next word in a sequence to generate responses.
- Retraining the Model The chatbot allows retraining of the LSTM model using a new dataset provided by the user. This feature is accessible via the retrain button on the GUI, and the chatbot can update its language model based on new conversations.
- Memory and Context Handling The chatbot maintains a conversation memory for each user, allowing it to remember past conversations and respond more contextually. How It All Fits Together User Interaction: The user inputs text (or uploads an image), which triggers either a text or image processing function. Emotion Detection and DQN: The chatbot detects the user's emotions and combines this with contextual information (conversation history, knowledge graph, and image embeddings) to select an appropriate action. Response Generation: The selected action influences the chatbot’s response, which is generated using an LSTM language model. GUI: The chatbot displays its response in the GUI, allowing a seamless user experience. Running the Application To run the application, execute the Python script, and it will launch a GUI where you can interact with the chatbot.
Train this chatbot with Dataset_2.csv which consists of two column input and response #update coming soon