Sentiment Analysis, also known as opinion mining, is a natural language processing (NLP) task that involves determining the sentiment expressed in a piece of text. The goal is to identify whether the text conveys a positive, negative, or neutral sentiment. Sentiment analysis has various applications, including social media monitoring, customer feedback analysis, and market research.

Here are some common approaches to sentiment analysis:

  1. Rule-Based Approaches:
    • Lexicon-based methods: Use predefined lists of words with associated sentiment scores. The overall sentiment of the text is calculated based on the presence and polarity of these words.
    • Pattern-matching rules: Employ predefined rules or patterns to identify sentiment-bearing phrases or expressions.
  2. Machine Learning Approaches:
    • Supervised learning: Train a model on a labeled dataset that includes examples of text with their corresponding sentiment labels (positive, negative, neutral). Common algorithms include Support Vector Machines (SVM), Naive Bayes, and neural networks.
    • Unsupervised learning: Discover patterns and sentiments without labeled training data. Techniques like clustering and topic modeling can be applied.
  3. Hybrid Approaches:
    • Combine rule-based and machine learning approaches to leverage the strengths of both methods.
  4. Deep Learning Approaches:
    • Utilize deep neural networks, such as Recurrent Neural Networks (RNNs) or Long Short-Term Memory (LSTM) networks, for capturing complex relationships and context in textual data.
  5. Aspect-Based Sentiment Analysis:
    • Analyze sentiment at a more granular level by identifying sentiments towards specific aspects or entities mentioned in the text.

When performing sentiment analysis, it’s important to consider the context, sarcasm, and ambiguity in language, as these factors can affect the accuracy of the analysis. Additionally, fine-tuning models on domain-specific data can enhance performance for particular applications.

Numerous tools and libraries are available for sentiment analysis, including NLTK, TextBlob, VADER, and various machine learning frameworks like scikit-learn and TensorFlow. Depending on your specific needs and the characteristics of your data, you can choose an approach or combination of approaches that best suits your application.

Here we will be using Rasa NLU for Sentiment Analysis. This can also be used for Classification under pre-defined labels.

Getting Started

First, setup a new environment in Python/ VSCode. Open a PowerShell terminal within VSCode and use the command  ->

PowerShell
python -m venv . venv

to create a virtual environment. Activate this virtual environment via the Terminal to your workspace using ->

PowerShell
.venv\Scripts\Activate.ps1

Now, install the required libraries using pip->

PowerShell
#Use Python 3.10.2
pip install rasa

Then change directory in terminal to path and invoke rasa init. This will perform the initial setup for Rasa. ->

PowerShell
cd .venv\Lib\site-packages\rasa
python -m rasa init

C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\core\tracker_store.py:1044: MovedIn20Warning: Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings.  Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  Base: DeclarativeMeta = declarative_base()
C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\shared\utils\validation.py:134: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\pkg_resources\__init__.py:2846: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages     
  declare_namespace(pkg)
C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\pkg_resources\__init__.py:2846: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('ruamel')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages     
  declare_namespace(pkg)
Welcome to Rasa! 🤖

To get started quickly, an initial project will be created.
If you need some help, check out the documentation at https://rasa.com/docs/rasa.
Now let's start! 👇🏽

? Please enter a path where the project will be created [default: current directory] C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\Rasa
2024-03-11 21:06:21 INFO     root  - creating actions
2024-03-11 21:06:21 INFO     root  - copying C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\cli\initial_project\actions\actions.py -> .\actions
2024-03-11 21:06:21 INFO     root  - copying C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\cli\initial_project\actions\__init__.py -> .\actions
2024-03-11 21:06:21 INFO     root  - creating actions\__pycache__
2024-03-11 21:06:21 INFO     root  - copying C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\cli\initial_project\actions\__pycache__\actions.cpython-310.pyc -> .\actions\__pycache__    
2024-03-11 21:06:21 INFO     root  - copying C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\cli\initial_project\actions\__pycache__\__init__.cpython-310.pyc -> .\actions\__pycache__   
2024-03-11 21:06:21 INFO     root  - copying C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\cli\initial_project\config.yml -> .
2024-03-11 21:06:21 INFO     root  - copying C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\cli\initial_project\credentials.yml -> .
2024-03-11 21:06:22 INFO     root  - creating data
2024-03-11 21:06:22 INFO     root  - copying C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\cli\initial_project\data\nlu.yml -> .\data
2024-03-11 21:06:22 INFO     root  - copying C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\cli\initial_project\data\rules.yml -> .\data
2024-03-11 21:06:22 INFO     root  - copying C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\cli\initial_project\data\stories.yml -> .\data
2024-03-11 21:06:22 INFO     root  - copying C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\cli\initial_project\domain.yml -> .
2024-03-11 21:06:22 INFO     root  - copying C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\cli\initial_project\endpoints.yml -> .
2024-03-11 21:06:22 INFO     root  - creating tests
2024-03-11 21:06:22 INFO     root  - copying C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\cli\initial_project\tests\test_stories.yml -> .\tests
Created project directory at 'C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\Rasa'.
Finished creating project structure.
? ? Do you want to train an initial model? 💪🏽 Yes
Training an initial model...
The configuration for pipeline and policies was chosen automatically. It was written into the config file at 'config.yml'.
2024-03-11 21:06:56 INFO     rasa.engine.training.hooks  - Starting to train component 'RegexFeaturizer'.
2024-03-11 21:06:56 INFO     rasa.engine.training.hooks  - Finished training component 'RegexFeaturizer'.
2024-03-11 21:06:57 INFO     rasa.engine.training.hooks  - Starting to train component 'LexicalSyntacticFeaturizer'.
2024-03-11 21:06:57 INFO     rasa.engine.training.hooks  - Finished training component 'LexicalSyntacticFeaturizer'.
2024-03-11 21:06:57 INFO     rasa.engine.training.hooks  - Starting to train component 'CountVectorsFeaturizer'.
2024-03-11 21:06:57 INFO     rasa.nlu.featurizers.sparse_featurizer.count_vectors_featurizer  - 80 vocabulary items were created for text attribute.
2024-03-11 21:06:57 INFO     rasa.engine.training.hooks  - Finished training component 'CountVectorsFeaturizer'.
2024-03-11 21:06:57 INFO     rasa.engine.training.hooks  - Starting to train component 'CountVectorsFeaturizer'.
2024-03-11 21:06:57 INFO     rasa.nlu.featurizers.sparse_featurizer.count_vectors_featurizer  - 697 vocabulary items were created for text attribute.
2024-03-11 21:06:57 INFO     rasa.engine.training.hooks  - Finished training component 'CountVectorsFeaturizer'.
2024-03-11 21:06:57 INFO     rasa.engine.training.hooks  - Starting to train component 'DIETClassifier'.
Epochs: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:20<00:00,  4.93it/s, t_loss=1.09, i_acc=1]
2024-03-11 21:07:18 INFO     rasa.engine.training.hooks  - Finished training component 'DIETClassifier'.
2024-03-11 21:07:18 INFO     rasa.engine.training.hooks  - Starting to train component 'EntitySynonymMapper'.
2024-03-11 21:07:18 INFO     rasa.engine.training.hooks  - Finished training component 'EntitySynonymMapper'.
2024-03-11 21:07:18 INFO     rasa.engine.training.hooks  - Starting to train component 'ResponseSelector'.
2024-03-11 21:07:18 INFO     rasa.nlu.selectors.response_selector  - Retrieval intent parameter was left to its default value. This response selector will be trained on training examples combining all retrieval intents.
2024-03-11 21:07:18 INFO     rasa.engine.training.hooks  - Finished training component 'ResponseSelector'.
Processed story blocks: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 1505.85it/s, # trackers=1] 
Processed story blocks: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 1000.39it/s, # trackers=3] 
Processed story blocks: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 285.43it/s, # trackers=12] 
Processed story blocks: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 83.33it/s, # trackers=39] 
Processed rules: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 2100.30it/s, # trackers=1] 
2024-03-11 21:07:18 INFO     rasa.engine.training.hooks  - Starting to train component 'MemoizationPolicy'.
Processed trackers: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 894.82it/s, # action=12] 
Processed actions: 12it [00:00, 5997.57it/s, # examples=12]
2024-03-11 21:07:18 INFO     rasa.engine.training.hooks  - Finished training component 'MemoizationPolicy'.
2024-03-11 21:07:18 INFO     rasa.engine.training.hooks  - Starting to train component 'RulePolicy'.
Processed trackers: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 1978.91it/s, # action=5] 
Processed actions: 5it [00:00, 4999.17it/s, # examples=4]
Processed trackers: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 1001.03it/s, # action=12] 
Processed trackers: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 1999.19it/s] 
Processed trackers: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 1678.80it/s] 
2024-03-11 21:07:18 INFO     rasa.engine.training.hooks  - Finished training component 'RulePolicy'.
2024-03-11 21:07:18 INFO     rasa.engine.training.hooks  - Starting to train component 'TEDPolicy'.
Processed trackers: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 120/120 [00:00<00:00, 2408.05it/s, # action=30] 
Epochs: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:14<00:00,  6.84it/s, t_loss=2.24, loss=2.08, acc=1] 
2024-03-11 21:07:34 INFO     rasa.engine.training.hooks  - Finished training component 'TEDPolicy'.
2024-03-11 21:07:34 INFO     rasa.engine.training.hooks  - Starting to train component 'UnexpecTEDIntentPolicy'.
2024-03-11 21:07:34 WARNING  rasa.shared.utils.common  - The UnexpecTED Intent Policy is currently experimental and might change or be removed in the future 🔬 Please share your feedback on it in the forum (https://forum.rasa.com) to help us make this feature ready for production.
Processed trackers: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 120/120 [00:00<00:00, 3745.67it/s, # intent=12] 
Epochs: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:12<00:00,  7.97it/s, t_loss=0.121, loss=0.00592, acc=1] 
2024-03-11 21:07:49 INFO     rasa.engine.training.hooks  - Finished training component 'UnexpecTEDIntentPolicy'.
Your Rasa model is trained and saved at 'models\20240311-210656-hushed-tambourine.tar.gz'.
? Do you want to speak to the trained assistant on the command line? 🤖 Yes
C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\sanic_cors\extension.py:39: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  SANIC_VERSION = LooseVersion(sanic_version)
2024-03-11 21:09:29 INFO     root  - Connecting to channel 'cmdline' which was specified by the '--connector' argument. Any other channels will be ignored. To connect to all given channels, omit the '--connector' argument.
2024-03-11 21:09:29 INFO     root  - Starting Rasa server on http://0.0.0.0:5005
2024-03-11 21:09:29 INFO     rasa.core.processor  - Loading model models\20240311-210656-hushed-tambourine.tar.gz...
2024-03-11 21:09:48 WARNING  rasa.shared.utils.common  - The UnexpecTED Intent Policy is currently experimental and might change or be removed in the future 🔬 Please share your feedback on it in the forum (https://forum.rasa.com) to help us make this feature ready for production.
2024-03-11 21:09:59 INFO     root  - Rasa server is up and running.
Bot loaded. Type a message and press enter (use '/stop' to exit):
Your input ->  Hello
Hey! How are you?

Now, got to .venv\Rasa\data and edit the nlu.yml file as follows and save it->

YAML
version: "3.1"

nlu:
- intent: negative
  examples: |
    - I'm furious with the constant glitches in your software; it's unacceptable!
    - Your website is a nightmare to navigate, and I'm seething with frustration.
    - I can't believe the incompetence of your support team – it's infuriating!
    - This is the worst customer experience ever; I'm beyond angry!
    - Your product is a disaster, and I'm fed up with the constant issues.
    - I'm outraged by the lack of transparency in your business practices.
    - The delays in your service are driving me crazy; this is inexcusable!
    - I'm seriously upset about the poor quality of your products.
    - Dealing with your company has become a source of constant irritation.
    - Your lack of communication is absolutely infuriating.
    - I'm angry about the complete disregard for customer satisfaction.
    - I'm absolutely livid about the way my concerns have been ignored.
    - This is beyond frustrating; your service has been a letdown.
    - Your customer service is a joke, and I'm not amused.
    - I'm disgusted by the way your company handles complaints.
    - The incompetence of your team is driving me up the wall.
    - I'm extremely agitated by the constant product malfunctions.
    - Your lack of accountability for mistakes is infuriating.
    - This level of negligence is absolutely infuriating.
    - I'm losing my patience with your company's lack of responsiveness.
    - I'm deeply disappointed in the way you handle customer issues.
    - The sheer incompetence is making me rethink my loyalty to your brand.
    - I'm beyond upset about the poor service I've received.
    - Your disregard for customer feedback is maddening.
    - I'm absolutely disgusted with the way you treat your customers.
    - Your indifference to customer concerns is absolutely infuriating.
    - I'm seething with anger over the constant billing errors.
    - I'm absolutely fed up with the lack of resolution to my problems.
    - Your company's policies are driving me insane; it's intolerable.
    - I'm outraged at the lack of respect for customers' time and money.
    - I can't express how angry I am with the constant letdowns from your company.
    - Your product defects are making me regret ever choosing your brand.
    - I'm beyond frustrated with the never-ending technical issues.
    - Your service has been a complete disaster, and I'm not happy about it.
    - The level of incompetence displayed is absolutely infuriating.
    - I'm absolutely appalled at the lack of professionalism from your team.
    - Your disregard for customer satisfaction is driving me up the wall.
    - I'm infuriated by the lack of urgency in resolving my concerns.
    - I'm deeply dissatisfied with the overall experience; it's a disgrace.
    - The constant inconveniences have pushed me to the brink of anger.
    - Your company's negligence is making me reconsider my choices.
    - I'm extremely displeased with the subpar quality of your service.
    - I'm furious at the blatant disregard for customer feedback.
    - This constant runaround is making me lose faith in your company.
    - I'm beyond irritated with the lack of accountability for mistakes.
    - Your unresponsiveness is driving me crazy; it's absolutely infuriating.
    - I'm absolutely livid about the lack of empathy in your customer service.
    - The lack of resolution to my issues is making me extremely angry.
    - I'm seething with frustration over the consistent failures of your service.
    - I'm thoroughly disgusted with the overall lack of professionalism.

- intent: positive
  examples: |
    - I'm thrilled with the outstanding customer service I received!
    - Your product exceeded my expectations, and I couldn't be happier.
    - I'm overjoyed by the seamless experience your website provided.
    - Kudos to your team for delivering such a fantastic service!
    - I'm delighted with the prompt and efficient resolution to my issue.
    - Your company consistently goes above and beyond; I'm elated!
    - I'm so happy with the quality and performance of your product.
    - Thanks a million for the amazing support; I'm truly grateful.
    - Your team's professionalism and kindness have made my day.
    - I'm beaming with joy over the positive impact your service had on me.
    - I can't express how satisfied I am with your excellent product.
    - I'm ecstatic about the positive changes your updates have brought.
    - The level of care and attention to detail is making me very happy.
    - Your team's dedication to customer satisfaction is truly commendable.
    - I'm absolutely delighted with the superb performance of your app.
    - I'm filled with gratitude for the outstanding service you provided.
    - I'm on cloud nine with the wonderful experience I had with your company.
    - Your commitment to excellence has turned me into a loyal customer.
    - I'm so pleased with the user-friendly design of your website.
    - Your product has brought so much joy and convenience into my life.
    - I'm over the moon about the positive impact your service has had on me.
    - I'm thrilled to be a part of such an innovative and customer-centric community.
    - I can't stop smiling because of the incredible service I received.
    - I'm genuinely happy with the personalized attention from your team.
    - Your company's commitment to customer satisfaction is truly uplifting.
    - I'm so grateful for the positive and enriching experience with your product.
    - I'm absolutely overjoyed with the exceptional quality of your service.
    - Hats off to your team for delivering such a fantastic product!
    - I'm positively impressed by the efficiency and effectiveness of your support.
    - I'm on cloud nine with the delightful surprises your service offers.
    - I'm thrilled to have discovered such a reliable and trustworthy company.
    - I'm elated by the delightful simplicity and functionality of your app.
    - Your product has brought so much joy and ease into my daily routine.
    - I'm overjoyed by the positive impact your company has on the community.
    - I'm so happy I chose your service; it has exceeded my expectations.
    - I'm filled with happiness over the exceptional quality of your product.
    - Your team's dedication to customer happiness is truly praiseworthy.
    - I'm grateful for the positive changes your service has brought into my life.
    - I'm ecstatic about the personalized and attentive service I received.
    - I'm delighted to be a part of such a forward-thinking and customer-centric community.
    - I can't thank your team enough for the consistently positive experiences.
    - I'm over the moon with the excellent value your product provides.
    - I'm genuinely pleased with the positive impact your company has on its customers.
    - Your team's responsiveness and efficiency have made me a happy customer.
    - I'm so grateful for the positive and uplifting interactions with your team.
    - I'm thrilled with the positive changes your updates have brought to the platform.
    - I'm beaming with joy over the seamless and enjoyable experience with your product.
    - Your commitment to customer satisfaction is making me a loyal and happy customer.
    - I'm genuinely happy with the positive influence your service has on my daily life.
    - I'm delighted by the extraordinary level of customer care your team provides.

Now run->

PowerShell
 cd .venv\Rasa
 python -m rasa train nlu

Output

PowerShell
C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\core\tracker_store.py:1044: MovedIn20Warning: Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings.  Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  Base: DeclarativeMeta = declarative_base()
C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\shared\utils\validation.py:134: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\pkg_resources\__init__.py:2846: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages     
  declare_namespace(pkg)
C:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\pkg_resources\__init__.py:2846: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('ruamel')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages     
  declare_namespace(pkg)
The configuration for pipeline was chosen automatically. It was written into the config file at 'config.yml'.
2024-03-11 21:26:26 INFO     rasa.engine.training.hooks  - Starting to train component 'RegexFeaturizer'.
2024-03-11 21:26:26 INFO     rasa.engine.training.hooks  - Finished training component 'RegexFeaturizer'.
2024-03-11 21:26:26 INFO     rasa.engine.training.hooks  - Starting to train component 'LexicalSyntacticFeaturizer'.
2024-03-11 21:26:26 INFO     rasa.engine.training.hooks  - Finished training component 'LexicalSyntacticFeaturizer'.
2024-03-11 21:26:26 INFO     rasa.engine.training.hooks  - Starting to train component 'CountVectorsFeaturizer'.
2024-03-11 21:26:26 INFO     rasa.nlu.featurizers.sparse_featurizer.count_vectors_featurizer  - 285 vocabulary items were created for text attribute.
2024-03-11 21:26:26 INFO     rasa.engine.training.hooks  - Finished training component 'CountVectorsFeaturizer'.
2024-03-11 21:26:26 INFO     rasa.engine.training.hooks  - Starting to train component 'CountVectorsFeaturizer'.
2024-03-11 21:26:26 INFO     rasa.nlu.featurizers.sparse_featurizer.count_vectors_featurizer  - 2565 vocabulary items were created for text attribute.
2024-03-11 21:26:26 INFO     rasa.engine.training.hooks  - Finished training component 'CountVectorsFeaturizer'.
2024-03-11 21:26:26 INFO     rasa.engine.training.hooks  - Starting to train component 'DIETClassifier'.
Epochs: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:40<00:00,  2.45it/s, t_loss=0.668, i_acc=1]
2024-03-11 21:27:08 INFO     rasa.engine.training.hooks  - Finished training component 'DIETClassifier'.
2024-03-11 21:27:08 INFO     rasa.engine.training.hooks  - Starting to train component 'EntitySynonymMapper'.
2024-03-11 21:27:08 INFO     rasa.engine.training.hooks  - Finished training component 'EntitySynonymMapper'.
2024-03-11 21:27:08 INFO     rasa.engine.training.hooks  - Starting to train component 'ResponseSelector'.
2024-03-11 21:27:08 INFO     rasa.nlu.selectors.response_selector  - Retrieval intent parameter was left to its default value. This response selector will be trained on training examples combining all retrieval intents.
2024-03-11 21:27:08 INFO     rasa.engine.training.hooks  - Finished training component 'ResponseSelector'.
Your Rasa model is trained and saved at 'models\nlu-20240311-212625-bright-mousse.tar.gz'.

Your Rasa model is trained and saved at ‘models\nlu-20240311-212625-bright-mousse.tar.gz’.
Now execute the following to load you model->

PowerShell
rasa run --enable-api -m models/nlu-20240311-212625-bright-mousse.tar.gz

Output

PowerShell
c:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\core\tracker_store.py:1044: MovedIn20Warning: Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings.  Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  Base: DeclarativeMeta = declarative_base()
c:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\rasa\shared\utils\validation.py:134: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
c:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\pkg_resources\__init__.py:2846: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages     
  declare_namespace(pkg)
c:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\pkg_resources\__init__.py:2846: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('ruamel')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages     
  declare_namespace(pkg)
c:\Code\Python\Environment\SentimentAnalysisRasa\.venv\lib\site-packages\sanic_cors\extension.py:39: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  SANIC_VERSION = LooseVersion(sanic_version)
2024-03-11 21:29:52 INFO     root  - Starting Rasa server on http://0.0.0.0:5005
2024-03-11 21:29:53 INFO     rasa.core.processor  - Loading model models/nlu-20240311-212625-bright-mousse.tar.gz...
2024-03-11 21:30:05 INFO     root  - Rasa server is up and running.

Rasa model is now loaded and ready to use as an API via http://0.0.0.0:5005/model/parse.

You could test the API in Postman->

Or use the following code->

Python
import requests
import json

url = "http://127.0.0.1:5005/model/parse"

payload = json.dumps({
  "text": "Hello. The issue is still not resolved."
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)
result=json.loads(response.text.encode('utf8'))
sentiment = result["intent"]["name"]
confidence = round(float(result["intent"]["confidence"] or '0.0')*100,2)
print("Sentiment: ",sentiment)
print("Confidence: ",confidence,"%")

Output

PowerShell
Sentiment:  negative
Confidence:  100.0 %

GitHub: https://github.com/mohammaddaoudfarooqi/SentimentAnalysisRasaNLU