import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns from transformers import pipeline def sentiment_analysis1(text): # Load the sentiment analysis pipeline with the BERT model classifier = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment") # Perform sentiment analysis result = classifier(text) return result # Example usage: financial_news = "The stock market experienced a significant downturn today amid concerns over inflation." result = sentiment_analysis1(financial_news) print("Sentiment Analysis Result:", result) data = { 'headline': [ "Apple's revenue exceeds expectations with a strong quarterly report", "Major banks face scrutiny as financial regulations tighten", "Tesla's new factory investment raises concerns over debt levels" ] } df = pd.DataFrame(data) df df['sentiment'] = sentiment_analysis1(df['headline'].tolist()) print(df) from transformers import pipeline # Initialize the sentiment analysis model model_name = "yiyanghkust/finbert-tone" finbert = pipeline("sentiment-analysis", model=model_name) # Function to analyze sentiment def analyze_sentiment(text): results = finbert(text) return results # Example usage: financial_news = "The company's revenue has exceeded expectations, but concerns about regulatory challenges remain." sentiment_result = analyze_sentiment(financial_news) # Print the results print("Sentiment Analysis Result:", sentiment_result) df['sentiment'] = analyze_sentiment(df['headline'].tolist()) print(df) pos="In two years at Texas State Dr. Yi was perhaps the most exceptional teacher \ I have had. His passion for what he teaches as well as his students well-being is \ evident. He went far beyond what is necessary to provide us with material via his canvas pages. \ I would highly highly recommend other students in Finance take his course(s) they would be better for it. \ Thank you" neg ="Was hard to understand what the professor was saying. \ Materials on the test sometimes would reflect only a small fraction of the homework and review,\ the rest seemed to be vague in where he got the information from. \ It was also hard to stay engaged during class, I fell asleep every time I attended class. \ The lectures were practically useless to me" #!pip install textblob from textblob import TextBlob print(TextBlob(pos).sentiment) print(TextBlob(neg).sentiment) !pip install vaderSentiment from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer vs_pos = SentimentIntensityAnalyzer().polarity_scores(pos) vs_neg = SentimentIntensityAnalyzer().polarity_scores(neg) print("{:-<65} {}".format(pos, str(vs_pos))) print('--------------') print("{:-<65} {}".format(neg, str(vs_neg))) print(vs_pos) print(vs_neg) !pip install flair from flair.models import TextClassifier from flair.data import Sentence classifier = TextClassifier.load('en-sentiment') sentence = Sentence(pos) classifier.predict(sentence) # print sentence with predicted labels print('Sentence above is: ', sentence.labels) sentence = Sentence(neg) classifier.predict(sentence) # print sentence with predicted labels print('Sentence above is: ', sentence.labels) from transformers import pipeline def sentiment_analysis1(text): # Load the sentiment analysis pipeline with the BERT model classifier = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment") # Perform sentiment analysis result = classifier(text) return result # Example usage: result = sentiment_analysis1(pos) print("Sentiment Analysis Result:", result) result = sentiment_analysis1(neg) print("Sentiment Analysis Result:", result) from transformers import pipeline # Initialize the sentiment analysis model model_name = "yiyanghkust/finbert-tone" finbert = pipeline("sentiment-analysis", model=model_name) # Function to analyze sentiment def analyze_sentiment(text): results = finbert(text) return results # Example usage: sentiment_result = analyze_sentiment(pos) # Print the results print("Sentiment Analysis Result:", sentiment_result) # Example usage: sentiment_result = analyze_sentiment(neg) # Print the results print("Sentiment Analysis Result:", sentiment_result)