Coder Social home page Coder Social logo

pythainlp / attacut Goto Github PK

View Code? Open in Web Editor NEW
78.0 78.0 16.0 4.24 MB

A Fast and Accurate Neural Thai Word Segmenter

Home Page: https://pythainlp.github.io/attacut/

License: MIT License

Python 98.75% Shell 1.25%
cnn hacktoberfest hactoberfest2022 nlp tokenization

attacut's Introduction

PyThaiNLP: Thai Natural Language Processing in Python

Project Status: Active – The project has reached a stable, usable state and is being actively developed. pypi Python 3.8 License Unit test and code coverage Coverage Status Google Colab Badge DOI Chat on Matrix

PyThaiNLP is a Python package for text processing and linguistic analysis, similar to NLTK with a focus on Thai language.

PyThaiNLP เป็นไลบารีภาษาไพทอนสำหรับประมวลผลภาษาธรรมชาติ คล้ายกับ NLTK โดยเน้นภาษาไทย ดูรายละเอียดภาษาไทยได้ที่ README_TH.MD

News

Now, You can contact with or ask any questions of the PyThaiNLP team. Chat on Matrix

Version Description Status
5.0.4 Stable Change Log
dev Release Candidate for 5.1 Change Log

Getting Started

Capabilities

PyThaiNLP provides standard linguistic analysis for Thai language and standard Thai locale utility functions. Some of these functions are also available via the command-line interface (run thainlp in your shell).

Partial list of features:

  • Convenient character and word classes, like Thai consonants (pythainlp.thai_consonants), vowels (pythainlp.thai_vowels), digits (pythainlp.thai_digits), and stop words (pythainlp.corpus.thai_stopwords) -- comparable to constants like string.letters, string.digits, and string.punctuation
  • Linguistic unit segmentation at different levels: sentence (sent_tokenize), word (word_tokenize), and subword (subword_tokenize)
  • Part-of-speech tagging (pos_tag)
  • Spelling suggestion and correction (spell and correct)
  • Phonetic algorithm and transliteration (soundex and transliterate)
  • Collation (sorted by dictionary order) (collate)
  • Number read out (num_to_thaiword and bahttext)
  • Datetime formatting (thai_strftime)
  • Thai-English keyboard misswitched fix (eng_to_thai, thai_to_eng)

Installation

pip install --upgrade pythainlp

This will install the latest stable release of PyThaiNLP.

Install different releases:

  • Stable release: pip install --upgrade pythainlp
  • Pre-release (nearly ready): pip install --upgrade --pre pythainlp
  • Development (likely to break things): pip install https://github.com/PyThaiNLP/pythainlp/archive/dev.zip

Installation Options

Some functionalities, like Thai WordNet, may require extra packages. To install those requirements, specify a set of [name] immediately after pythainlp:

pip install pythainlp[extra1,extra2,...]

Possible extras:

  • full (install everything)
  • attacut (to support attacut, a fast and accurate tokenizer)
  • benchmarks (for word tokenization benchmarking)
  • icu (for ICU, International Components for Unicode, support in transliteration and tokenization)
  • ipa (for IPA, International Phonetic Alphabet, support in transliteration)
  • ml (to support ULMFiT models for classification)
  • thai2fit (for Thai word vector)
  • thai2rom (for machine-learnt romanization)
  • wordnet (for Thai WordNet API)

For dependency details, look at the extras variable in setup.py.

Data Directory

  • Some additional data, like word lists and language models, may be automatically downloaded during runtime.
  • PyThaiNLP caches these data under the directory ~/pythainlp-data by default.
  • The data directory can be changed by specifying the environment variable PYTHAINLP_DATA_DIR.
  • See the data catalog (db.json) at https://github.com/PyThaiNLP/pythainlp-corpus

Command-Line Interface

Some of PyThaiNLP functionalities can be used via command line with the thainlp command.

For example, to display a catalog of datasets:

thainlp data catalog

To show how to use:

thainlp help

Licenses

License
PyThaiNLP source codes and notebooks Apache Software License 2.0
Corpora, datasets, and documentations created by PyThaiNLP Creative Commons Zero 1.0 Universal Public Domain Dedication License (CC0)
Language models created by PyThaiNLP Creative Commons Attribution 4.0 International Public License (CC-by)
Other corpora and models that may be included in PyThaiNLP See Corpus License

Contribute to PyThaiNLP

  • Please fork and create a pull request :)
  • For style guides and other information, including references to algorithms we use, please refer to our contributing page.

Who uses PyThaiNLP?

You can read INTHEWILD.md.

Citations

If you use PyThaiNLP in your project or publication, please cite the library as follows:

Wannaphong Phatthiyaphaibun, Korakot Chaovavanich, Charin Polpanumas, Arthit Suriyawongkul, Lalita Lowphansirikul, & Pattarawat Chormai. (2016, Jun 27). PyThaiNLP: Thai Natural Language Processing in Python. Zenodo. http://doi.org/10.5281/zenodo.3519354

or by BibTeX entry:

@misc{pythainlp,
    title = "{P}y{T}hai{NLP}: {T}hai Natural Language Processing in {P}ython",
    author = "Phatthiyaphaibun, Wannaphong  and
      Chaovavanich, Korakot  and
      Polpanumas, Charin  and
      Suriyawongkul, Arthit  and
      Lowphansirikul, Lalita  and
      Chormai, Pattarawat",
    month = jun,
    year = "2016",
    doi = {10.5281/zenodo.3519354},
    publisher = {Zenodo},
    url = {http://doi.org/10.5281/zenodo.3519354}
}

Our NLP-OSS 2023 paper:

Wannaphong Phatthiyaphaibun, Korakot Chaovavanich, Charin Polpanumas, Arthit Suriyawongkul, Lalita Lowphansirikul, Pattarawat Chormai, Peerat Limkonchotiwat, Thanathip Suntorntip, and Can Udomcharoenchaikit. 2023. PyThaiNLP: Thai Natural Language Processing in Python. In Proceedings of the 3rd Workshop for Natural Language Processing Open Source Software (NLP-OSS 2023), pages 25–36, Singapore, Singapore. Empirical Methods in Natural Language Processing.

and its BibTeX entry:

@inproceedings{phatthiyaphaibun-etal-2023-pythainlp,
    title = "{P}y{T}hai{NLP}: {T}hai Natural Language Processing in {P}ython",
    author = "Phatthiyaphaibun, Wannaphong  and
      Chaovavanich, Korakot  and
      Polpanumas, Charin  and
      Suriyawongkul, Arthit  and
      Lowphansirikul, Lalita  and
      Chormai, Pattarawat  and
      Limkonchotiwat, Peerat  and
      Suntorntip, Thanathip  and
      Udomcharoenchaikit, Can",
    editor = "Tan, Liling  and
      Milajevs, Dmitrijs  and
      Chauhan, Geeticka  and
      Gwinnup, Jeremy  and
      Rippeth, Elijah",
    booktitle = "Proceedings of the 3rd Workshop for Natural Language Processing Open Source Software (NLP-OSS 2023)",
    month = dec,
    year = "2023",
    address = "Singapore, Singapore",
    publisher = "Empirical Methods in Natural Language Processing",
    url = "https://aclanthology.org/2023.nlposs-1.4",
    pages = "25--36",
    abstract = "We present PyThaiNLP, a free and open-source natural language processing (NLP) library for Thai language implemented in Python. It provides a wide range of software, models, and datasets for Thai language. We first provide a brief historical context of tools for Thai language prior to the development of PyThaiNLP. We then outline the functionalities it provided as well as datasets and pre-trained language models. We later summarize its development milestones and discuss our experience during its development. We conclude by demonstrating how industrial and research communities utilize PyThaiNLP in their work. The library is freely available at https://github.com/pythainlp/pythainlp.",
}

Sponsors

Logo Description
VISTEC-depa Thailand Artificial Intelligence Research Institute Since 2019, our contributors Korakot Chaovavanich and Lalita Lowphansirikul have been supported by VISTEC-depa Thailand Artificial Intelligence Research Institute.
MacStadium We get support of free Mac Mini M1 from MacStadium for running CI builds.

Made with ❤️ | PyThaiNLP Team 💻 | "We build Thai NLP" 🇹🇭

We have only one official repository at https://github.com/PyThaiNLP/pythainlp and another mirror at https://gitlab.com/pythainlp/pythainlp
Beware of malware if you use codes from mirrors other than the official two on GitHub and GitLab.

attacut's People

Contributors

bact avatar p16i avatar titipata avatar wannaphong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

attacut's Issues

attacut-sc doesn't tokenise space properly

Example from https://colab.research.google.com/drive/11nMfWmPGR_82voL37okn4XlxMPVbsu9r#scrollTo=v5sGX_dlQ2_B

It seems that spaces aren't tokenised properly. Please see the issue below:

|Blognone |Tomorrow |2019 |ประกาศ|ชื่อ |speaker |เพิ่มเติม |1 |ท่าน|คือ |คุณธนาธร |จึงรุ่งเรืองกิจ |หัวหน้า|พรรคอนาคต|ใหม่ |จะ|มา|พูด|ใน|หัวข้อ |Hyperloop |and |Path |Skipping |Development 
|Strategy |หรือ|แปล|เป็น|ภาษา|ไทย|คือ |"|Hyperloop |กับ|การ|พัฒนา|แบบ|เสือ|กระโดด|"

Can't install on Windows

I used pip install https://github.com/PyThaiNLP/attacut/archive/master.zip on Windows but it has a installation problems. torch can't install on Windows.

>pip install https://github.com/PyThaiNLP/attacut/archive/master.zip
Collecting https://github.com/PyThaiNLP/attacut/archive/master.zip
  Downloading https://github.com/PyThaiNLP/attacut/archive/master.zip
     \ 2.4MB 1.1MB/s
Requirement already satisfied: docopt==0.6.2 in c:\users\tc\anaconda3\lib\site-packages (from attacut==0.0.3.dev0) (0.6.2)
Collecting fire==0.1.3 (from attacut==0.0.3.dev0)
  Downloading https://files.pythonhosted.org/packages/5a/b7/205702f348aab198baecd1d8344a90748cb68f53bdcd1cc30cbc08e47d3e/fire-0.1.3.tar.gz
Collecting nptyping==0.2.0 (from attacut==0.0.3.dev0)
  Downloading https://files.pythonhosted.org/packages/a5/0f/9b44a1866c7911d03329669d82d2ebb1b8e6dac15803fdb6588549a44193/nptyping-0.2.0-py3-none-any.whl
Collecting numpy==1.17.0 (from attacut==0.0.3.dev0)
  Downloading https://files.pythonhosted.org/packages/26/26/73ba03b2206371cdef62afebb877e9ba90a1f0dc3d9de22680a3970f5a50/numpy-1.17.0-cp37-cp37m-win_amd64.whl (12.8MB)
     |████████████████████████████████| 12.8MB 3.3MB/s
Requirement already satisfied: python-crfsuite==0.9.6 in c:\users\tc\anaconda3\lib\site-packages (from attacut==0.0.3.dev0) (0.9.6)
Collecting pyyaml==5.1.2 (from attacut==0.0.3.dev0)
  Downloading https://files.pythonhosted.org/packages/bc/3f/4f733cd0b1b675f34beb290d465a65e0f06b492c00b111d1b75125062de1/PyYAML-5.1.2-cp37-cp37m-win_amd64.whl (215kB)
     |████████████████████████████████| 225kB 3.2MB/s
Requirement already satisfied: six==1.12.0 in c:\users\tc\anaconda3\lib\site-packages (from attacut==0.0.3.dev0) (1.12.0)
Collecting ssg==0.0.4 (from attacut==0.0.3.dev0)
  Downloading https://files.pythonhosted.org/packages/05/e0/226b4fb9144d80a3efc474e581097d77abc4e8c3ce8e751469cb1c25e671/ssg-0.0.4-py3-none-any.whl (473kB)
     |████████████████████████████████| 481kB 2.2MB/s
Collecting torch==1.2.0 (from attacut==0.0.3.dev0)
  ERROR: Could not find a version that satisfies the requirement torch==1.2.0 (from attacut==0.0.3.dev0) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2)
ERROR: No matching distribution found for torch==1.2.0 (from attacut==0.0.3.dev0)

beta release

Tasks

  • make it pipable
  • use logger instead of print
  • add more test
  • add linting
  • refactor training.py
  • [ ] batch processing for attacut-cli (moved to #5)

Documentations (now available on https://pythainlp.github.io/attacut)

  • how to train a new model
  • module overview in this repo

Testing & Final Benchmark

  • install via pip
  • run tokenization to check whether the implement is correctly migrated.
  • testing speed
  • update visualisation results

the meaning of label data

@cnlinxi sorry again for my response. You can find the data at https://codeforthailand.s3-ap-southeast-1.amazonaws.com/attacut-related/data.zip

Please unzip and make sure the root directory is at ./data. The content of the archive contains
image

Only the first two are relevant for training; sampling-0 means all the dateset, while sampling-10 means only 10 files are used. You can use sampling-10 for quick training.

Before running the training command below, make sure that you have the ./artifacts directory.

python ./scripts/train.py --model-name seq_sy_ch_conv_concat \
 --model-params "embc:8|embs:8|conv:8|l1:6|do:0.1" \
 --data-dir ./data/best-syllable-crf-and-character-seq-feature-sampling-0  \
 --output-dir ./artifacts/model-xx  \
 --epoch 2 \
 --batch-size 1024 \
 --lr 0.001 \
 --lr-schedule "step:5|gamma:0.5"

Originally posted by @heytitle in #20 (comment)

custom_dict param is not working properly on attacut tokenizer

Env:

  • Google Colab

Version :

  • pythainlp (3.0.5)
  • attacut (1.0.6)

as Docs pythainlp.tokenize.word_tokenize said Attacut tokenizer provided custom_dict param. However, it seem not working properly.

from pythainlp.corpus.common import thai_words
from pythainlp.util import dict_trie
from pythainlp.tokenize import Tokenizer

custom_words_list = set(thai_words())
custom_words_list |= set(['ต้องการระบาย'])
trie = dict_trie(dict_source=custom_words_list)

_tokenizer = Tokenizer(custom_dict=trie, engine='attacut')

_tokenizer.word_tokenize('ต้องการ')

output

['ต้องการ', 'ระบาย']

expected output

['ต้องการระบาย']

PS1. I also tested with pythainlp.tokenize.word_tokenize. it's worked similar to above.
PS2. newmm and longest engine still work with custom_dict param.

the accuracy between "AttaCut" and "newmm".

Why the accuracy of "AttaCut" model more worse than "newmm" throgh PyThaiNLP in TNHC(Thai National Historical Corpus) dataset?
Is there any problem that needs my attention?
屏幕快照 2020-12-31 下午5 36 01
And, do you what's the meaning of "、#、$" in TNHC dataset?

What is the format of the input data?

I want to continue training attacut on my own data set, but I am not sure what the format of the data set should be?
截图
The data set link here is no longer valid, so I cannot view the format of the data set, can you help me?

Uplift version pin of nptying

I'm wondering that if there is any reason that the nptying dependency is pinned at <=0.3.1 while the latest version of nptying is 1.4.0?

Provide a way to make part of text not to be tokenized

I've been using attacut to process Thai chat corpus. The problem is many texts contain hyperlink, emoji, email addr, etc. I detect these entities and try to use placeholders to replace them before sending them to attacut hoping that attacut will leave them untoudhed. The placeholders I use are long english word string like "EMOJIPLACEHOLDER". It works for other tokenizers like deepcut, but attacut occasionly cut the placeholder into pieces: "EMO JIPLACEHOLDER".

So is there any way that I can tell attacut not to cut a string in a line of text?
Or any way to work around this problem?

Thanks.

เพิ่ม option `attacut-sc` และ `attacut-c` ใน engine เมื่อเรียก from pythainlp.tokenize import word_tokenize

Tokenizer(model = "attacut-sc").tokenize("วัดพระแก้วกรุงเทพ") และ word_tokenize("วัดพระแก้วกรุงเทพ", engine="attacut") ถึงได้ผลลัพธ์เป็น ["วัดพระแก้วกรุงเทพ"]

ในขณะที่ Tokenizer(model = "attacut-c").tokenize("วัดพระแก้วกรุงเทพ") ได้ผลลัพธ์เป็น ["วัดพระแก้ว", "กรุงเทพ"]

หากเพิ่มเติมรายละเอียดความแตกต่างระหว่าง attacut-sc และ attacut-c ในหน้าหลักของ https://thainlp.org/pythainlp/docs/2.0/api/tokenize.html จะดีมาก

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.