GithubHelp home page GithubHelp logo

kh-polarity's Introduction

kh-polarity

Sentiment polarity classification is a natural language processing (NLP) technique that determines whether a given piece of text has a positive, negative, or neutral sentiment. We investigated the application of a well-known shallow neural network classifier, FastText, to the Khmer language, which is a low-resource language. To our knowledge, there isn’t a freely available polarity corpus for Khmer. Thus, one of the primary objectives of this research is to develop a human-annotated benchmark corpus tailored for sentiment analysis in this language. Our findings indicate that the FastText model achieves a precision and recall of 0.740 using our modest-sized Khmer polarity corpus, which consists of about 9,000 training sentences and about 1,000 testing sentences. Among traditional machine learning methods—K-Nearest Neighbors (KNN), Decision Tree, Random Forest, Support Vector Machine (SVM), and Stochastic Gradient Descent (SGD)—the SVM outperforms the rest.

ការចាត់ថ្នាក់កំណត់ចំណាំមតិគឺជាបច្ចេកវិទ្យាភាសា (NLP) មួយ ដែលអាចកំណត់បានថាតើប្រយោគដែលបានផ្តល់ឱ្យបង្ហាញអំពីមិតិ វិជ្ជមាន(positive) អវិជ្ជមាន(negative) ឬមិនលម្អៀង(neutral)។ យើងបានអង្កេតលើការអនុវត្តវិធីសាស្ដ្រនៃការចាត់ថ្នាក់ដែលមានលក្ខណៈជា shallow neural network នោះគឺ គំរូ FastText ដើម្បីធ្វើការពិសោធន៍ទៅលើភាសាខ្មែរ ដែលជាភាសាមានសំណុំទិន្នន័យតិចតួចនៅឡើយ។ យោងតាមការសិក្សាស្រាវជ្រាវ យើងរកឃើញថាមិនទាន់មានធនធាន ឬសំណុំទិន្នន័យអំពីការធ្វើការចាត់ថ្នាក់កំណត់ចំណាំមតិសម្រាប់ភាសាខ្មែរនៅឡើយទេ។ ដូច្នេះហើយ គោលបំណងដំបូងរបស់យើងសម្រាប់ការស្រាវជ្រាវមួយនេះគឺ ដើម្បីបង្កើតទិន្នន័យកំណត់ចំណាំមតិរបស់មនុស្សលើប្រយោគមួយសម្រាប់ធ្វើការវិភាគមតិ ឬគំនិតយល់ឃើញរបស់មនុស្សនៅក្នុងភាសាខ្មែរនេះ។ តាមការរកឃើញរបស់យើងបានបង្ហាញថា គំរូ FastText ទទួលបាននូវតម្លៃ precision និង recall ស្មើនឹង 0.740 ដោយបានប្រើប្រាស់ទំហំទិន្នន័យភាសាខ្មែរសមល្មមដែលរួមមានសំណុំទិន្នន័យបង្វឹកចំនួន 9,000 ប្រយោគ និងសំណុំទិន្នន័យតេស្ដចំនួន 1,000 ប្រយោគ ។ មិនតែប៉ុណ្ណោះយើងក៏បានធ្វើពិសោធលើគំរូមួយចំនួនរបស់សិក្ខាម៉ាស៊ីន (machine learning) ដូចជា K-Nearest Neighbors (KNN), Decision Tree, Random Forest, Support Vector Machine (SVM) និង Stochastic Gradient Descent (SGD) ក្រោយមកយើងសង្កេតឃើញថា គំរូ SVM ផ្ដល់លទ្ធផលបានល្អជាងគំរូដទៃ។

Corpus Information

Below is the tree structure of the corpus folder:

$ tree ./corpus/
./corpus/
├── exp
│   ├── csv_format
│   │   ├── test.csv
│   │   └── train.csv
│   └── fasttext_format
│       ├── test.sentence.fasttext
│       └── train.sentence.fasttext
└── version-1
    └── kh-polar.ver1.0.txt

4 directories, 5 files

In the exp/ folder, you will find the training and test datasets used in our experiments. These datasets are formatted as comma-separated values (CSV) and are located under the exp/csv_format/ folder. We applied traditional machine learning methods such as K-nearest Neighbors (KNN), Decision Tree, Random Forest, Support Vector Machine (SVM), and Stochastic Gradient Descent (SGD) for Khmer polarity classification. The CSV format is as follows:

(base) ye@lst-gpu-3090:~/tmp/kh-polarity/corpus/exp/csv_format$ head -n 3 train.csv
text,label
▁រដ្ឋ ម ន្ត រី ប រ ិ ស្ថាន អ ៊ ុយ ក្រ ែន បាន បញ្ជា ក់ កាល ពី ថ ្ ង ៃ ច ន្ទ ទី ▁៣ ▁ខែ ត ុល ា ថា ▁ការ ខ ូ ច ខាត ប រ ិ ស្ថាន ក្នុង ប្រ ទេស អ ៊ ុយ ក្រ ែន ដែ ល ប ណ្តាល មក ពី ការ ឈ ្ល ាន ព ាន រ ប ស់ រ ុ ស្ ស៊ី ត្រ ូវ បាន គេ ប៉ ាន់ ប្រ មា ណ ថា ▁មាន ទ ំ ហ ំ ជា ង ▁៣ ៥ ៣ ព ាន់ ល ាន ដ ុល ្ល ារ ▁ជាមួយ នឹង ត ំ ប ន់ អ ភ ិ រ ក្ស ធ ម្ ម ជាតិ រ ាប់ ល ាន ហ ិក តា ទ ៀ ត ស្ ថ ិត ន ៅ ក ្រោម ការ គ ំ រា មក ំ ហ ែង ▁។,negative
▁ខ្ញុំ ច ង់ ច ាប់ ផ្តើម ប្រ ើ ផ ា ស ពិសេស ស ំ រ ាប់ អ ្ន ក ធ្វើដំណើរ,neutral
(base) ye@lst-gpu-3090:~/tmp/kh-polarity/corpus/exp/csv_format$ head -n 3 test.csv
text,label
▁ នេះ ប ើ តា ម ប្រ សា ស ន៍ រ ប ស់ ▁ឯក ឧ ត្ត ម ▁ ន េ ត្រ ▁ភ ក ្ត រា ▁រដ្ឋ លេខ ា ធ ិ ការ ▁និង ជា អ ន ុ ប្រ ធាន អ ច ិ ន្ត រ ៃ យ ៍ ក្រ ុ ម ការ ង ារ ប្រឆាំង ការ ស ម្ អា ត ប្រ ាក់ នៃ ក្រ ស ួង ប រ ិ ស្ថាន ▁កាល ថ ្ ង ៃ ទី ៥ ▁ខែ ត ុល ា ▁ឆ្នាំ ២ ០ ២ ២ ▁។,negative
▁ចំណ ែក ▁ម ន្ត រី ▁ សិទ្ធិ ម ន ុ ស្ស ▁និង ▁អ្នក វិ ភ ា គ ▁យល់ ▁ថា ▁អ្វី ▁ដែល ▁លោក ▁ ហ៊ុន ▁ស ែន ▁លើក ▁ឡើង ▁មក ▁នោះ ▁ជា ▁វ ោ ហា រ សា ស្ត រ ▁ ន យោប ាយ ▁ដើម្បី ▁ប ន ្ល ំ ▁ការ ▁ពិ ត ▁ប៉ុណ្ណ ោះ ។,negative

For experiments utilizing the FastText approach, a specific data format is required. FastText is a library for efficient learning of word representations and sentence classification. It is particularly useful for applications that benefit from understanding the nuances and meanings of words within large datasets. To accommodate FastText's requirements, we prepared our data in a format that is compatible with this library. This formatted data can be found under exp/fasttext_format/. The FastText format is structured as follows:

(base) ye@lst-gpu-3090:~/tmp/kh-polarity/corpus/exp/fasttext_format$ head -n 3 train.sentence.fasttext
__label__negative ▁រដ្ឋ ម ន្ត រី ប រ ិ ស្ថាន អ ៊ ុយ ក្រ ែន បាន បញ្ជា ក់ កាល ពី ថ ្ ង ៃ ច ន្ទ ទី ▁៣ ▁ខែ ត ុល ា ថា ▁ការ ខ ូ ច ខាត ប រ ិ ស្ថាន ក្នុង ប្រ ទេស អ ៊ ុយ ក្រ ែន ដែ ល ប ណ្តាល មក ពី ការ ឈ ្ល ាន ព ាន រ ប ស់ រ ុ ស្ ស៊ី ត្រ ូវ បាន គេ ប៉ ាន់ ប្រ មា ណ ថា ▁មាន ទ ំ ហ ំ ជា ង ▁៣ ៥ ៣ ព ាន់ ល ាន ដ ុល ្ល ារ ▁ជាមួយ នឹង ត ំ ប ន់ អ ភ ិ រ ក្ស ធ ម្ ម ជាតិ រ ាប់ ល ាន ហ ិក តា ទ ៀ ត ស្ ថ ិត ន ៅ ក ្រោម ការ គ ំ រា មក ំ ហ ែង ▁។
__label__neutral ▁ខ្ញុំ ច ង់ ច ាប់ ផ្តើម ប្រ ើ ផ ា ស ពិសេស ស ំ រ ាប់ អ ្ន ក ធ្វើដំណើរ
__label__neutral ▁ក្រោយ ពេល ដែ ល វា បាន ហ ែ ល ប ត់ ច ុះ ប ត់ ឡើង គ ្រ ប់ ៗ ក ន ្ល ែង វា ទៅ ដល់ ស្រ ុក ខ ោ ន ហើយ វា ស ំ ច ត ន ៅ ទី នោះ ២ . ២ ថ ្ ង ៃ ទ ើ ប វា ហ ែ ល ច ុះ មក វិញ ។
(base) ye@lst-gpu-3090:~/tmp/kh-polarity/corpus/exp/fasttext_format$
(base) ye@lst-gpu-3090:~/tmp/kh-polarity/corpus/exp/fasttext_format$ head -n 3 test.sentence.fasttext
__label__negative ▁ នេះ ប ើ តា ម ប្រ សា ស ន៍ រ ប ស់ ▁ឯក ឧ ត្ត ម ▁ ន េ ត្រ ▁ភ ក ្ត រា ▁រដ្ឋ លេខ ា ធ ិ ការ ▁និង ជា អ ន ុ ប្រ ធាន អ ច ិ ន្ត រ ៃ យ ៍ ក្រ ុ ម ការ ង ារ ប្រឆាំង ការ ស ម្ អា ត ប្រ ាក់ នៃ ក្រ ស ួង ប រ ិ ស្ថាន ▁កាល ថ ្ ង ៃ ទី ៥ ▁ខែ ត ុល ា ▁ឆ្នាំ ២ ០ ២ ២ ▁។
__label__negative ▁ចំណ ែក ▁ម ន្ត រី ▁ សិទ្ធិ ម ន ុ ស្ស ▁និង ▁អ្នក វិ ភ ា គ ▁យល់ ▁ថា ▁អ្វី ▁ដែល ▁លោក ▁ ហ៊ុន ▁ស ែន ▁លើក ▁ឡើង ▁មក ▁នោះ ▁ជា ▁វ ោ ហា រ សា ស្ត រ ▁ ន យោប ាយ ▁ដើម្បី ▁ប ន ្ល ំ ▁ការ ▁ពិ ត ▁ប៉ុណ្ណ ោះ ។
__label__positive ▁ការងា រ មាន ស្ ថ ិ រ ភាព ▁ហើយ អ ្ន ក អា ច ទ ទ ួល បាន ស ម ិទ្ធ ផល ជ ាក់ ល ាក់ ក្នុង អា ជ ី ព រ ប ស់ អ ្ន ក ▁ ធាន ា ជ ី វ ិត រ ប ស់ អ ្ន ក ។
(base) ye@lst-gpu-3090:~/tmp/kh-polarity/corpus/exp/fasttext_format$

kh-polarity (Version 1.0)

The complete dataset for kh-polarity version 1.0 is stored in the corpus/version-1/ folder. The format of the dataset is 'sentence ||| keyword ||| polarity', as illustrated below:

(base) ye@lst-gpu-3090:~/tmp/kh-polarity/corpus/version-1$ head ./kh-polar.ver1.0.txt
នាយិកាមជ្ឈមណ្ឌលសិទ្ធិមនុស្សកម្ពុជាអ្នកស្រី ចក់ សុភាព បង្ហាញខ្លួននៅតុលាការក្រុងភ្នំពេញ ក្នុងនាមជាសាក្សីក្នុងចំណោមសាក្សីផ្សេងទៀត ក្នុងសំណុំរឿងមេដឹកនាំនយោបាយជំទាស់លោក កឹម សុខា ទីក្រុងភ្នំពេញ ថ្ងៃទី៥ ខែតុលា ឆ្នាំ២០២២។ ||| បង្ហាញខ្លួន ||| neutral
ការឃុំខ្លួនកញ្ញា សេង ធារី កាន់តែយូរដោយរដ្ឋាភិបាលលោក ហ៊ុន សែន នោះនឹងធ្វើឱ្យមនុស្សម្នាកាន់តែច្រើនដឹងឮកាន់តែខ្លាំងអំពីរបបផ្តាច់ការនេះ និងការណ៍ដែលរបបនេះពុំមានឆន្ទៈអនុញ្ញាតឱ្យមានសំឡេងនយោបាយប្រឆាំង ព្រមទាំងវិធីដែលលោក ហ៊ុន សែន រក្សាអំណាចដោយប្រើកណ្តាប់ដៃដែករបស់គាត់។ ||| ដឹងឮកាន់តែខ្លាំង ||| positive
ប្រភពបង្ហើបថា បន្ទប់នោះមានខ្ទង់ចំណាយប្រមាណជាង ១០ម៉ឺនដុល្លារអាមេរិកឯណោះ។ ||| បង្ហើប ||| neutral
1956បានបង្ហាញថាផូស្វ័របានផ្ទេរចេញពីដើមបែកអារទៅដើមបែកឱ្យផលក្នុងអំឡុងដំណាក់កាលផើមប៉ុន្តែមិនមានការផ្ទេរផូស្វ័រចេញពីដើមបែកថ្មីទៅដើមបែកចាស់នោះទេ ||| ផ្ទេរ ||| neutral
ដរាបណាយើងមិនបានតាំងចិត្តខិតខំប្រឹងរៀន ប្រឹងធ្វើលំហាត់ជារៀងរាល់ថ្ងៃតាំងពីដើមឆ្នាំទេ នោះនិទ្ទេស A ក៏គ្មានថ្ងៃក្លាយជារបស់យើងដែរ។ ||| មិនបានតាំងចិត្តខិតខំប្រឹងរៀន/គ្មានថ្ងៃក្លាយជារបស់យើង ||| negative
សូមបញ្ជាក់ថា ក្រុមការងារក្រសួងមហាផ្ទៃបានសហការជាមួយអាជ្ញាធរខេត្តព្រះ សីហនុ បានចុះបង្ក្រាបទីតាំងល្បែងខុសច្បាប់ចំនួន៥ទីតាំង នៅក្នុងក្រុងព្រះសីហនុ និងបាន រកឃើញជនបរទេសចម្រុះជាតិសាសន៍៕ ||| សហការ ||| positive
សាលាដំបូងរាជធានីភ្នំពេញបានចោទប្រកាន់លោក សុន ឆ័យ ពីបទបរិហាកេរ្តិ៍ពាក់ព័ន្ធនឹងការអត្ថាធិប្បាយរិះគន់ការបោះឆ្នោតក្រុមប្រឹក្សាឃុំសង្កាត់ តាមពាក្យបណ្តឹងរបស់គណបក្សប្រជាជនកម្ពុជា ដែលទាមទារឱ្យមេដឹកនាំគណបក្សប្រឆាំងបង់សងជំងឺចិត្តចំនួន ៤ ពាន់លានរៀល គឺប្រមាណ ១ លានដុល្លារអាមេរិក និងស្ថាប័នរៀបចំការបោះឆ្នោត គ.ជ.ប ទាមទារឱ្យលោក សុន ឆ័យ សុំទោសជាសាធារណៈ។ ||| អត្ថាធិប្បាយរិះគន់ ||| negative
ក្នុងលិខិតបានបញ្ជាក់ថា ក្រុមការងារបង្ក្រាបមានតួនាទីភារកិច្ចក្នុងការរៀបចំផែនការ វិធានការ គោលការណ៍ណែនាំ ដើម្បីឱ្យអាជ្ញាធរមានសមត្ថកិច្ចគ្រប់លំដាប់ថ្នាក់ អនុវត្តបង្ក្រាបនូវរាល់ការលេងល្បែងស៊ីសងខុសច្បាប់គ្រប់ប្រភេទ និងត្រូវសហការជាមួយអាជ្ញាធរមានសមត្ថកិច្ចទាំងនៅថ្នាក់ជាតិ រដ្ឋបាលថ្នាក់ក្រោមជាតិ ដើម្បីធ្វើការស្រាវជ្រាវ និងចាត់វិធានការបង្ក្រាបនូវទីតាំងលេងល្បែងស៊ីសងខុសច្បាប់។ ||| សហការជាមួយអាជ្ញាធរមានសមត្ថកិច្ច ||| positive
ជាទូទៅកសិករភាគច្រើនមិនចង់លក់ដី ស្រែរបស់គាត់ទេ ពីព្រោះដីស្រែជាឆ្នាំងបាយ និង ប្រភពចំណូលដ៏សំខាន់របស់កសិករ ||| មិនចង់លក់ដីស្រែរបស់គាត់ទេ ||| negative
យុវនារីណាដែលកាន់សៀវភៅពេលបច្ចុប្បន្ន គឺនឹងក្លាយទៅជាម្តាយដ៏ល្អនាពេលអនាគត។ ||| ម្តាយដ៏ល្អ ||| positive
(base) ye@lst-gpu-3090:~/tmp/kh-polarity/corpus/version-1$

Code Information

for Preprocessing

[1]. khnormal, The original or active code for Khmer Normalization.
[2]. khnormal.2.py, This code was used for Khmer Normalization.
[3]. cut-column.pl, This code was used to fix the number of class errors.
[4]. print-codepoint.pl, This code was used for printing the code points (decimal, Unicode) of each Khmer character.
[5]. check-empty-field.pl, This code was used to clean blank fields in the Khmer polarity corpus.
[6]. train-sentencepiece.py, This code was used to train SentencePiece model.
[7]. break.py, This code was used for SentencePiece segmentation.

for Modeling

[1]. knn-classifier.py: K Nearest Neighbor (KNN) Classifier
[2]. dtree-classifier.py: Decision-Tree Classifier
[3]. rforest-classifier.py: Random-Forest Classifier
[4]. svm-classifier.py: Support Vector Machine (SVM) Classifier
[5]. sgd-classifier2.py: Stochastic Gradient Descent (SGD) Classifier
[6]. sgd-tune-classifier.py: Tuning with Stochastic Gradient Descent (SGD) Classifier

For the FastText modeling, I utilized the command-line tool fastText. For guidance, I referred to this tutorial. Details of the experiment can be found in this log file: testing-tabpfn.md, which documents an experiment involving TabPFN. However, it's important to note that this TabPFN experiment is not yet completed and is not included in our paper.

Experiment Logs

In this section, you will find detailed logs of our experiments. File No. 1 includes data cleaning and various preprocessing steps. File No. 2 details the results obtained using the first version of our classifiers. The results presented in our paper are primarily derived from log files No. 3 and the latter part of No. 4.

  1. kh-polarity-exp1: This log file pertains to Experiment 1, focusing on data cleaning and preprocessing.
  2. kh-polarity-exp2: This log file corresponds to Experiment 2, featuring the initial classifier results.
  3. kh-polarity-exp3: This log file is for Experiment 3, which significantly contributes to the results discussed in our paper.
  4. testing-tabpfn.md: This log file documents an experiment involving TabPFN and FastText, with its latter part being crucial for our paper's findings.

Presentation Slide

At the 4th NLP/AI Workshop 2022

At the iSAI-NLP Conference 2023

  • kh_polarity_talk.pdf: This is the presentation slide for the 18th iSAI-NLP 2023 conference, held in Bangkok, Thailand.

Citation

If you plan to use any code snippets or the kh-polarity corpus in your research, we kindly ask that you acknowledge and cite the following paper:

Sokheng Khim, Ye Kyaw Thu and Sethserey Sam, "Sentiment Polarity Classification for Khmer", In Proceedings of the 18th International Joint Symposium on Artificial Intelligence and Natural Language Processing (iSAI-NLP 2023), Nov 27 to 29, 2023, Bangkok, Thailand, pp. xx-xx

References

[1]. Pandey, A., & Jain, A. (2017). Comparative analysis of KNN algorithm using various normalization techniques. International Journal of Computer Network and Information Security, 9(11), 36.
[2]. Uddin, S., Haque, I., Lu, H., Moni, M. A., & Gide, E. (2022). Comparative performance analysis of K-nearest neighbour (KNN) algorithm and its different variants for disease prediction. Scientific Reports, 12(1), 1-11.
[3]. Quinlan, J. R. (1996). Learning decision tree classifiers. ACM Computing Surveys (CSUR), 28(1), 71-72.
[4] Song, Y. Y., & Ying, L. U. (2015). Decision tree methods: applications for classification and prediction. Shanghai archives of psychiatry, 27(2), 130.
[5]. Gao, D., Zhang, Y. X., & Zhao, Y. H. (2009). Random forest algorithm for classification of multiwavelength data. Research in Astronomy and Astrophysics, 9(2), 220.
[6]. Bhavsar, H., & Panchal, M. H. (2012). A review on support vector machine for data classification. International Journal of Advanced Research in Computer Engineering & Technology (IJARCET), 1(10), 185-189.
[7]. Sharma, A. (2018). Guided stochastic gradient descent algorithm for inconsistent datasets. Applied Soft Computing, 73, 1068-1080.
[8]. Wang, J., & Joshi, G. (2021). Cooperative SGD: A unified framework for the design and analysis of local-update SGD algorithms. Journal of Machine Learning Research, 22.
[9]. A. Joulin, E. Grave, P. Bojanowski, T. Mikolov, Bag of Tricks for Efficient Text Classification

kh-polarity's People

Contributors

ye-kyaw-thu avatar

Stargazers

 avatar Than Lwin Aung avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.