課時92 BERT模型訓練方法
>>如何訓練BERT
方法1:15%詞匯被隨機mask掉(涉及損失函數
方法2:預測兩個句子是否應該連在一起
課時93 訓練實例
閱讀理解題:輸入的是文章和問題聊浅,輸出的是理解的答案位置原茅。返回結果是答案(詞匯)在文章中所在的位置
如何設計網絡:需要額外設置兩個輔助向量豺旬,分別記錄答案的起始位置和終止位置闻坚,用輔助向量和文章中每個詞做內積(表示相關性),通過softmax確定最大值
課時94 BERT開源項目簡介
BERT下bert-master文件夾
1. 為文件設置參數
--num_train_epochs=3.0小項目可以更小一點
2.?運行文件測試基礎環(huán)境
運行run_classifier.py文件出現問題“AttributeError: module 'tensorflow._api.v2.train' has no attribute 'Optimizer'”
解決方法:額外安裝更老的tensorflow版本
命令:python -m pip install tensorflow-gpu==1.15.0
3.?讀+修改基礎代碼
1)#代碼296行
class MrpcProcessor(DataProcessor):
"""Processor for the MRPC data set (GLUE version)."""
……
2)如果數據集不是MRPC則需要進行個人改動底洗,例如盆耽,test a莹桅,b
#代碼325行
text_a = tokenization.convert_to_unicode(line[3])
text_b = tokenization.convert_to_unicode(line[4])
3)調整迭代次數,train_batch_steps是迭代次數尼荆,get_train_examples讀數據
#代碼842
if FLAGS.do_train:
train_examples = processor.get_train_examples(FLAGS.data_dir)
num_train_steps =int(
len(train_examples) / FLAGS.train_batch_size * FLAGS.num_train_epochs)
num_warmup_steps =int(num_train_steps * FLAGS.warmup_proportion)
4. 運行問題
TensorFlow報錯:AttributeError: module 'tensorflow_core._api.v2.train' has no attribute 'Optimizer‘
https://blog.csdn.net/weixin_42720673/article/details/103066349
TensorFlow版本更新到2.0左腔,Optimizer方法調用方式改變 。將tf.train.Optimizer捅儒,更改為tf.optimizers.Optimizer即可液样。
AttributeError: module 'tensorflow' has no attribute 'flags'
https://blog.csdn.net/qq_40212975/article/details/103718044
import tensorflow ad tf 改為 import tensorflow.compat.v1 as tf
module 'tensorflow' has no attribute 'gfile'
https://blog.csdn.net/weixin_41845265/article/details/108573026
tf.gfile 改成 tf.io.gfile
以上問題最后只是通過改變TensorFlow版本從2.4.0->2.0.0就可以了