Developer Interface¶
word_tokenize¶
-
underthesea.
word_tokenize
(sentence, format=None, use_token_normalize=True)[source]¶ Vietnamese word segmentation
Parameters: Returns: word tokens
Return type: Examples
>>> # -*- coding: utf-8 -*- >>> from underthesea import word_tokenize >>> sentence = "Bác sĩ bây giờ có thể thản nhiên báo tin bệnh nhân bị ung thư"
>>> word_tokenize(sentence) ["Bác sĩ", "bây giờ", "có thể", "thản nhiên", "báo tin", "bệnh nhân", "bị", "ung thư"]
>>> word_tokenize(sentence, format="text") "Bác_sĩ bây_giờ có_thể thản_nhiên báo_tin bệnh_nhân bị ung_thư"
pos_tag¶
-
underthesea.
pos_tag
(sentence, format=None)[source]¶ Vietnamese POS tagging
Parameters: sentence ({unicode, str}) – Raw sentence Returns: tokens – tagged sentence Return type: list of tuple with word, pos tag Examples
>>> # -*- coding: utf-8 -*- >>> from underthesea import pos_tag >>> sentence = "Chợ thịt chó nổi tiếng ở TPHCM bị truy quét" >>> pos_tag(sentence) [('Chợ', 'N'), ('thịt', 'N'), ('chó', 'N'), ('nổi tiếng', 'A'), ('ở', 'E'), ('TPHCM', 'Np'), ('bị', 'V'), ('truy quét', 'V')]
chunking¶
-
underthesea.
chunk
(sentence, format=None)[source]¶ Vietnamese chunking
Parameters: sentence ({unicode, str}) – raw sentence Returns: tokens – tagged sentence Return type: list of tuple with word, pos tag, chunking tag Examples
>>> # -*- coding: utf-8 -*- >>> from underthesea import chunk >>> sentence = "Nghi vấn 4 thi thể Triều Tiên trôi dạt bờ biển Nhật Bản" >>> chunk(sentence) [('Nghi vấn', 'N', 'B-NP'), ('4', 'M', 'B-NP'), ('thi thể', 'N', 'B-NP'), ('Triều Tiên', 'Np', 'B-NP'), ('trôi dạt', 'V', 'B-VP'), ('bờ biển', 'N', 'B-NP'), ('Nhật Bản', 'Np', 'B-NP')]
ner¶
-
underthesea.
ner
(sentence, format=None)[source]¶ Location and classify named entities in text
Parameters: sentence ({unicode, str}) – raw sentence Returns: tokens – tagged sentence Return type: list of tuple with word, pos tag, chunking tag, ner tag Examples
>>> # -*- coding: utf-8 -*- >>> from underthesea import ner >>> sentence = "Ông Putin ca ngợi những thành tựu vĩ đại của Liên Xô" >>> ner(sentence) [('Ông', 'Nc', 'B-NP', 'O'), ('Putin', 'Np', 'B-NP', 'B-PER'), ('ca ngợi', 'V', 'B-VP', 'O'), ('những', 'L', 'B-NP', 'O'), ('thành tựu', 'N', 'B-NP', 'O'), ('vĩ đại', 'A', 'B-AP', 'O'), ('của', 'E', 'B-PP', 'O'), ('Liên Xô', 'Np', 'B-NP', 'B-LOC')]
classify¶
Install dependencies and download default model
$ pip install Cython
$ pip install future scipy numpy scikit-learn
$ pip install -U fasttext --no-cache-dir --no-deps --force-reinstall
$ underthesea data
sentiment¶
Install dependencies
$ pip install future scipy numpy scikit-learn==0.19.2 joblib
-
underthesea.
sentiment
(X, domain='general')[source]¶ Sentiment Analysis
Parameters: Returns: - Text (Text of input sentence)
- Labels (Sentiment of sentence)
Examples
>>> from underthesea import sentiment >>> sentence = "Chuyen tiền k nhận Dc tiên" >>> sentiment(sentence, domain='bank') [MONEY_TRANSFER#negative (1.0)]
viet2ipa¶
-
underthesea.pipeline.ipa.
viet2ipa
(text: str, *args, **kwargs)[source]¶ Generate ipa of the syllable
Vietnamese syllabic structure (Anh & Trang 2022)
syllable = onset + rhyme + tone
rhyme = medial + nuclear vowel + (coda)
Parameters: Returns: A string. Represents ipa of the syllable
Examples
>>> # -*- coding: utf-8 -*- >>> from underthesea.pipeline.ipa import viet2ipa >>> viet2ipa("trồng") tɕoŋ³²