ซอร์สโค้ดสำหรับกระดาษ " CoLAKE : การฝังภาษาตามบริบทและความรู้" หากคุณมีปัญหาใดๆ เกี่ยวกับการทดลองซ้ำ โปรดติดต่อเราหรือเสนอปัญหาได้เลย
เราขอแนะนำให้สร้างสภาพแวดล้อมใหม่
conda create --name CoLAKE python=3.7
source activate CoLAKE
CoLAKE ใช้งานโดยอิงจาก fastNLP และหม้อแปลงของ Huggingface และใช้ fitlog เพื่อบันทึกการทดลอง
git clone https://github.com/fastnlp/fastNLP.git
cd fastNLP/ & python setup.py install
git clone https://github.com/fastnlp/fitlog.git
cd fitlog/ & python setup.py install
pip install transformers==2.11
pip install sklearn
หากต้องการฝึก CoLAKE อีกครั้ง คุณอาจจำเป็นต้องฝึกอบรม CPU-GPU แบบผสมเพื่อจัดการกับเอนทิตีจำนวนมาก การใช้งานของเราขึ้นอยู่กับ KVStore ที่ DGL จัดหาให้ นอกจากนี้ หากต้องการจำลองการทดลองเกี่ยวกับการทำนายลิงก์ คุณอาจต้องใช้ DGL-KE ด้วย
pip install dgl==0.4.3
pip install dglke
ดาวน์โหลดโมเดล CoLAKE ที่ได้รับการฝึกอบรมล่วงหน้าและการฝังสำหรับเอนทิตีมากกว่า 3M หากต้องการทำซ้ำการทดลองบน LAMA และ LAMA-UHN คุณจะต้องดาวน์โหลดโมเดลเท่านั้น คุณสามารถใช้ download_gdrive.py
ใน repo นี้เพื่อดาวน์โหลดไฟล์โดยตรงจาก Google Drive ไปยังเซิร์ฟเวอร์ของคุณ:
mkdir model
python download_gdrive.py 1MEGcmJUBXOyxKaK6K88fZFyj_IbH9U5b ./model/model.bin
python download_gdrive.py 1_FG9mpTrOnxV2NolXlu1n2ihgSZFXHnI ./model/entities.npy
หรือคุณสามารถใช้ gdown
:
pip install gdown
gdown https://drive.google.com/uc ? id=1MEGcmJUBXOyxKaK6K88fZFyj_IbH9U5b
gdown https://drive.google.com/uc ? id=1_FG9mpTrOnxV2NolXlu1n2ihgSZFXHnI
ดาวน์โหลดชุดข้อมูลสำหรับการทดลองในรายงาน: Google Drive
python download_gdrive.py 1UNXICdkB5JbRyS5WTq6QNX4ndpMlNob6 ./data.tar.gz
tar -xzvf data.tar.gz
cd finetune/
python run_re.py --debug --gpu 0
python run_typing.py --debug --gpu 0
cd ../lama/
python eval_lama.py
ดาวน์โหลดดัมพ์วิกิล่าสุด (รูปแบบ XML):
wget -c https://dumps.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2
ดาวน์โหลดกราฟความรู้ (Wikidata5M):
wget -c https://www.dropbox.com/s/6sbhm0rwo4l73jq/wikidata5m_transductive.tar.gz ? dl=1
tar -xzvf wikidata5m_transductive.tar.gz
ดาวน์โหลด Wikidata5M เอนทิตีและนามแฝงความสัมพันธ์:
wget -c https://www.dropbox.com/s/lnbhc8yuhit4wm5/wikidata5m_alias.tar.gz ? dl=1
tar -xzvf wikidata5m_alias.tar.gz
ประมวลผลดัมพ์วิกิล่วงหน้า:
mkdir pretrain_data
# process xml-format wiki dump
python preprocess/WikiExtractor.py enwiki-latest-pages-articles.xml.bz2 -o pretrain_data/output -l --min_text_length 100 --filter_disambig_pages -it abbr,b,big --processes 4
# Modify anchors
python preprocess/extract.py 4
python preprocess/gen_data.py 4
# Count entity & relation frequency and generate vocabs
python statistic.py
เริ่มต้นการฝังเอนทิตีและความสัมพันธ์ด้วยค่าเฉลี่ยของการฝัง RoBERTa BPE ของเอนทิตีและนามแฝงที่เกี่ยวข้อง:
cd pretrain/
python init_ent_rel.py
ฝึก CoLAKE ด้วย CPU-GPU แบบผสม:
./run_pretrain.sh
หากคุณใช้รหัสและรุ่น โปรดอ้างอิงเอกสารนี้:
@inproceedings{sun2020 CoLAKE ,
author = {Tianxiang Sun and Yunfan Shao and Xipeng Qiu and Qipeng Guo and Yaru Hu and Xuanjing Huang and Zheng Zhang},
title = { CoLAKE : Contextualized Language and Knowledge Embedding},
booktitle = {Proceedings of the 28th International Conference on Computational Linguistics, {COLING}},
year = {2020}
}
รวดเร็ว NLP
ลามะ
เออร์นี่