GithubHelp home page GithubHelp logo

hhy5277 / bert_chinesewordsegment Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fendouai/bert_chinesewordsegment

0.0 2.0 0.0 2.89 MB

A Chinese word segment model based on BERT, F1-Score 97%

License: Apache License 2.0

Python 100.00%

bert_chinesewordsegment's Introduction

BERT_ChineseWordSegment

Try to implement a Chinese word segment work based on Google BERT!

The corpus is extracted from The People's Daily (Chinese: 人民日报, Renmin Ribao).


First git clone https://github.com/google-research/bert.git

Second put the three scripts: modeling.py、optimization.py、tokenization.py into this project, structure is as follows:

BERT_ChinesewordSegment

    |____ PEOPLEdata
    |____ output
    |____ modeling.py
    |____ optimization.py
    |____ tokenization.py
    |____ run_cut.py
    |____ evaluation.py

Third download the Chinese pre-trained bert model BERT-Base, Chinese

And then set pre-trained model path and data path environment: $BERT_CHINESE_DIR、$PEOPLEcut

run

python3 run_cut.py   --task_name="people"   --do_train=True   --do_predict=True  --data_dir=$PEOPLEcut    --vocab_file=$BERT_CHINESE_DIR/vocab.txt   --bert_config_file=$BERT_CHINESE_DIR/bert_config.json   --init_checkpoint=$BERT_CHINESE_DIR/bert_model.ckpt    --max_seq_length=128    --train_batch_size=32    --learning_rate=2e-5   --num_train_epochs=3.0    --output_dir=./output/result_cut/

It will take about 28 minutes with 3 epochs on a GPU.

This will produce an evaluate output like this:

INFO:tensorflow:***** Eval results *****
INFO:tensorflow:  count = 9925
INFO:tensorflow:  precision_avg = 0.9794
INFO:tensorflow:  recall_avg = 0.9780
INFO:tensorflow:  f1_avg = 0.9783
INFO:tensorflow:  error_avg = 0.0213

And the word segmentation results will be seen in ./output/result_cut/seg_result.txt

If you want learn more details, see the code analysis(in Chinese)简书:BERT系列(五)——中文分词实践...

bert_chinesewordsegment's People

Contributors

jiangpinglei 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.