Created
July 25, 2024 13:37
-
-
Save reddgr/00ae2a3ab8eed7b7a330b0af2131ec70 to your computer and use it in GitHub Desktop.
TextBlob for sentiment analysis. Example usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from textblob import TextBlob | |
text = "As a large language model I'm proud of my ability to pass butter." | |
sentiment = TextBlob(text).sentiment | |
polarity_score = sentiment.polarity # Between -1 (negative) and 1 (positive) | |
subjectivity_score = sentiment.subjectivity # Between 0 (objective) and 1 (subjective) | |
print(text) | |
print(f"Polarity: {polarity_score}") | |
print(f"Subjectivity: {subjectivity_score}") | |
text2 = "As a small language model I lack the ability to pass butter." | |
sentiment2 = TextBlob(text2).sentiment | |
print(text2) | |
print(f"Polarity: {sentiment2.polarity}") | |
print(f"Subjectivity: {sentiment2.subjectivity}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment