การแบ่งโทเคนและการทำความสะอาดข้อมูล

การวิเคราะห์ข้อความเบื้องต้นใน R

Maham Faisal Khan

Senior Data Science Content Developer

การใช้ tidytext

การวิเคราะห์ข้อความเบื้องต้นใน R

การแบ่งโทเคนข้อความ

คำศัพท์พื้นฐานของการประมวลผลภาษาธรรมชาติ (NLP):

  • Bag of words: คำในเอกสารมีความเป็นอิสระต่อกัน
  • ข้อความแต่ละชิ้นคือเอกสาร (document)
  • คำที่ไม่ซ้ำกันแต่ละคำคือ term
  • การปรากฏของ term แต่ละครั้งคือ token
  • กระบวนการสร้าง bag of words เรียกว่า tokenizing
การวิเคราะห์ข้อความเบื้องต้นใน R

การใช้ unnest_tokens()

tidy_review <- review_data %>% 
  unnest_tokens(word, review)

tidy_review
# A tibble: 229,481 x 4
   date    product                    stars word   
   <chr>   <chr>                      <dbl> <chr>  
 1 2/28/15 iRobot Roomba 650 for Pets     5 you    
 2 2/28/15 iRobot Roomba 650 for Pets     5 would  
 3 2/28/15 iRobot Roomba 650 for Pets     5 not    
# … with 229,478 more rows
การวิเคราะห์ข้อความเบื้องต้นใน R

การนับคำ

tidy_review %>% 
  count(word) %>% 
  arrange(desc(n))
# A tibble: 10,310 x 2
   word      n
   <chr> <int>
 1 the   11785
 2 it     7905
 3 and    6794
# … with 10,307 more rows
การวิเคราะห์ข้อความเบื้องต้นใน R

การใช้ anti_join()

  • ต้องการลบ stop words ออกจาก data frame ที่จัดระเบียบแล้ว
  • ใช้ join เพื่อดำเนินการนี้

การวิเคราะห์ข้อความเบื้องต้นใน R

การใช้ anti_join()

tidy_review2 <- review_data %>% 
  unnest_tokens(word, review) %>% 
  anti_join(stop_words)

tidy_review2
# A tibble: 78,868 x 4
   date     product                    stars word       
   <chr>    <chr>                      <dbl> <chr>      
 1 1/12/15  iRobot Roomba 650 for Pets     4 walk       
 2 1/12/15  iRobot Roomba 650 for Pets     4 rest       
# … with 78,866 more rows
การวิเคราะห์ข้อความเบื้องต้นใน R

นับคำอีกครั้ง

tidy_review2 %>% 
  count(word) %>% 
  arrange(desc(n))
# A tibble: 9,672 x 2
   word         n
   <chr>    <int>
 1 roomba    2286
 2 clean     1204
 3 vacuum     989
# … with 9,669 more rows
การวิเคราะห์ข้อความเบื้องต้นใน R

มาฝึกกันเถอะ!

การวิเคราะห์ข้อความเบื้องต้นใน R

Preparing Video For Download...