Bắt đầu ngayBắt đầu miễn phí

Detecting the sentiment of Tale of Two Cities

In the video we saw that one type of algorithms for detecting the sentiment are based on a lexicon of predefined words and their corresponding polarity score. Your task in this exercise is to detect the sentiment, including polarity and subjectivity of a given string using such a rule-based approach and the textblob library in Python.

You will work with the two_cities string. It contains the first sentence of Dickens's A Tale of Two Cities novel. Feel free to explore it in the Shell.

Bài tập này là một phần của khóa học

Sentiment Analysis in Python

Xem khóa học

Hướng dẫn bài tập

  • Create a text blob object from the two_cities string.
  • Print out the polarity and subjectivity.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

# Import the required packages
from textblob import TextBlob

# Create a textblob object  
blob_two_cities = ____(two_cities)

# Print out the sentiment 
print(blob_two_cities.____)
Chỉnh sửa và Chạy Mã