Coder Social home page Coder Social logo

vunb / vntk Goto Github PK

View Code? Open in Web Editor NEW
213.0 22.0 61.0 3.65 MB

Vietnamese NLP Toolkit for Node

License: MIT License

JavaScript 97.32% HTML 2.68%
vietnamese-nlp vietnamese-tokenizer natural-language-processing vietnamese vietnamese-text-classification language-identification named-entity-recognition tf-idf pos-tagging

vntk's Introduction

VNTK

Vietnamese NLP Toolkit for Node

Join the chat at https://gitter.im/vntk/Lobby npm version npm downloads Travis Appveyor

Installation In A Nutshell

  1. Install Node.js
  2. Run: $ npm install vntk --save

If you are interested in contributing to vntk, or just hacking on it, then fork it away!

Jump to guide: How to build an NLP API Server using Vntk.

Documentation

CLI Utilities

1. Installation

Vntk cli will install nice and easy with:

npm install -g @vntk/cli

Then you need to pay attention to how to use these cli utilities to preprocess text from files, especially vietnamese that describe at the end of each apis usage. If you wish to improve the tool, please fork and make it better here.

2. Usage Example

After the CLI has installed, you need to open your Terminal (or Command Prompt on Windows) and type command you need to use.

For instance, the following command will open a file and process it by using Word Tokenizer to tokenize each lines in the file.

# Process a text file or a folder
$ vntk ws input.txt --output output.txt

# Output file will contain lines which have tokenized.

API Usage

1. Tokenizer

Regex Tokenizer using Regular Expression.
Tokenizer is provided to break text into arrays of tokens!

Example:

var vntk = require('vntk');
var tokenizer = vntk.tokenizer();

console.log(tokenizer.tokenize('Giá khuyến mãi: 140.000đ / kg  ==> giảm được 20%'))
// [ 'Giá', 'khuyến', 'mãi', ':', '140.000', 'đ', '/', 'kg', '==>', 'giảm', 'được', '20', '%' ]

console.log(tokenizer.stokenize('Giá khuyến mãi: 140.000đ / kg  ==> giảm được 20%'))
// Giá khuyến mãi : 140.000 đ / kg ==> giảm được 20 %

Command line: vntk tok <file_name.txt>

2. Word Segmentation

Vietnamese Word Segmentation using Conditional Random Fields, called: Word Tokenizer.
Word Tokenizer helps break text into arrays of words!

var vntk = require('vntk');
var tokenizer = vntk.wordTokenizer();

console.log(tokenizer.tag('Chào mừng các bạn trẻ tới thành phố Hà Nội'));
// [ 'Chào mừng', 'các', 'bạn', 'trẻ', 'tới', 'thành phố', 'Hà Nội' ]

Load custom trained model:

var vntk = require('vntk');
var tokenizer = vntk.wordTokenizer(new_model_path);

console.log(tokenizer.tag('Chào mừng các bạn trẻ tới thành phố Hà Nội', 'text'));
// Chào_mừng các bạn trẻ tới thành_phố Hà_Nội

Command line: vntk ws <file_name.txt>

3. POS Tagging

Vietnamese Part of Speech Tagging using Conditional Random Fields, called: posTag.
Pos_Tag helps labeling the part of speech of sentences!

var vntk = require('vntk');
var pos_tag = vntk.posTag();

console.log(pos_tag.tag('Chợ thịt chó nổi tiếng ở TP Hồ Chí Minh bị truy quét'))
// [ [ 'Chợ', 'N' ],
//   [ 'thịt', 'N' ],
//   [ 'chó', 'N' ],
//   [ 'nổi tiếng', 'A' ],
//   [ 'ở', 'E' ],
//   [ 'TP', 'N' ],
//   [ 'Hồ', 'Np' ],
//   [ 'Chí', 'Np' ],
//   [ 'Minh', 'Np' ],
//   [ 'bị', 'V' ],
//   [ 'truy quét', 'V' ] ]

Load custom trained model:

var vntk = require('vntk');
var pos_tag = vntk.posTag(new_model_path);

console.log(pos_tag.tag('Cán bộ xã và những chiêu "xin làm hộ nghèo" cười ra nước mắt', 'text'))
// [N Cán bộ] [N xã] [C và] [L những] [N chiêu] [CH "] [V xin] [V làm] [N hộ] [A nghèo] [CH "] [V cười] [V ra] [N nước mắt]

Command line: vntk pos <file_name.txt>

4. Chunking

Vietnamese Chunking using Conditional Random Fields
Chucking helps labeling the part of speech of sentences and short phrases (like noun phrases)!

var vntk = require('vntk');
var chunking = vntk.chunking();

console.log(chunking.tag('Nhật ký SEA Games ngày 21/8: Ánh Viên thắng giòn giã ở vòng loại.'))
// [ [ 'Nhật ký', 'N', 'B-NP' ],
//   [ 'SEA', 'N', 'B-NP' ],
//   [ 'Games', 'Np', 'B-NP' ],
//   [ 'ngày', 'N', 'B-NP' ],
//   [ '21/8', 'M', 'B-NP' ],
//   [ ':', 'CH', 'O' ],
//   [ 'Ánh', 'Np', 'B-NP' ],
//   [ 'Viên', 'Np', 'I-NP' ],
//   [ 'thắng', 'V', 'B-VP' ],
//   [ 'giòn giã', 'N', 'B-NP' ],
//   [ 'ở', 'E', 'B-PP' ],
//   [ 'vòng', 'N', 'B-NP' ],
//   [ 'loại', 'N', 'B-NP' ],
//   [ '.', 'CH', 'O' ] ]

Load custom trained model:

var vntk = require('vntk');
var chunking = vntk.chunking(new_model_path);

console.log(chunking.tag('Nhật ký SEA Games ngày 21/8: Ánh Viên thắng giòn giã ở vòng loại.', 'text'));
// [NP Nhật ký] [NP SEA] [NP Games] [NP ngày] [NP 21/8] : [NP Ánh Viên] [VP thắng] [NP giòn giã] [PP ở] [NP vòng] [NP loại] .

Command line: vntk chunk <file_name.txt>

5. Named Entity Recognition

Vietnamese Named Entity Recognition (NER) using Conditional Random Fields
In NER, your goal is to find named entities, which tend to be noun phrases (though aren't always)

var vntk = require('vntk');
var ner = vntk.ner();

console.log(ner.tag('Chưa tiết lộ lịch trình tới Việt Nam của Tổng thống Mỹ Donald Trump'))
// [ [ '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' ] ]

Load custom trained model:

var vntk = require('vntk');
var ner = vntk.ner(new_model_path);

console.log(ner.tag('Chưa tiết lộ lịch trình tới Việt Nam của Tổng thống Mỹ Donald Trump', 'text'))
// Chưa  tiết lộ  lịch trình  tới [LOC Việt Nam] của  Tổng thống [LOC Mỹ] [PER Donald Trump]

Command line: vntk ner <file_name.txt>

6. Utility

Dictionary

  • Check a word is exists in dictionary
var vntk = require('vntk');
var dictionary = vntk.dictionary();

dictionary.has('chào');
// true
  • Lookup word definitons
var vntk = require('vntk');
var dictionary = vntk.dictionary();

var senses = dictionary.lookup('chào');
console.log(senses);

// Output
[ { example: 'chào thầy giáo ~ con chào mẹ',
    sub_pos: 'Vt',
    definition: 'tỏ thái độ kính trọng hoặc quan tâm đối với ai bằng lời nói hay cử chỉ, khi gặp nhau hoặc khi từ biệt',
    pos: 'V' },
    { example: 'đứng nghiêm làm lễ chào cờ',
    sub_pos: 'Vu',
    definition: 'tỏ thái độ kính cẩn trước cái gì thiêng liêng, cao quý',
    pos: 'V' },
    { example: 'chào hàng ~ lời chào cao hơn mâm cỗ (tng)',
    sub_pos: 'Vu',
    definition: 'mời ăn uống hoặc mua hàng',
    pos: 'V' }]

Clean html

var vntk = require('vntk');
var util = vntk.util();

util.clean_html('<span style="color: #4b67a1;">Xin chào!!!</span>');
// Xin chào!!!
# command line
vntk clean <file_name1.txt>

7. TF-IDF

Term Frequency–Inverse Document Frequency (tf-idf) is implemented to determine how important a word (or words) is to a document relative to a corpus. See following example.

var vntk = require('vntk');
var tfidf = new vntk.TfIdf();

tfidf.addDocument('Đại tướng Trần Đại Quang - Ủy viên Bộ Chính trị, Bí thư Đảng ủy Công an Trung ương, Bộ trưởng Bộ Công an.');
tfidf.addDocument('Thượng tướng Tô Lâm - Ủy viên Bộ Chính trị - Thứ trưởng Bộ Công an.');
tfidf.addDocument('Thượng tướng Lê Quý Vương - Ủy viên Trung ương Đảng - Thứ trưởng Bộ Công an.');
tfidf.addDocument('Thiếu tướng Bùi Mậu Quân - Phó Tổng cục trưởng Tổng cục An ninh');

console.log('Bộ Công an --------------------------------');
tfidf.tfidfs('Bộ Công an', function(i, measure) {
    console.log('document #' + i + ' is ' + measure);
});

console.log('Tổng cục An ninh --------------------------------');
tfidf.tfidfs('Tổng cục An ninh', function(i, measure) {
    console.log('document #' + i + ' is ' + measure);
});

The above output:

Bộ Công an --------------------------------
document #0 is 6.553712897371581
document #1 is 3.7768564486857903
document #2 is 2.7768564486857903
document #3 is 0.7768564486857903
Tổng cục An ninh --------------------------
document #0 is 1.5537128973715806
document #1 is 0.7768564486857903
document #2 is 0.7768564486857903
document #3 is 9.242592351485516

8. Classifiers

Naive Bayes, fastText are classifiers currently supported.

Bayes Classifier

The following examples use the BayesClassifier class:

var vntk = require('vntk');

var classifier = new vntk.BayesClassifier();

classifier.addDocument('khi nào trận chiến đã kết thúc?', 'when');
classifier.addDocument('tàu rời đi lúc mấy giờ?', 'when');
classifier.addDocument('trận đấu diễn ra vào thời gian nào?', 'when');
classifier.addDocument('anh ấy rời đi vào lúc mấy giờ?', 'when');
classifier.addDocument('bao giờ thì đến lễ hội hóa trang?', 'when');
classifier.addDocument('ai phát hiện ra điện ?', 'who');
classifier.addDocument('người sáng lập ra microsoft là ai?', 'who');
classifier.addDocument('ai kiếm được tiền của họ một cách chăm chỉ ?', 'who');
classifier.addDocument('người phát minh tạo ra.', 'who');
classifier.addDocument('gia đình bạn gồm những ai?', 'who');

classifier.train();


console.log(classifier.classify('chiến tranh thế giới bắt đầu vào lúc nào?'));
// output: when

console.log(classifier.classify('kẻ thù của luffy là ai?'));
// output: who

FastText Classifier

According to fasttext.cc. We have a simple classifier for executing prediction models about cooking from stackexchange questions:

const path = require('path');
const vntk = require('vntk');

const model = path.resolve(__dirname, './model_cooking.bin');
const classifier = new vntk.FastTextClassifier(model);

classifier.predict('Why not put knives in the dishwasher?', 5, (err, res) => {
    if (err) {
        console.error(err);
    } else if (res.length > 0) {
        let tag = res[0].label; // __label__knives
        let confidence = res[0].value // 0.8787146210670471
        console.log('classify', tag, confidence, res);
    } else {
        console.log('No matches');
    }
});

9. Language identification

VNTK Langid can identify 176 languages from text samples and return confidence scores for each (see the list of ISO codes below). This model was trained by fastText on data from Wikipedia, Tatoeba and SETimes, used under CC-BY-SA.

Api usage example:

  • langid.detect([input])
  • langid.getLanguages([input, num, callback])
  • langid.langids - list of supported languages
const langid = require('vntk').langid();

// returns the most accuracy language detected
langid.detect('sử dụng vntk với fastext rất tuyệt?')
    .then((lid) => {
        console.log(lid)
        // vi
    });

// returns the list of detectable languages
langid.getLanguages('Wie lange bleiben Sie?', 5)
    .then((res) => {
        let lid = res[0].label;
        t.equal(lid, 'de', 'German');
        t.equal(res.length, 5, 'number of languagues are detected');
        console.log(res)
    });

// returns list of supported languagues
console.log(langid.langids)

Load custom trained model:

var vntk = require('vntk');
var langid = vntk.langid(new_model_path);

List of supported languages

af als am an ar arz as ast av az azb ba bar bcl be bg bh bn bo bpy br bs bxr ca cbk ce ceb ckb co cs cv cy da de diq dsb dty dv el eml en eo es et eu fa fi fr frr fy ga gd gl gn gom gu gv he hi hif hr hsb ht hu hy ia id ie ilo io is it ja jbo jv ka kk km kn ko krc ku kv kw ky la lb lez li lmo lo lrc lt lv mai mg mhr min mk ml mn mr mrj ms mt mwl my myv mzn nah nap nds ne new nl nn no oc or os pa pam pfl pl pms pnb ps pt qu rm ro ru rue sa sah sc scn sco sd sh si sk sl so sq sr su sv sw ta te tg th tk tl tr tt tyv ug uk ur uz vec vep vi vls vo wa war wuu xal xmf yi yo yue zh

10. CRFSuite

For quick access to CRFSuite which shipped with vntk we can refer to it via following api.

var crfsuite = require('vntk').crfsuite()

Then create a Tagger or Trainer:

var crfsuite = require('vntk').crfsuite()
var tagger = new crfsuite.Tagger()
var trainer = new crfsuite.Trainer()

For detail documentation, click here.

NLP API Server

Follow these steps to quickly serve an NLP API server using vntk:

# Clone the repository
git clone https://github.com/vunb/vntk

# Move to source code folder
cd vntk

# Install dependencies
npm install

# Run NLP API server
npm run server

# Copy and paste the following link to your browser to see result in action
# http://localhost:3000/api/tok/Phó Thủ tướng Vương Đình Huệ yêu cầu điều chỉnh tên gọi “trạm thu giá” BOT

Detail checkout: ./server

Contributing

Pull requests and stars are highly welcome.

For bugs and feature requests, please create an issue.

LICENSE

MIT.

vntk's People

Contributors

daomtthuan avatar drenvir avatar vunb 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vntk's Issues

vntk not support linux

i installed vntk on linux, but not support
error: node_modules/crfsuite/lib/binding/crfsuite.node: invalid ELF header

Lỗi khi settup server api

TypeError: engine is not a function
at Object. (/Users/TrieuVu/vntk/server/app.js:5:1)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:236:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:560:3)

Nhờ anh chỉ em fix với nhé !

Bổ sung tiện ích phát hiện câu tiếng Việt

Người dùng có thể sử dụng lệnh sau để bóc tách, phát hiện câu (sentence detector) trong 1 file tiếng Việt.

Xử lý input là một chuỗi

$ vntk sd [text]

Xử lý input là một tệp tin

$ vntk sd -f demo.txt another.txt
$ //Output: demo.txt.sd, another.txt.sd

Xử lý như một thư viện

var vntk = require("vntk");

vntk.sd("text");

Tóm tắt văn bản Tiếng Việt tự động - Text Summarization

Ví dụ 1: Để đọc được nhiều, nắm bắt tin tức nhanh và tránh bội thực thông tin, mình có thể đọc tóm tắt từ bài viết, bài báo thay vì đọc hết.

Ví dụ 2: User yêu cầu thông tin về bệnh Nhức đầu, mình không thể bê nguyên bài báo vào chat bot, nhưng mình có thể tổng hợp vài bài báo ở tóm tắt cho user xem nhanh. Sau khi user xem tóm tắt, user có thể chọn bài nào thích hợp nhất.

Tham khảo code: https://rare-technologies.com/text-summarization-in-python-extractive-vs-abstractive-techniques-revisited/

Bổ sung dữ liệu: https://github.com/lupanh/VietnameseMDS
Mô tả: 200 Cụm văn bản tiếng Việt dùng cho tóm tắt đa văn bản

Bổ sung ROUGE, thuật toán dùng để đánh giá Văn bản được tóm tắt.
http://text-analytics101.rxnlp.com/2017/01/how-rouge-works-for-evaluation-of.html

Thêm javascript code để tham khảo: https://github.com/hvlcrs/textrank-node

NER output

I want to ask about where can the type and meaning of the fourth column of the output be found?

Cài đặt và sử dụng trên giao diện dòng lệnh

Cài đặt vntk sử dụng npm:

npm install -g vntk

Sau đó, chạy một tiện ích trong vntk, ví dụ cho bài toán tách từ tiếng Việt (word segmentation) như sau:

Xử lý input là một chuỗi

Input: vntk ws "Chào mừng bạn đến với đất nước Việt Nam"
Output: Chào_mừng bạn đến với đất_nước Việt_Nam

Xử lý input là một tệp tin

Input: vntk ws -f demo.txt another.txt
Output: demo.txt.seg, another.txt.seg

Xử lý như một thư viện

var vntk = require("vntk");

vntk.ws("Chào mừng bạn đến với đất nước Việt Nam");
// Output: Chào_mừng bạn đến với đất_nước Việt_Nam

cli tool

The CLI currently does not work.

The list of cli tools need to update:

  • Tokenizer: vntk tok <file_name.txt> - convert lines of text to lines of tokens
  • Word segmentation: vntk ws <file_name.txt> - convert lines of text to lines of vietnamese words
  • Post tagging: vntk pos <file_name.txt>
  • Chunking: vntk chunk <file_name.txt>
  • NER: vntk ner <file_name.txt>

invalid ELF header

Hi Team,

Good Library in Node. Its working fine in my local machine windows 10.

But when i tried to deploy in centos 7 server am facing the issue of invalid ELF header

Please let me know the solution for this.

Capture

can not run vntk function (tag) in parallel.

Thank you for this module, it helped me so much for my work. But there have a problem with me, I can not run multi vntk.workTokenizer().tag at the same time (Promise.all). I tried to use promisify on the function but it did not work for me. Please give me a solution about it...

lỗi không install được

`Last login: Sun Jul 29 21:46:46 on ttys002
LDragons-MacBook-Pro:~ Ldragon$ npm install -g vntk

[email protected] preinstall /Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/fasttext
npm install node-pre-gyp

/Users/Ldragon/.npm-global/bin/node-pre-gyp -> /Users/Ldragon/.npm-global/lib/node_modules/node-pre-gyp/bin/node-pre-gyp

[email protected] preinstall /Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite
npm install node-pre-gyp

/Users/Ldragon/.npm-global/bin/node-pre-gyp -> /Users/Ldragon/.npm-global/lib/node_modules/node-pre-gyp/bin/node-pre-gyp

  • [email protected]
    updated 1 package in 1.503s
    /Users/Ldragon/.npm-global/bin/vntk -> /Users/Ldragon/.npm-global/lib/node_modules/vntk/bin/vntk.js

[email protected] postinstall /Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite
node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! Tried to download(404): https://github.com/vunb/node-crfsuite/releases/download/0.9.4/crfsuite-v0.9.4-node-v64-darwin-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v64 ABI, unknown) (falling back to source compile with node-gyp)
node-pre-gyp ERR! Tried to download(undefined): https://github.com/vunb/node-crfsuite/releases/download/0.9.4/crfsuite-v0.9.4-node-v64-darwin-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v64 ABI, unknown) (falling back to source compile with node-gyp)
CC(target) Release/obj.target/crfsuite/liblbfgs/lib/lbfgs.o
CC(target) Release/obj.target/crfsuite/liblbfgs/lib/lbfgs.o
rm: ./Release/.deps/Release/obj.target/crfsuite/liblbfgs/lib/lbfgs.o.d.raw: No such file or directory
make: *** [Release/obj.target/crfsuite/liblbfgs/lib/lbfgs.o] Error 1
gyp ERR! CC(target) Release/obj.target/crfsuite/crfsuite/lib/crf/src/crf1d_context.o
build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite/lib/binding/crfsuite.node" "--module_name=crfsuite" "--module_path=/Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite/lib/binding"
gyp ERR! cwd /Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite
gyp ERR! node -v v10.7.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite/lib/binding/crfsuite.node --module_name=crfsuite --module_path=/Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite/lib/binding' (1)
node-pre-gyp ERR! stack at ChildProcess. (/Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:182:13)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:961:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
node-pre-gyp ERR! System Darwin 17.7.0
node-pre-gyp ERR! command "/usr/local/bin/node" "/Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite
node-pre-gyp ERR! node -v v10.7.0
node-pre-gyp ERR! node-pre-gyp -v v0.6.39
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite/lib/binding/crfsuite.node --module_name=crfsuite --module_path=/Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite/lib/binding' (1)
../crfsuite/lib/crf/src/crf1d_context.c:71:17: warning: using the result of an assignment as a condition without parentheses
[-Wparentheses]
if (ret = crf1dc_set_num_items(ctx, T)) {
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../crfsuite/lib/crf/src/crf1d_context.c:71:17: note: place parentheses around the assignment to silence this warning
if (ret = crf1dc_set_num_items(ctx, T)) {
^
( )
../crfsuite/lib/crf/src/crf1d_context.c:71:17: note: use '==' to turn this assignment into an equality comparison
if (ret = crf1dc_set_num_items(ctx, T)) {
^
==
../crfsuite/lib/crf/src/crf1d_context.c:440:15: warning: unused variable 'L' [-Wunused-variable]
const int L = ctx->num_labels;
^
../crfsuite/lib/crf/src/crf1d_context.c:438:38: warning: unused variable 'cur' [-Wunused-variable]
const floatval_t *state = NULL, *cur = NULL, *trans = NULL;
^
3 warnings generated.⠙ postinstall: info lifecycle [email protected]~postinstall: Failed to exec postinstall script
make: *** No rule to make target ../crfsuite/lib/crf/src/crf1d_encode.c', needed by Release/obj.target/crfsuite/crfsuite/lib/crf/src/crf1d_encode.o'. Stop.
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite/lib/binding/crfsuite.node" "--module_name=crfsuite" "--module_path=/Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite/lib/binding"
gyp ERR! cwd /Users/Ldragon/.npm-global/lib/node_modules/vntk/node_modules/crfsuite
gyp ERR! node -v v10.7.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: node-pre-gyp install --fallback-to-build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Ldragon/.npm/_logs/2018-07-29T15_52_38_147Z-debug.log
LDragons-MacBook-Pro:~ Ldragon$ `

Print output as text format

Please add option to print output as text format.

For example:

Input: Nhật ký SEA Games ngày 21/8: Ánh Viên thắng giòn giã ở vòng loại.

Output:

// POST Tagging
console.log(pos_tag.tag('Nhật ký SEA Games ngày 21/8: Ánh Viên thắng giòn giã ở vòng loại.', 'text'))
'N/Nhật_ký Np/SEA_Games N/ngày M/21/8 CH/: Np/Ánh_Viên V/thắng A/giòn_giã E/ở N/vòng_loại CH/.'

// Chunking
console.log(chunking.tag('Nhật ký SEA Games ngày 21/8: Ánh Viên thắng giòn giã ở vòng loại.', 'text'))
'[NP Nhật_ký SEA_Games] [NP ngày 21/8] : [NP Ánh_Viên] [VP thắng giòn_giã] [PP ở] [NP vòng_loại] .'

// Named Entity Recognition
console.log(ner.tag('Nhật ký SEA Games ngày 21/8: Ánh Viên thắng giòn giã ở vòng loại.', 'text'))
'Nhật_ký SEA_Games ngày 21/8 : [PER Ánh_Viên] thắng giòn_giã ở vòng_loại .'

Crawl dữ liệu từ FB sử dụng graph API

GraphAPI trên facebook cho phép lấy dữ liệu theo định dạng json.
image
Tuy nhiên input đầu vào của chương trình chatbot cần là những đoạn hội thoại liền kế nhau.
Input.txt:
"Đừng lo em ơi. Đi học hay k k còn quan trọng nữa. Đơn giản chỉ là cái "tha thu" mà sơn tùng vẽ lên thôi"
"Không hiểu sao nói từ bà già với mẹ mình éo nói được chứ =-= mà nhiều đứa nói hồn nhiên vãi"

=> mục tiêu: viết 1 tool bằng java/php sử dụng SDK facebook cho phép crawl dữ liệu từ 1 trang fb (lấy comment) và lưu vào file input.txt

Lỗi cài vntk-master

Dear bạn!
Hiện tại mình download module vntk-master và sau đó chạy npm install để cài đặt các module còn thiếu
tuy nhiên khi cài lệnh xong đang báo lỗi
"node-pre-gyp ERR! Tried to download(404): https://github.com/vunb/node-crfsuite/releases/download/0.9.3/crfsuite-v0.9.3-node-v59-win32-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v59 ABI) (falling back to source compile with node-gyp)"

qua kiểm tra link https://github.com/vunb/node-crfsuite/releases/download/0.9.3/crfsuite-v0.9.3-node-v59-win32-x64.tar.gz thì không tồn tại.

Bạn kiểm tra lại nhé.

load custom model

Please open vntk to have ability load custom model for word_sent, chunking, ner.

For example:

var tagger = new vntk.NER([model_filename]);
tagger.tag('text input');

Run vntk as a NLP API service

Create a node server to serve NLP service using vntk

Assume:

  • npm run server
  • docker-compose build && docker-compose up -d

Bổ sung tiện ích làm sạch dữ liệu

Làm sạch dữ liệu bao gồm:

  • Xóa khoảng trắng
  • Xóa câu trùng lặp liên tiếp nhau (flag: -d: delete duplicated)
  • Xóa các thẻ html, ký tự đặc biệt, ký tự điều khiển

Tóm tắt - và phân tích

Put another way, investors are more volatile than investments. Economic reality governs the returns earned by our businesses, and Black Swans are unlikely. But emotions and perceptions—the swings of hope, greed, and fear among the participants in our financial system—govern the returns earned in our markets. Emotional factors magnify or minimize this central core of economic reality, and Black Swans can appear at any time. —John C. Bogle, founder of The Vanguard Group8 Modern Portfolio Theory (MPT), like all theories, has been subject to much criticism. Most of that criticism is focused either on the failings of the theory’s fundamental assumptions, or in the way the theory and its assumptions have been applied. Ultimately, it has been accused of failing to predict the major financial crises of our time, like Black Monday in 1987, the credit crisis in the U.S. in 2008, or the current financial crisis over sovereign debt in Europe. Criticisms of Modern Portfolio Theory Modern portfolio theory was the creation of Harry Markowitz in which he applied principles of linear programming to the creation of asset portfolios. Markowitz demonstrated that an investor could reduce the standard deviation of portfolio returns by combining assets that were less than perfectly correlated in their returns. The theory assumes that all investors have access to the same information at the same point in time. It assumes all investors are rational and risk averse, and will take on additional risk only if compensated by higher expected returns. It assumes all investors are similarly rational, although different investors will have different trade-offs between risk and return based on their own risk aversion characteristics. The usual measure of risk used in portfolio theory is the standard deviation of returns, assuming a normal distribution of returns over time. As one would expect, the criticisms of portfolio theory are pointed at each and every assumption behind the theory. For example, the field of behavioral economics argues that investors are not necessarily rational—that in some cases, gamblers buy risk. All investors do not have access to the same information, that insider trading persists, that some investors are biased, that some investors regularly beat the market through market timing. Even the mathematics comes under attack, as to whether standard deviations are the appropriate measure of risk to minimize, or whether the standard normal distribution is appropriate. Many of the major stock market collapses in recent history, like that of Black Monday’s crash on October 19, 1987, when the Dow fell 23%, were “missed” by the purveyors of portfolio strategy. Statistical studies of markets and their returns over time often show returns that are not normally distributed, but are subject to greater deviation from the mean than traditional normal distributions—evidence of so-called fat tails. Much of the work of Benoit Mandelbrot, the father of fractal geometry, revolved around the possibility that financial markets exhibited fat tail distributions. Mandelbrot’s analysis in fact showed that the Black Monday event was a 20-sigma event, one which, according to normal distributions (bell curve or Gaussian model), was so improbable as not likely to ever occur.10 And if something has not happened in the past, portfolio theory assumes it cannot happen in the future. Yet it did.The argument and criticism that has been deployed with the greatest traction seems to be that portfolio theory is typically executed using historical data—the numbers from the past—assuming a distribution that the data does not fit. Any attempts to refine the tools of modern portfolio theory by relaxing the bell curve assumptions, or by “fudging” and adding the occasional “jumps” will not be sufficient. We live in a world primarily driven by random jumps, and tools designed for random walks address the wrong problem. It would be like tinkering with models of gases in an attempt to characterise them as solids and call them “a good approximation”. Black Swan Theory Nassim Nicholas Taleb published a book in 2001 entitled Fooled by Randomness in which he introduced the analogy of the black swan.12 The argument is quite simple: prior to the discovery of Australia and the existence of black swans, all swans were thought to be white. Black swans did not exist because no one had ever seen one. But that did not mean they did not exist. Taleb then applied this premise to financial markets, arguing that simply because a specific event had never occurred did not mean it couldn’t. Taleb argued that a black swan event is characterized by three fundamentals, in order, Rarity, Extremeness, and Retrospective Predictability: 1. Rarity: The event is a shock or surprise to the observer. 2. Extremeness: The event has a major impact. 3. Retrospective Predictability: After the event has occurred, the event is rationalized by hindsight, and found to have been predictable. Although the third argument is a characteristic of human intellectual nature, it is the first element that is fundamental to the debate. If an event has not been recorded, does that mean it cannot occur? Portfolio theory is a mathematical analysis of provided inputs. Its outcomes are no better than its inputs. The theory itself does not predict price movements. It simply allows the identification of portfolios in which the risk is at a minimum for an expected level of return. Taleb does not argue that he has some secret ability to predict the future when historical data cannot. Rather, he argues that investors should structure their portfolios, their investments, to protect against the extremes, the improbable events rather than the probable ones. He argues for what many call “investment humility,” to acknowledge that the world we live in is not always the one we think we live in, and to understand how much we will never understand. What Drives the Improbable? So what causes the “random jumps” noted by Mandelbrot and Taleb? A number of investment theorists, including John Maynard Keynes and John Bogle, have argued over the past century that equity returns are driven by two fundamental forces, enterprise (economic or business returns over time) and speculation (the psychology or emotions of the individuals in the market). First Keynes and then Bogle eventually concluded that speculation would win out over enterprise, very much akin to arguing that hope will win out over logic. This is what Bogle means in the opening quotation when he states that “investors are more volatile than investments.” All agree that the behavior of the speculators (in the words of Keynes) or the jumps of market returns (in the words of Mandelbrot) are largely unpredictable. And all that one can do is try and protect against the unpredictable by building more robust systems and portfolios than can hopefully with stand the improbable. But most also agree that the “jumps” are exceedingly rare, and depending upon the holding period, the market may return to more fundamental values, if given the time. But the event does indeed have a lasting impact. Portfolio theory remains a valuable tool. It allows investors to gain approximate values over the risk and expected returns they are likely to see in their total positions. But it is fraught with failings, although it is not at all clear what would be better. Even some of history’s greatest market timers have noted that they have followed modern portfolio theory, but have used subjective inputs on what is to be expected in the future. Even Harry Markowitz—on the last page of the same article that started it all, Portfolio Selection—noted that “. . . in the selection of securities we must have procedures for finding reasonable pi and oij. These procedures, I believe, should combine statistical techniques and the judgment of practical men.” But the judgement of practical men is—well—difficult to validate. We need predictions of what may come, even if it is generally based on the past. Kenneth Arrow, a famed economist and Nobel Prize winner relayed the following story of how during the World War II a group of statisticians were tasked with forecasting weather patterns. The statisticians subjected these forecasts to verification and found they differed in no way from chance. The forecasters themselves were convinced and requested that the forecasts be discontinued. The reply read approximately like this: “The Commanding General is well aware that the forecasts are no good. However, he needs them for planning purposes.” Taleb, in a recent edition of Black Swan Theory, notes that the event is a surprise to the specific observer, and that what is a surprise to the turkey is not a surprise to the butcher. The challenge is “to avoid being the turkey.”

Chuyển thời gian ở dạng nói/viết sang Unix timestamp và ngược lại

Vấn đề: Đặt hàng hay nhắc nhở.

Đặt hàng:
Máy -> Người
Giả sử lúc này là 16:00 03/02/2018, Mark mua hàng tủ lạnh. Nếu vào ngày 05/02/2017 Amazon giao hàng, thì trả về là 2 (Hai) ngày nữa chúng tôi sẽ giao hàng.

Nhắc nhỏ:
Người -> Máy:
Này chatbot, nhắc tao có việc cần làm lúc 6 giờ ngày mai. Hay chủ nhật này nhắc tao đi sinh nhật vợ lẽ của sếp. Thì chatbot lưu thời gian ở dạng Unix timestamp để dễ tính.

Error: EPERM: operation not permitted, rename

Install dependency vunb/node-crfsuite got following error:

npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "i" "crfsuite" "--save"
npm ERR! node v6.9.0
npm ERR! npm  v4.0.0
npm ERR! path D:\node\github\vntk\vntk\node_modules\crfsuite
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall rename

npm ERR! Error: EPERM: operation not permitted, rename 'D:\node\github\vntk\vntk\node_modules\crfsuite' -> 'D:\node\github\vntk\vntk\node_modules\.crfsuite.DELETE'
npm ERR!     at moveAway (C:\Users\nhuba\AppData\Roaming\nvm\v6.9.0\node_modules\npm\lib\install\action\finalize.js:38:5)
npm ERR!     at destStatted (C:\Users\nhuba\AppData\Roaming\nvm\v6.9.0\node_modules\npm\lib\install\action\finalize.js:27:7)
npm ERR!     at C:\Users\nhuba\AppData\Roaming\nvm\v6.9.0\node_modules\npm\node_modules\graceful-fs\polyfills.js:267:18
npm ERR!     at FSReqWrap.oncomplete (fs.js:123:15)
npm ERR!
npm ERR! Error: EPERM: operation not permitted, rename 'D:\node\github\vntk\vntk\node_modules\crfsuite' -> 'D:\node\github\vntk\vntk\node_modules\.crfsuite.DELETE'
npm ERR!     at Error (native)
npm ERR!  { Error: EPERM: operation not permitted, rename 'D:\node\github\vntk\vntk\node_modules\crfsuite' -> 'D:\node\github\vntk\vntk\node_modules\.crfsuite.DELETE'
npm ERR!     at moveAway (C:\Users\nhuba\AppData\Roaming\nvm\v6.9.0\node_modules\npm\lib\install\action\finalize.js:38:5)
npm ERR!     at destStatted (C:\Users\nhuba\AppData\Roaming\nvm\v6.9.0\node_modules\npm\lib\install\action\finalize.js:27:7)
npm ERR!     at C:\Users\nhuba\AppData\Roaming\nvm\v6.9.0\node_modules\npm\node_modules\graceful-fs\polyfills.js:267:18
npm ERR!     at FSReqWrap.oncomplete (fs.js:123:15)
npm ERR!
npm ERR! Error: EPERM: operation not permitted, rename 'D:\node\github\vntk\vntk\node_modules\crfsuite' -> 'D:\node\github\vntk\vntk\node_modules\.crfsuite.DELETE'
npm ERR!     at Error (native) parent: 'vntk' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     D:\node\github\vntk\vntk\npm-debug.log

QA

var vntk = require('vntk');
var tfidf = new vntk.TfIdf();

tfidf.addDocument('1 Đại tướng Trần Đại Quang - Ủy viên Bộ Chính trị, Bí thư Đảng ủy Công an Trung ương, Bộ trưởng Bộ Công an.');
tfidf.addDocument('2 Đại tướng Trần Đại Quang - Ủy viên Bộ Chính trị, Bí thư Đảng ủy Công an Trung ương, Bộ trưởng Bộ Công an.');
tfidf.addDocument('3 Đại tướng Trần Đại Quang - Ủy viên Bộ Chính trị, Bí thư Đảng ủy Công an Trung ương, Bộ trưởng Bộ Công an.');
tfidf.addDocument('4 Đại tướng Trần Đại Quang - Ủy viên Bộ Chính trị, Bí thư Đảng ủy Công an Trung ương, Bộ trưởng Bộ Công an.');

tfidf.tfidfs('4 Đại tướng Trần Đại Quang - Ủy viên Bộ Chính trị, Bí thư Đảng ủy Công an Trung ương, Bộ trưởng Bộ Công an.', function(i, measure) {
console.log('document #' + i + ' is ' + measure);
});

document #0 is 28.743688601374252
document #1 is 28.743688601374252
document #2 is 28.743688601374252
document #3 is 28.743688601374252

xác suất này chưa xử lý với number

Bổ sung các bài toán cơ bản của xử lý tiếng Việt

Các tính năng, công việc cần thực hiện:

  • Từ điển tiếng Việt 74K từ
  • Tích hợp sử dụng các models đã được huấn luyện từ bộ nguồn mở @underthesea
  • Tách từ Word Segmentation
  • Gán nhãn từ loại POS Tagging
  • Xác định cụm từ Chunking
  • Nhận dạng thực thể có tên Named Entity Recognition
  • Phân lớp văn bản Text Classification

Bổ sung bộ từ điển tiếng Việt

Cần có 1 bộ từ điển tiếng Việt để phục vụ mục đích

  • Kiểm tra từ đó có trong tiếng Việt không ?
  • Loại bỏ các hư từ, từ không có ý nghĩa
  • Tra cứu ý nghĩa của 1 từ

CÀI ĐẶT BỊ LỖI

Em xin chào,
Em không biết tẹo nào về code cả chỉ vô tình rơi vào hoàn cảnh phải phân tích nlp tiếng việt.
Em mới cài đặt cái này nhưng bị lỗi, cho em hỏi: "Có phải vntk này chỉ chạy trên linux ko ạ? Vì em đang sài window k muốn dùng linux"
Em mong được các cao thủ giải đáp giúp.
Em cảm ơn ạ.

Public an api which exports and allows to use CRFsuite

Wanted an api which exports / allows to use CRFsuite from module vntk as an utility.

Example: var crfsuite = require('vntk').crfsuite()

Then create a Tagger or Trainer:

var crfsuite = require('vntk').crfsuite()
var tagger = new crfsuite.Tagger()
var trainer = new crfsuite.Trainer()

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.