Bert Multi Label Text Classification
1.0.0
このレポは、マルチラベルテキスト分類のための前提条件のBERTおよびXLNETモデルのPytorch実装が含まれています。
プロジェクトの根本に、あなたは次のようになります:
├── pybert
| └── callback
| | └── lrscheduler.py
| | └── trainingmonitor.py
| | └── ...
| └── config
| | └── basic_config.py #a configuration file for storing model parameters
| └── dataset
| └── io
| | └── dataset.py
| | └── data_transformer.py
| └── model
| | └── nn
| | └── pretrain
| └── output #save the ouput of model
| └── preprocessing #text preprocessing
| └── train #used for training a model
| | └── trainer.py
| | └── ...
| └── common # a set of utility functions
├── run_bert.py
├── run_xlnet.py
前提条件のBERTモデルとXLNETモデルをダウンロードする必要があります。
BERT:Bert-Base-Uncased
XLNET:XLNET-Base-Cased
S3からBert Treatreaded Modelをダウンロードしてください
S3からBert Configファイルをダウンロードします
S3からBert Vocabファイルをダウンロードします
改名:
bert-base-uncased-pytorch_model.bin to pytorch_model.binbert-base-uncased-config.json to config.jsonbert_vocab.txtからbert-base-uncased-vocab.txt /pybert/pretrain/bert/base-uncasedディレクトリにmodel 、 configおよびvocabファイルを配置します。
GitHubからpip install pytorch-transformers 。
Kaggleデータをダウンロードし、 pybert/datasetに配置します。
io.task_data.pyを変更してデータを適応させることができます。 pybert/configs/basic_config.py (データのパス、...)の構成情報を変更します。
python run_bert.py --do_dataを実行してください。
python run_bert.py --do_train --save_best --do_lower_case微調整bertモデルを微調整します。
run_bert.py --do_test --do_lower_case新しいデータを予測します。
[training] 8511/8511 [>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] -0.8s/step- loss: 0.0640
training result:
[2019-01-14 04:01:05]: bert-multi-label trainer.py[line:176] INFO
Epoch: 2 - loss: 0.0338 - val_loss: 0.0373 - val_auc: 0.9922
- - - - train report every label - - - - -
Label : toxic - auc : 0.9903
Label : severe_toxic - auc : 0.9913
Label : obscene - auc : 0.9951
Label : threat - auc : 0.9898
Label : insult - auc : 0.9911
Label : identity_hate - auc : 0.9910
- - - - valid report every label - - - - -
Label : toxic - auc : 0.9892
Label : severe_toxic - auc : 0.9911
Label : obscene - auc : 0.9945
Label : threat - auc : 0.9955
Label : insult - auc : 0.9903
Label : identity_hate - auc : 0.9927