Downloads · 30 days
0
kishanj97/nltk_tone_analyzer
nltk_tone_analyzer is a machine learning model from kishanj97. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
import nltk from nltk.sentiment import SentimentIntensityAnalyzer
Downloads · 30 days
0
Access
Public
Updated Feb 9, 2024
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md1.6 KB · 34%
From the Hugging Face model README
import nltk from nltk.sentiment import SentimentIntensityAnalyzer
nltk.download('vader_lexicon')
with open("lks.txt", 'r') as file: fl = file.read()
contactId = fl.split("|")[0] transcript=fl.split("|")[1] transcript=transcript.replace("'",'')
sia = SentimentIntensityAnalyzer() print(transcript)
sentiment_score = sia.polarity_scores(transcript)
tones = { 'analytical': 0, 'anger': 0, 'confident': 0, 'fear': 0, 'joy': 0, 'sadness': 0, 'tentative': 0 }
if sentiment_score['compound'] >= 0.05: # Threshold for positive sentiment tones['joy'] += 1 elif sentiment_score['compound'] <= -0.05: # Threshold for negative sentiment tones['anger'] += 1 elif sentiment_score['neg'] >= 0.5: # Threshold for high negativity tones['sadness'] += 1 elif sentiment_score['pos'] <= 0.2: # Threshold for low positivity tones['fear'] += 1 elif sentiment_score['neu'] >= 0.5: # Threshold for high neutrality tones['tentative'] += 1 else: # Otherwise, consider it analytical or confident tones['analytical'] += 1 tones['confident'] += 1
print("Tone Counts:", tones)
#Tone Counts: {'analytical': 0, 'anger': 0, 'confident': 0, 'fear': 0, 'joy': 1, 'sadness': 0, 'tentative': 0}