สรุปบทเรียน AI แบบงงๆกับพี่ทิวใจบางภาคสุดท้าย : โกรธไม่โกรธจะรู้ได้ไง? กับ Sentiment Analysis


วาดเอง ตั้งใจมาก

Sentiment Analysis เป็นการวิเคราะห์ Emotion จากข้อความเพื่อแสดงให้เห็นว่าข้อความต่อไปนี้มีอารมณ์เป็นอย่างไร โดยแบ่งได้ง่ายๆเป็น

ทิศทางบวก : Positive

ทิศทางลบ : Negative

เป็นกลาง : Neutral

โดยในวันนี้จะแสดงให้เห็นว่า Sentiment Analysis สามารถทำอะไรได้บ้าง

import pandas as pd

from pathlib import Path

from pythainlp.tokenize import word_tokenize

from matplotlib import pyplot as plt

ตัดคำ

หาตวามยาวของประโยค

แสดงเป็นกราฟ โดยแบ่งตามกลุ่ม

ด้านล่างต่อจากนี้จะเป็นการทำ Word2Vec

import multiprocessing
from gensim.models import Word2Vec

ประโยคทั้งหมด

สร้างโมเดล

ผลลัพท์

OneHot

from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import LabelEncoder

Padding

นิยาม และ Compile Model

Split Data

Train

วัดประสิทธิภาพของโมเดล

โดยมีความแม่นยำอยู่ที่ 61 %

โดยภาษาไทยนั้นค่อนข้างยากที่จะแยกประโยค เพราะบางประโยคไม่ได้สื่อความหมายไปทางนั้นๆอย่างจริงๆจังๆ และ ส่วนนึงโมเดลอาจจะเกิด Overfitting ทำให้มีความแม่นยำที่ต่ำ


ก็ขอบคุณมากครับที่แวะเข้ามาอ่าน นี่ก็เป็นกระทู้สุดท้ายแล้ว ถ้ามีโอกาศในวันข้างหน้าก็อาจจะกลับมาเขียนใหม่ หรือกลับมานั่งแก้ที่ตัวเองเขียนลวกๆส่ง อจ. (รู้สึกผิดจริงๆนะครับ T_T ) ช่วงนี้ก็เข้าสู่ฤดูหนาวแล้วอย่าลืมใส่เสื้อกันหนาวนะครับ ยังไงก็ขอบคุณมากเลยครับที่ติดตามมาจนถึงทุกวันนี้ ขอตัวลาไปก่อน สวัสดีครับ

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade