Hãy tạo một đám mây từ!

Phân tích cảm xúc với Python

Violeta Misheva

Data Scientist

Ví dụ đám mây từ

ví dụ một đám mây từ nền đen

Phân tích cảm xúc với Python

Đám mây từ hoạt động thế nào?

 

Từ xuất hiện càng nhiều sẽ càng TO và đậm trên đám mây từ.

Phân tích cảm xúc với Python
  • Đám mây từ tạo từ một trong các đánh giá dài nhất

một đám mây từ hình tròn từ đánh giá về Titanic

Phân tích cảm xúc với Python

Vì sao dùng đám mây từ?

Ưu điểm
  • Có thể lộ rõ phần cốt lõi
  • Cho cảm nhận tổng quan về văn bản
  • Dễ hiểu và hấp dẫn
Nhược điểm

  • Đôi khi khó hiểu, ít thông tin
  • Với văn bản lớn, cần nhiều công sức hơn
Phân tích cảm xúc với Python

Tạo đám mây từ trong Python!

from wordcloud import WordCloud
import matplotlib.pyplot as plt
two_cities = "It was the best of times, it was the worst of times, 
        it was the age of wisdom, it was the age of foolishness, 
        it was the epoch of belief, it was the epoch of incredulity, 
        it was the season of Light, it was the season of Darkness, 
        it was the spring of hope, it was the winter of despair, 
        we had everything before us, we had nothing before us, 
        we were all going direct to Heaven, we were all going
        direct the other way – in short, the period was so far
        like the present period, that some of its noisiest
        authorities insisted on its being received, for good
        or for evil, in the superlative degree of comparison only."
Phân tích cảm xúc với Python

Định nghĩa đối tượng WordCloud

cloud_two_cities = WordCloud().generate(two_cities)
# To see all arguments of the function
?WordCloud
  • Màu nền
  • Kích thước, phông chữ, tỉ lệ
  • Stopwords
# How does cloud_two_cities look like?
cloud_two_cities
<wordcloud.wordcloud.WordCloud at 0x2585f286d68>
Phân tích cảm xúc với Python

Hiển thị đám mây từ

plt.imshow(cloud_two_cities, interpolation='bilinear')
plt.axis('off')
plt.show()

một đám mây từ nền đen, tạo từ câu đầu của A Tale of Two Cities

Phân tích cảm xúc với Python

Ayo berlatih!

Phân tích cảm xúc với Python

Preparing Video For Download...