Coder Social home page Coder Social logo

tan800630 / bert-test Goto Github PK

View Code? Open in Web Editor NEW

This project forked from google-research/bert

0.0 3.0 0.0 227 KB

TensorFlow code and pre-trained models for BERT

Home Page: https://arxiv.org/abs/1810.04805

License: Apache License 2.0

Python 57.19% Jupyter Notebook 42.81%

bert-test's Introduction

BERT - forked from google-research

施工中,未完成

前言

2018年11月釋出的Bidirectional Encoder Representations from Transformers論文根基於google前一段時間發表的transformer模型,並且在多個自然語言處理相關作業/比賽上都取得了亮眼的成績。模型架構完全採用transformer-encoder module,而非seq2seq類型的遞迴神經網路(這也是transformer的亮點),然而在論文中似乎是為了要跟BERT之類的Language Model做一個比較,因此畫的仍然像是序列式處理的模型,一開始我也被搞混了: /

官方也釋出各種版本的pretrain model供使用者下載,以下將我這段時間測試的內容記錄下來。

註:此版本使用tensorflow框架

Pretrain Model

已提供之預訓練模型請見google-research github

在以下的範例中,採用BERT-Base, Multilingual Cased版本,支援104種語言,總參數量大概在110 Million 左右。

預訓練模型可直接由官方提供的連結下載(.zip檔案),裏頭包含了模型檔案(bert_model.ckpt)、字典檔案(vocab.txt)、以及模型超參數設定檔(bert_config.json)

Fine-tune Model with your own data

google團隊提供了GLUE data中幾個資料集的fine-tune方式(在程式碼部分也寫好前處理的部分),然而若要應用到自己的資料內的話需要自己改寫Processor。

在此使用Imdb sentiment analysis dataset作為範例,並稍微修改原始碼,呈現應如何應用此模型到自己的資料中。 (不過這只是單句分類作業,還有另外一塊沒有涵蓋到) 採取的方式是兩階段式的資料整理,首先先將訓練與測試資料儲存為tf_record格式,接著再直接包成input_fn丟入tf.contrib.tpu.TPUEstimator作模型訓練/測試。

註:由於TFRecordDataset().shuffle運作的方式,發現若資料排序整齊整個模型會訓練不起來。建議在寫入tf_record檔案前手動先shuffle過一遍。

同樣使用Imdb sentiment analysis dataset資料,此版本直接修改run_classifier.py中的內容,使其可以應用在Imdb資料集中,修改完的code可在terminal上直接執行訓練與驗證流程。

Citation

Imdb 資料來源

-- Andrew L. Maas, Raymond E. Daly, Peter T. Pham, Dan Huang, Andrew Y. Ng, and Christopher Potts. (2011). Learning Word Vectors for Sentiment Analysis. The 49th Annual Meeting of the Association for Computational Linguistics (ACL 2011).

bert-test's People

Contributors

jacobdevlin-google avatar tan800630 avatar cbockman avatar abhishekraok avatar bogdandidenko avatar eric-haibin-lin avatar 0xflotus avatar aijunbai avatar ammarasmro avatar imcaspar avatar craigcitro avatar georgefeng avatar rodgzilla avatar qwfy avatar jasonjpu avatar pengli09 avatar stefan-it avatar zhaoyongke avatar

Watchers

James Cloos avatar  avatar Frank 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.