Skip to main content

Vietnamese NLP Toolkit

Project description

Underthesea - Vietnamese NLP Toolkit

https://img.shields.io/pypi/v/underthesea.svg https://img.shields.io/pypi/pyversions/underthesea.svg https://img.shields.io/badge/license-GNU%20General%20Public%20License%20v3-brightgreen.svg https://img.shields.io/travis/undertheseanlp/underthesea.svg Documentation Status https://img.shields.io/badge/chat-on%20facebook-green.svg

https://raw.githubusercontent.com/undertheseanlp/underthesea/master/logo.jpg

underthesea is a suite of open source Python modules, data sets and tutorials supporting research and development in Vietnamese Natural Language Processing.

Free software

GNU General Public License v3

Live demo

undertheseanlp.com

Colab notebooks

latest / stable

Documentation

Underthesea Documentation

Facebook

Underthesea Page

Youtube

Underthesea NLP Channel

Installation

To install underthesea, simply:

$ pip install underthesea
✨🍰✨

Satisfaction, guaranteed.

Usage

1. Sentence Segmentation

https://img.shields.io/badge/F1-98%25-red.svg https://img.shields.io/badge/✎-custom%20models-blue.svg

Usage

>>> # -*- coding: utf-8 -*-
>>> from underthesea import sent_tokenize
>>> text = 'Taylor cho biết lúc đầu cô cảm thấy ngại với cô bạn thân Amanda nhưng rồi mọi thứ trôi qua nhanh chóng. Amanda cũng thoải mái với mối quan hệ này.'

>>> sent_tokenize(text)
[
    "Taylor cho biết lúc đầu cô cảm thấy ngại với cô bạn thân Amanda nhưng rồi mọi thứ trôi qua nhanh chóng.",
    "Amanda cũng thoải mái với mối quan hệ này."
]

2. Word Segmentation

https://img.shields.io/badge/F1-94%25-red.svg

Usage

>>> # -*- coding: utf-8 -*-
>>> from underthesea import word_tokenize
>>> sentence = 'Chàng trai 9X Quảng Trị khởi nghiệp từ nấm sò'

>>> word_tokenize(sentence)
['Chàng trai', '9X', 'Quảng Trị', 'khởi nghiệp', 'từ', 'nấm', 'sò']

>>> word_tokenize(sentence, format="text")
'Chàng_trai 9X Quảng_Trị khởi_nghiệp từ nấm sò'

3. POS Tagging

https://img.shields.io/badge/accuracy-92.3%25-red.svg

Usage

>>> # -*- coding: utf-8 -*-
>>> from underthesea import pos_tag
>>> pos_tag('Chợ thịt chó nổi tiếng ở Sài Gòn bị truy quét')
[('Chợ', 'N'),
 ('thịt', 'N'),
 ('chó', 'N'),
 ('nổi tiếng', 'A'),
 ('ở', 'E'),
 ('Sài Gòn', 'Np'),
 ('bị', 'V'),
 ('truy quét', 'V')]

4. Chunking

https://img.shields.io/badge/F1-77%25-red.svg

Usage

>>> # -*- coding: utf-8 -*-
>>> from underthesea import chunk
>>> text = 'Bác sĩ bây giờ có thể thản nhiên báo tin bệnh nhân bị ung thư?'
>>> chunk(text)
[('Bác sĩ', 'N', 'B-NP'),
 ('bây giờ', 'P', 'I-NP'),
 ('có thể', 'R', 'B-VP'),
 ('thản nhiên', 'V', 'I-VP'),
 ('báo tin', 'N', 'B-NP'),
 ('bệnh nhân', 'N', 'I-NP'),
 ('bị', 'V', 'B-VP'),
 ('ung thư', 'N', 'I-VP'),
 ('?', 'CH', 'O')]

5. Named Entity Recognition

https://img.shields.io/badge/F1-86.6%25-red.svg

Usage

>>> # -*- coding: utf-8 -*-
>>> from underthesea import ner
>>> text = 'Chưa tiết lộ lịch trình tới Việt Nam của Tổng thống Mỹ Donald Trump'
>>> ner(text)
[('Chưa', 'R', 'O', 'O'),
 ('tiết lộ', 'V', 'B-VP', 'O'),
 ('lịch trình', 'V', 'B-VP', 'O'),
 ('tới', 'E', 'B-PP', 'O'),
 ('Việt Nam', 'Np', 'B-NP', 'B-LOC'),
 ('của', 'E', 'B-PP', 'O'),
 ('Tổng thống', 'N', 'B-NP', 'O'),
 ('Mỹ', 'Np', 'B-NP', 'B-LOC'),
 ('Donald', 'Np', 'B-NP', 'B-PER'),
 ('Trump', 'Np', 'B-NP', 'I-PER')]

6. Text Classification

https://img.shields.io/badge/accuracy-86.7%25-red.svg

Download models

$ underthesea download-model TC_GENERAL
$ underthesea download-model TC_BANK

Usage

>>> # -*- coding: utf-8 -*-
>>> from underthesea import classify

>>> classify('HLV đầu tiên ở Premier League bị sa thải sau 4 vòng đấu')
['The thao']
>>> classify('Hội đồng tư vấn kinh doanh Asean vinh danh giải thưởng quốc tế')
['Kinh doanh']

>> classify('Lãi suất từ BIDV rất ưu đãi', domain='bank')
['INTEREST_RATE']

7. Sentiment Analysis

https://img.shields.io/badge/F1-59.5%25-red.svg

Download models

$ underthesea download-model SA_GENERAL
$ underthesea download-model SA_BANK

Usage

>>> # -*- coding: utf-8 -*-
>>> from underthesea import sentiment

>>> sentiment('hàng kém chất lg,chăn đắp lên dính lông lá khắp người. thất vọng')
negative
>>> sentiment('Sản phẩm hơi nhỏ so với tưởng tượng nhưng chất lượng tốt, đóng gói cẩn thận.')
positive

>>> sentiment('Đky qua đường link ở bài viết này từ thứ 6 mà giờ chưa thấy ai lhe hết', domain='bank')
['CUSTOMER_SUPPORT#negative']
>>> sentiment('Xem lại vẫn thấy xúc động và tự hào về BIDV của mình', domain='bank')
['TRADEMARK#positive']

8. Vietnamese NLP Resources

List resources

$ underthesea list-data
| Name         | Type        | License   |   Year | Directory             |
|--------------+-------------+-----------+--------+-----------------------|
| UTS2017-BANK | Categorized | Open      |   2017 | datasets/UTS2017-BANK |
| VNESES       | Plaintext   | Open      |   2012 | datasets/LTA          |
| VNTQ_BIG     | Plaintext   | Open      |   2012 | datasets/LTA          |
| VNTQ_SMALL   | Plaintext   | Open      |   2012 | datasets/LTA          |
| VNTC         | Categorized | Open      |   2007 | datasets/VNTC         |

$ underthesea list-data --all

Download resources

$ underthesea download-data VNTC
100%|██████████| 74846806/74846806 [00:09<00:00, 8243779.16B/s]
Resource VNTC is downloaded in ~/.underthesea/datasets/VNTC folder

Up Coming Features

  • Text to Speech

  • Automatic Speech Recognition

  • Machine Translation

  • Dependency Parsing

Contributing

Do you want to contribute with underthesea development? Great! Please read more details at CONTRIBUTING.rst.

History

Current

  • Thêm API xử lý dữ liệu (GH-299)

1.2.2 (2020-11-04)

  • Remove nltk strict version (GH-308)

  • Add word_hyphen rule (GH-290)

  • Sanity check python version (GH-320)

  • Handle exception case in sentiment module (GH-321)

  • Cập nhật quản lý resources từ languageflow (GH-295)

  • Loại bỏ languageflow trong quá trình cài đặt (GH-295)

  • Cập nhật phiên bản fasttext (GH-304)

1.1.16 (2019-06-15)

  • Bumping up version of the languageflow dependency (GH-231)

  • Update phiên bản scikit-learn 0.20.2 (GH-229)

  • Cập nhật lại các dependencies (GH-241)

  • Cập nhật mô hình trên bộ dữ liệu VNTC (GH-246)

  • Cập nhật mô hình trên bộ dữ liệu UTS2017_BANK_TC (GH-243)

  • Cập nhật mô hình trên bộ dữ liệu UTS2017_BANK_SA (GH-244)

  • Lỗi với các câu sentiment ở demo (GH-236)

  • Thống nhất cách đặt tên và quản lý model (GH-225)

1.1.12 (2019-03-13)

  • Add sentence segmentation feature

1.1.9 (2019-01-01)

  • Improve speed of word_tokenize function

  • Only support python 3.6+

  • Use flake8 for style guide enforcement

1.1.8 (2018-06-20)

  • Fix word_tokenize error when text contains tab (t) character

  • Fix regex_tokenize with url

1.1.7 (2018-04-12)

  • Rename word_sent function to word_tokenize

  • Refactor version control in setup.py file and __init__.py file

  • Update documentation badge url

1.1.6 (2017-12-26)

  • New feature: aspect sentiment analysis

  • Integrate with languageflow 1.1.6

  • Fix bug tokenize string with ‘=’ (#159)

1.1.5 (2017-10-12)

  • New feature: named entity recognition

  • Refactor and update model for word_sent, pos_tag, chunking

1.1.4 (2017-09-12)

  • New feature: text classification

  • [bug] Fix Text error

  • [doc] Add facebook link

1.1.3 (2017-08-30)

1.1.2 (2017-08-22)

  • Add dictionary

1.1.1 (2017-07-05)

  • Support Python 3

  • Refactor feature_engineering code

1.1.0 (2017-05-30)

  • Add chunking feature

  • Add pos_tag feature

  • Add word_sent feature, fix performance

  • Add Corpus class

  • Add Transformer classes

  • Integrated with dictionary of Ho Ngoc Duc

  • Add travis-CI, auto build with PyPI

1.0.0 (2017-03-01)

  • First release on PyPI.

  • First release on Readthedocs

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

underthesea-1.2.3a2.tar.gz (8.1 MB view hashes)

Uploaded Source

Built Distribution

underthesea-1.2.3a2-py3-none-any.whl (7.5 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page