Coder Social home page Coder Social logo

easy_bert_pretrain's Introduction

easy_bert_pretrain

The very easy BERT pretrain process by using tokenizers and transformers repos.

Requirements

So we need following repos:

tokenizers==0.5.0
transformers==2.5.0

How to use

Tokenize corpus

First, you need data, lots of data. If not, you still can train anyway.

So I put an sample of text, lunyun(论语), the bible of confucianist, in the repo. How nice am I.

Then you just need set the train_tokenizer.sh script and run it.

python train_tokenizer.py \
    --files ./data/lunyun.txt \
    --out model \
    --vocab_size 10000 \
    --min_frequency 2 \
    --limit_alphabet 10000

Pretrain BERT

Second, just set pretrain_bert.sh and run it, especially you need specify the tokenizer_name to the vocab file you get from last step and config_name to the config file in model folder.

python run_language_modeling.py \
    --train_data_file ./data/lunyu.txt \
    --output_dir ./model/ \
    --model_type bert \
    --mlm \
    --config_name ./model/ \
    --tokenizer_name ./model/ \
    --do_train \
    --learning_rate 1e-4 \
    --num_train_epochs 20 \
    --save_total_limit 2 \
    --save_steps 2000 \
    --per_gpu_train_batch_size 16 \
    --evaluate_during_training \
    --line_by_line \
    --block_size 256

If you need specify your dataset processing, you can edit the Dataset class in run_language_modeling.py file.

easy_bert_pretrain's People

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.