GithubHelp home page GithubHelp logo

harrydrippin / bert-online Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ainblockchain/bert-online

0.0 3.0 0.0 47 KB

An online version of BERT for AI Network.

License: Apache License 2.0

Dockerfile 0.36% Python 99.64%

bert-online's Introduction

bert-online

An online version of BERT for AI Network Demo (http://cloud.ainetwork.ai).

How to run on AI Network Demo

TBD

How to run using commandlines

It can be run in Docker environment using the commandlines below:

Run w/ tensorflow docker image (on CPU machine):

DOCKER_BERT_DIR=/bert
TF_CPP_MIN_LOG_LEVEL=2

docker run -v $PWD:/bert \
  -w /bert \
  --env PYTHONPATH=/bert \
  --rm tensorflow/tensorflow \
  python /bert/bert_online/run_squad_online.py \
  --vocab_file=$DOCKER_BERT_DIR/model_base_cased/vocab.txt \
  --bert_config_file=$DOCKER_BERT_DIR/model_base_cased/bert_config.json \
  --init_checkpoint=$DOCKER_BERT_DIR/squad1.1-output-train_2/model.ckpt-14599 \
  --max_seq_length=320 \
  --doc_stride=128 \
  --n_best_size=3

Run w/ bert-online docker image (on CPU machine):

docker run -v $PWD/bert_online:/bert/bert_online \
  -w /bert \
  --env PYTHONPATH=/bert \
  -t --rm comcomai/bert-online:1.0.0 \
  python /bert/bert_online/run_squad_online.py \
  --vocab_file=/bert/model_base_cased/vocab.txt \
  --bert_config_file=/bert/model_base_cased/bert_config.json \
  --init_checkpoint=/bert/squad1.1-output-train_2/model.ckpt-14599 \
  --max_seq_length=320 \
  --doc_stride=128 \
  --n_best_size=3

Run w/ tensorflow-gpu docker image (on GPU machine):

DOCKER_BERT_DIR=/bert

docker run -v $PWD:/bert \
  -w /bert \
  --env PYTHONPATH=/bert \
  --runtime=nvidia --rm tensorflow/tensorflow:1.12.0-rc2-gpu \
  python /bert/bert_online/run_squad_online.py \
  --vocab_file=$DOCKER_BERT_DIR/model_base_cased/vocab.txt \
  --bert_config_file=$DOCKER_BERT_DIR/model_base_cased/bert_config.json \
  --init_checkpoint=$DOCKER_BERT_DIR/squad1.1-output-train_2/model.ckpt-14599 \

--max_seq_length=320 \
  --doc_stride=128 \
  --n_best_size=3

Run w/ bert-online-gpu docker image (on GPU machine):

docker run -v $PWD/bert_online:/bert/bert_online \
  -w /bert \
  --env PYTHONPATH=/bert \
  --runtime=nvidia -t --rm comcomai/bert-online:1.0.0-gpu \
  python /bert/bert_online/run_squad_online.py \
  --vocab_file=/bert/model_base_cased/vocab.txt \
  --bert_config_file=/bert/model_base_cased/bert_config.json \
  --init_checkpoint=/bert/squad1.1-output-train_2/model.ckpt-14599 \
  --max_seq_length=320 \
  --doc_stride=128 \
  --n_best_size=3

How to train BERT models

BERT models can be trained using the commandlines below.

For more details, please refer to BERT github (https://github.com/google-research/bert).

Download pre-trained model

Download <BERT-Base, Cased> model files and put them under model_base_cased directory.

Download SQuAD files

Download SQuAD1.1 files and put them under squad1.1 directory.

Download BERT code

Download BERT source code and put them under bert directory.

Train BERT model (on GPU machine):

DOCKER_BERT_BASE_DIR=/bert/model_base_cased
DOCKER_SQUAD_DIR=/bert/squad1.1
DOCKER_OUTPUT_DIR=/bert/squad1.1-output

docker run -v  $PWD:/bert \
  -w /bert \
  --runtime=nvidia --rm tensorflow/tensorflow:latest-gpu \
  python /bert/bert/run_squad.py \
  --vocab_file=$DOCKER_BERT_BASE_DIR/vocab.txt \
  --bert_config_file=$DOCKER_BERT_BASE_DIR/bert_config.json \
  --init_checkpoint=$DOCKER_BERT_BASE_DIR/bert_model.ckpt \
  --do_train=True \
  --train_file=$DOCKER_SQUAD_DIR/train-v1.1.json \
  --do_predict=True \
  --predict_file=$DOCKER_SQUAD_DIR/dev-v1.1.json \
  --train_batch_size=12 \
  --learning_rate=3e-5 \
  --num_train_epochs=2.0 \
  --max_seq_length=320 \
  --doc_stride=128 \
  --output_dir=$DOCKER_OUTPUT_DIR 

How to build Docker images

Docker images can be built using the commandlines below:

Build bert-online docker image (for CPU machine):

docker build -t bert-online .
docker tag bert-online:latest comcomai/bert-online:1.0.0
docker push comcomai/bert-online:1.0.0
docker pull comcomai/bert-online:1.0.0

Build bert-online-gpu docker image (for GPU machine):

vi Dockerfile  # Change tensorflow/tensorflow:1.12.0-rc2 to tensorflow/tensorflow:1.12.0-rc2-gpu 
docker build -t bert-online-gpu .
docker tag bert-online:latest comcomai/bert-online:1.0.0-gpu
docker push comcomai/bert-online:1.0.0-gpu
docker pull comcomai/bert-online:1.0.0-gpu

bert-online's People

Contributors

dev-ainetwork avatar platfowner avatar

Watchers

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