Bert-Multi-Label-Text-Classification
PyTorch implementation of a pretrained BERT model for multi-label text classification
GraphCanon updated 1d · GitHub synced 1d
Decision brief
Specific to Bert-Multi-Label-Text-Classification
Good fit when
- When PyTorch-based fine-tuning of BERT for multi-label text classification tasks is required.
- If your project already utilizes Python and the MIT License aligns with your licensing requirements.
Avoid when
- Avoid if TensorFlow is preferred over PyTorch for your workloads.
- Not ideal if your text classification task only requires single-label outcomes rather than multi-label ones.
Observed Jul 12, 2026 · Source: enrich:decision_facts
Verify the decision
Maintenance and security
Full trust report- Maintenance
- Dormant (1223d since push)
- As of 1d
- Provenance
- Not a fork · Personal account
- As of 1d
- Security (OSV)
- No lockfile
- As of 1mo
Public GitHub metadata and optional OSV scans. Signals, not a guarantee. Trust methodology.
Install
pip install Bert-Multi-Label-Text-Classification PyPISimilar tools
Same-category neighbours. No typed graph edges are catalogued for this tool yet.
Evidence and technical details
Sourced facts, taxonomy, compatibility claims, README excerpt, and machine-readable endpoints.
Overview
This repository provides a PyTorch-based approach to fine-tuning pretrained models like BERT for the purpose of classifying text into multiple labels. It is useful in natural language processing tasks where texts can belong to more than one category.
Capability facts
- Languages
- python
Source: github.language · Aug 24, 2026
Categories
Compatibility
Sourced claims from the README excerpt - not unsourced marketing copy.
Source: README excerpt (regex_v1, Aug 24, 2026)
9. Run `python run_bert.py --do_data` to preprocess data.Source link
Tags
README
Bert multi-label text classification by PyTorch
This repo contains a PyTorch implementation of the pretrained BERT and XLNET model for multi-label text classification.
Structure of the code
At the root of the project, you will see:
├── 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
Dependencies
- csv
- tqdm
- numpy
- pickle
- scikit-learn
- PyTorch 1.1+
- matplotlib
- pandas
- transformers=2.5.1
How to use the code
you need download pretrained bert model and xlnet model.
BERT: bert-base-uncased
XLNET: xlnet-base-cased
-
Download the Bert pretrained model from s3
-
Download the Bert config file from s3
-
Download the Bert vocab file from s3
-
Rename:
bert-base-uncased-pytorch_model.bintopytorch_model.binbert-base-uncased-config.jsontoconfig.jsonbert-base-uncased-vocab.txttobert_vocab.txt
-
Place
model,configandvocabfile into the/pybert/pretrain/bert/base-uncaseddirectory. -
pip install pytorch-transformersfrom github. -
Download kaggle data and place in
pybert/dataset.- you can modify the
io.task_data.pyto adapt your data.
- you can modify the
-
Modify configuration information in
pybert/configs/basic_config.py(the path of data,...). -
Run
python run_bert.py --do_datato preprocess data. -
Run
python run_bert.py --do_train --save_best --do_lower_caseto fine tuning bert model. -
Run
run_bert.py --do_test --do_lower_caseto predict new data.
training
[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
training figure
result
---- 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
Tips
- When converting the tensorflow checkpoint into the pytorch, it's expected to choice the "bert_model.ckpt", instead of "bert_model.ckpt.index", as the input file. Otherwise, you will see that the model can learn nothing and give almost same random outputs for any inputs. This means, in fact, you have not loaded the true ckpt for your model
- When using multiple GPUs, the non-tensor calculations, such as accuracy and f1_score, are not supported by DataParallel instance
- As recommanded by Jocob in his paper https://arxiv.org/pdf/1810.04805.pdf, in fine-tuning tasks, the hyperparameters are expected to set as following: Batch_size: 16 or 32, learning_rate: 5e-5 or 2e-5 or 3e-5, num_train_epoch: 3 or 4
- The pretrained model has a limit for the sentence of input that its length
For agents
This page has a .md twin and JSON over the API.