K BERT
1.0.0
"K-Bert : 지식 그래프로 언어 표현 활성화"에 대한 소스 코드 및 데이터 세트는 UER 프레임 워크를 기반으로 구현됩니다.
소식
소프트웨어:
Python3
Pytorch >= 1.0
argparse == 1.1
google_model.bin 을 다운로드하여 models/ 디렉토리에 저장하십시오.CnDbpedia.spo 다운로드하여 brain/kgs/ 디렉토리에 저장하십시오.datasets/ 디렉토리에 배치하십시오.K-Bert의 디렉토리 트리 :
K-BERT
├── brain
│ ├── config.py
│ ├── __init__.py
│ ├── kgs
│ │ ├── CnDbpedia.spo
│ │ ├── HowNet.spo
│ │ └── Medical.spo
│ └── knowgraph.py
├── datasets
│ ├── book_review
│ │ ├── dev.tsv
│ │ ├── test.tsv
│ │ └── train.tsv
│ ├── chnsenticorp
│ │ ├── dev.tsv
│ │ ├── test.tsv
│ │ └── train.tsv
│ ...
│
├── models
│ ├── google_config.json
│ ├── google_model.bin
│ └── google_vocab.txt
├── outputs
├── uer
├── README.md
├── requirements.txt
├── run_kbert_cls.py
└── run_kbert_ner.py
CNDBPEDIA와 함께 서평 검토 예제 실행 :
CUDA_VISIBLE_DEVICES= ' 0 ' nohup python3 -u run_kbert_cls.py
--pretrained_model_path ./models/google_model.bin
--config_path ./models/google_config.json
--vocab_path ./models/google_vocab.txt
--train_path ./datasets/book_review/train.tsv
--dev_path ./datasets/book_review/dev.tsv
--test_path ./datasets/book_review/test.tsv
--epochs_num 5 --batch_size 32 --kg_name CnDbpedia
--output_model_path ./outputs/kbert_bookreview_CnDbpedia.bin
> ./outputs/kbert_bookreview_CnDbpedia.log &결과:
Best accuracy in dev : 88.80%
Best accuracy in test: 87.69%
run_kbert_cls.py 의 옵션 :
useage: [--pretrained_model_path] - Path to the pre-trained model parameters.
[--config_path] - Path to the model configuration file.
[--vocab_path] - Path to the vocabulary file.
--train_path - Path to the training dataset.
--dev_path - Path to the validating dataset.
--test_path - Path to the testing dataset.
[--epochs_num] - The number of training epoches.
[--batch_size] - Batch size of the training process.
[--kg_name] - The name of knowledge graph, "HowNet", "CnDbpedia" or "Medical".
[--output_model_path] - Path to the output model.
다른 데이터 세트의 정확도 (dev/test %) :
| 데이터 세트 | Hownet | CNDBPEDIA |
|---|---|---|
| 서평 | 88.75/87.75 | 88.80/87.69 |
| chnsenticorp | 95.00/95.50 | 94.42/95.25 |
| 쇼핑 | 97.01/96.92 | 96.94/96.73 |
| 와이보 | 98.22/98.33 | 98.29/98.33 |
| LCQMC | 88.97/87.14 | 88.91/87.20 |
| xnli | 77.11/77.07 | 76.99/77.43 |
CNDBPEDIA와 함께 MSRA_NER 데이터 세트에서 예제를 실행하십시오.
CUDA_VISIBLE_DEVICES='0' nohup python3 -u run_kbert_ner.py
--pretrained_model_path ./models/google_model.bin
--config_path ./models/google_config.json
--vocab_path ./models/google_vocab.txt
--train_path ./datasets/msra_ner/train.tsv
--dev_path ./datasets/msra_ner/dev.tsv
--test_path ./datasets/msra_ner/test.tsv
--epochs_num 5 --batch_size 16 --kg_name CnDbpedia
--output_model_path ./outputs/kbert_msraner_CnDbpedia.bin
> ./outputs/kbert_msraner_CnDbpedia.log &
결과:
The best in dev : precision=0.957, recall=0.962, f1=0.960
The best in test: precision=0.953, recall=0.959, f1=0.956
run_kbert_ner.py 의 옵션 :
useage: [--pretrained_model_path] - Path to the pre-trained model parameters.
[--config_path] - Path to the model configuration file.
[--vocab_path] - Path to the vocabulary file.
--train_path - Path to the training dataset.
--dev_path - Path to the validating dataset.
--test_path - Path to the testing dataset.
[--epochs_num] - The number of training epoches.
[--batch_size] - Batch size of the training process.
[--kg_name] - The name of knowledge graph.
[--output_model_path] - Path to the output model.
도메인 별 작업에 대한 실험 결과 (정밀/리콜/F1 %) :
| kg | Finance_QA | law_qa | Finance_ner | Medicine_ner |
|---|---|---|---|---|
| Hownet | 0.805/0.888/0.845 | 0.842/0.903/0.871 | 0.860/0.888/0.874 | 0.935/0.939/0.937 |
| CN-DBPEDIA | 0.814/0.881/0.846 | 0.814/0.942/0.874 | 0.860/0.887/0.873 | 0.935/0.937/0.936 |
| MedicalKG | - | - | - | 0.944/0.943/0.944 |
이 작업은 Peking University and Tencent Inc의 지원을 가진 공동 연구입니다.
이 코드를 사용하는 경우이 논문을 인용하십시오.
@inproceedings{weijie2019kbert,
title={{K-BERT}: Enabling Language Representation with Knowledge Graph},
author={Weijie Liu, Peng Zhou, Zhe Zhao, Zhiruo Wang, Qi Ju, Haotang Deng, Ping Wang},
booktitle={Proceedings of AAAI 2020},
year={2020}
}