import streamlit as st # Custom CSS for better styling st.markdown(""" """, unsafe_allow_html=True) # Introduction st.markdown('
Welcome to the Spark NLP Sentiment Analysis Demo App! Sentiment analysis is an automated process capable of understanding the feelings or opinions that underlie a text. This process is considered a text classification and is one of the most interesting subfields of NLP. Using Spark NLP, it is possible to analyze the sentiment in a text with high accuracy.
This app demonstrates how to use Spark NLP's SentimentDetector to perform sentiment analysis using a rule-based approach.
Sentiment analysis studies the subjective information in an expression, such as opinions, appraisals, emotions, or attitudes towards a topic, person, or entity. Expressions can be classified as positive, negative, or neutral — in some cases, even more detailed.
Some popular sentiment analysis applications include social media monitoring, customer support management, and analyzing customer feedback.
The SentimentDetector annotator in Spark NLP uses a rule-based approach to analyze the sentiment in text data. This method involves using a set of predefined rules or patterns to classify text as positive, negative, or neutral.
Spark NLP also provides Machine Learning (ML) and Deep Learning (DL) solutions for sentiment analysis. If you are interested in those approaches, please check the ViveknSentiment and SentimentDL annotators of Spark NLP.
Here’s how you can implement sentiment analysis using the SentimentDetector annotator in Spark NLP:
', unsafe_allow_html=True) # Setup Instructions st.markdown('To install Spark NLP in Python, use your favorite package manager (conda, pip, etc.). For example:
', unsafe_allow_html=True) st.code(""" pip install spark-nlp pip install pyspark """, language="bash") st.markdown("Then, import Spark NLP and start a Spark session:
", unsafe_allow_html=True) st.code(""" import sparknlp # Start Spark Session spark = sparknlp.start() """, language='python') # load data st.markdown('The code snippet demonstrates how to set up a pipeline in Spark NLP to perform sentiment analysis on text data using the SentimentDetector annotator. The resulting DataFrame contains the sentiment predictions.
""", unsafe_allow_html=True) # One-liner Alternative st.markdown('In October 2022, John Snow Labs released the open-source johnsnowlabs
library that contains all the company products, open-source and licensed, under one common library. This simplified the workflow, especially for users working with more than one of the libraries (e.g., Spark NLP + Healthcare NLP). This new library is a wrapper on all of John Snow Lab’s libraries and can be installed with pip:
pip install johnsnowlabs
To run sentiment analysis with one line of code, we can simply:
', unsafe_allow_html=True) st.code(""" # Import the NLP module which contains Spark NLP and NLU libraries from johnsnowlabs import nlp sample_text = "The restaurant staff is really nice" # Returns a pandas DataFrame, we select the desired columns nlp.load('en.sentiment').predict(sample_text, output_level='sentence') """, language='python') st.image('images/johnsnowlabs-sentiment-output.png', use_column_width='auto') st.markdown("""This approach demonstrates how to use the johnsnowlabs
library to perform sentiment analysis with a single line of code. The resulting DataFrame contains the sentiment predictions.
In this app, we demonstrated how to use Spark NLP's SentimentDetector annotator to perform sentiment analysis on text data. These powerful tools enable users to efficiently process large datasets and identify sentiment, providing deeper insights for various applications. By integrating these annotators into your NLP pipelines, you can enhance text understanding, information extraction, and customer sentiment analysis.