import streamlit as st # Custom CSS for better styling st.markdown(""" """, unsafe_allow_html=True) # Introduction st.markdown('
Financial Sentiment Analysis with Spark NLP
', unsafe_allow_html=True) st.markdown("""

Welcome to the Spark NLP Financial Sentiment Analysis Demo App! Financial sentiment analysis is the process of identifying and categorizing the emotional tone of financial news articles, reports, tweets, and other textual data related to finance. Using Spark NLP, this app demonstrates how to accurately analyze the sentiment of financial texts.

This app leverages Spark NLP's advanced models to detect sentiments in financial texts, helping users gain insights into market sentiment and make informed decisions.

""", unsafe_allow_html=True) st.image('images/financial-sentiment.png', use_column_width='auto') # About Financial Sentiment Analysis st.markdown('
About Financial Sentiment Analysis
', unsafe_allow_html=True) st.markdown("""

Financial sentiment analysis involves analyzing texts to determine whether the expressed sentiment is positive, negative, or neutral with respect to financial markets. It is widely used by investors, traders, and analysts to gauge market sentiment and predict market movements.

Applications of financial sentiment analysis include analyzing news articles, earnings reports, social media posts, and more to identify trends and make data-driven investment decisions.

""", unsafe_allow_html=True) # Using Sentiment Analysis in Spark NLP st.markdown('
Using Sentiment Analysis in Spark NLP
', unsafe_allow_html=True) st.markdown("""

The following pipeline demonstrates how to use Spark NLP for financial sentiment analysis:

""", unsafe_allow_html=True) # Setup Instructions st.markdown('
Setup
', unsafe_allow_html=True) 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') # Example Pipeline for Financial Sentiment Analysis st.markdown('
Example Usage: Financial Sentiment Analysis with Spark NLP
', unsafe_allow_html=True) st.code(''' from sparknlp.base import DocumentAssembler from sparknlp.annotator import BertSentenceEmbeddings, ClassifierDLModel from pyspark.ml import Pipeline # Step 1: Document Assembler document = DocumentAssembler()\\ .setInputCol("text")\\ .setOutputCol("document") # Step 2: Sentence Embeddings embeddings = BertSentenceEmbeddings\\ .pretrained('sent_bert_wiki_books_sst2', 'en') \\ .setInputCols(["document"])\\ .setOutputCol("sentence_embeddings") # Step 3: Sentiment Classifier sentimentClassifier = ClassifierDLModel.pretrained("classifierdl_bertwiki_finance_sentiment", "en") \\ .setInputCols(["sentence_embeddings"]) \\ .setOutputCol("class_") # Define the pipeline financial_sentiment_pipeline = Pipeline( stages=[document, embeddings, sentimentClassifier]) # Sample Data data = spark.createDataFrame( [["The company reported a significant increase in revenue for the last quarter."]], ["text"] ) # Fit-transform to get predictions result = financial_sentiment_pipeline.fit(data).transform(data) result.select("text","class_.result").show(truncate=False) ''', language='python') st.text(""" +----------------------------------------------------------------------------+----------+ |text |result | +----------------------------------------------------------------------------+----------+ |The company reported a significant increase in revenue for the last quarter.|[positive]| +----------------------------------------------------------------------------+----------+ """) st.markdown("""

The code snippet demonstrates how to set up a pipeline in Spark NLP to perform financial sentiment analysis on text data using pre-trained models. The resulting DataFrame contains the sentiment predictions.

""", unsafe_allow_html=True) # Conclusion st.markdown("""

Conclusion

In this app, we demonstrated how to use Spark NLP's pre-trained models to perform financial sentiment analysis on text data. By integrating these models into your NLP pipelines, you can gain valuable insights into market sentiment and make informed financial decisions.

""", unsafe_allow_html=True) # References and Additional Information st.markdown('
For additional information, please check the following references.
', unsafe_allow_html=True) st.markdown("""
""", unsafe_allow_html=True) st.markdown('
Community & Support
', unsafe_allow_html=True) st.markdown("""
""", unsafe_allow_html=True)