Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create sushil-AI-Based Chatbot for Customer Support Automation
Text Input Handling: The program accepts user input using input(). The user enters a sentence or paragraph that is analyzed for sentiment. Bag of Words (BoW) Representation: The text is tokenized into individual words. A Bag of Words model is created using CountVectorizer(), which counts the frequency of each unique word in the text. The resulting matrix (word counts) and feature names (unique words) are displayed. Word Sentiment Rating: Each word from the Bag of Words feature set is analyzed using the TextBlob library to calculate its sentiment polarity. Based on polarity: Positive: Polarity > 0 Negative: Polarity < 0 Neutral: Polarity = 0 Words with negative polarity are flagged, and their sentiment is printed. Sentence-Level Sentiment Analysis: The input text is split into individual sentences. Each sentence is analyzed for sentiment using TextBlob: Positive: Polarity > 0 Negative: Polarity < 0 Neutral: Polarity = 0 If a sentence has a negative sentiment, a predefined negative response is triggered. Overall Sentiment Analysis: The overall sentiment polarity is calculated by analyzing the entire input text as a single unit. If any sentence was flagged as negative earlier, the overall sentiment is overridden as Negative. Otherwise, it is determined by the calculated polarity: Positive: Polarity > 0 Neutral: Polarity = 0 Response Generation: Based on the overall sentiment: Positive Sentiment: Displays a predefined positive response. Negative Sentiment: Displays a predefined negative response. Neutral Sentiment: Indicates that the text is neutral. Execution Example: Input: "The product is amazing and I absolutely love it! But the delivery service was horrible." Output: Sentence 1: Positive (Polarity: 0.6125) Sentence 2: Negative (Polarity: -1.0) Overall: Negative (overridden due to the negative sentence) Response: "Sorry for the bad service. Our customer care will call you back."
- Loading branch information