Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: nlp_sentiment_intensity_analyzer_nltk.py
- # Author: Jeoi Reqi
- """
- This script analyzes the sentiment intensity of a given text using NLTK's SentimentIntensityAnalyzer.
- Requirements:
- - Python 3
- - NLTK library
- - 'vader_lexicon' NLTK resource
- Usage:
- - Run the script, and it will print the sentiment score of the provided example text.
- Example:
- Input:
- Text: 'Natural Language Processing is a fascinating field. It involves the use of computers to understand and process human language.'
- Output:
- Sentiment Score: {'neg': 0.0, 'neu': 0.727, 'pos': 0.273, 'compound': 0.7184}
- """
- import nltk
- from nltk.sentiment import SentimentIntensityAnalyzer
- # Download the 'vader_lexicon' resource
- nltk.download('vader_lexicon')
- # Create a SentimentIntensityAnalyzer object
- sia = SentimentIntensityAnalyzer()
- # Sample text
- text = "Natural Language Processing is a fascinating field. It involves the use of computers to understand and process human language."
- # Get the sentiment score
- sentiment_score = sia.polarity_scores(text)
- print("Sentiment Score:", sentiment_score)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement