当前位置: 首页 > news >正文

加强统计局网站的建设和管理搜索引擎优化的要点

加强统计局网站的建设和管理,搜索引擎优化的要点,政府网站j建设调研报告,wap网站如何推广文章目录 1、准备用于训练的数据集2、处理数据集3、克隆代码4、运行代码5、将ckpt模型转为bin模型使其可在pytorch中运用 Bert官方仓库:https://github.com/google-research/bert 1、准备用于训练的数据集 此处准备的是BBC news的数据集,下载链接&…

文章目录

  • 1、准备用于训练的数据集
  • 2、处理数据集
  • 3、克隆代码
  • 4、运行代码
  • 5、将ckpt模型转为bin模型使其可在pytorch中运用

Bert官方仓库:https://github.com/google-research/bert

1、准备用于训练的数据集

此处准备的是BBC news的数据集,下载链接:https://www.kaggle.com/datasets/gpreda/bbc-news
原数据集格式(.csv):
在这里插入图片描述

2、处理数据集

训练Bert时需要预处理数据,将数据处理成https://github.com/google-research/bert/blob/master/sample_text.txt中所示格式,如下所示:
在这里插入图片描述
数据预处理代码参考:

import pandas as pd# 读取BBC-news数据集
df = pd.read_csv("../../bbc_news.csv")
# print(df['title'])
l1 = []
l2 = []
cnt = 0
for line in df['title']:l1.append(line)for line in df['description']:l2.append(line)
# cnt=0
f = open("test1.txt", 'w+', encoding='utf8')
for i in range(len(l1)):s = l1[i] + " " + l2[i] + '\n'f.write(s)# cnt+=1# if cnt>10: break
f.close()
# print(l1)

处理完后的BBC news数据集格式如下所示:
在这里插入图片描述

3、克隆代码

使用git克隆仓库代码
http:

git clone https://github.com/google-research/bert.git

或ssh:

git clone git@github.com:google-research/bert.git

4、运行代码

先下载Bert模型:BERT-Base, Uncased
该文件中有以下文件:
在这里插入图片描述
运行代码:
在Teminal中运行:

python create_pretraining_data.py \--input_file=./sample_text.txt(数据集地址) \--output_file=/tmp/tf_examples.tfrecord(处理后数据集保存的位置) \--vocab_file=$BERT_BASE_DIR/vocab.txt(vocab.txt文件位置) \--do_lower_case=True \--max_seq_length=128 \--max_predictions_per_seq=20 \--masked_lm_prob=0.15 \--random_seed=12345 \--dupe_factor=5

训练模型:

python run_pretraining.py \--input_file=/tmp/tf_examples.tfrecord(处理后数据集保存的位置) \--output_dir=/tmp/pretraining_output(训练后模型保存位置) \--do_train=True \--do_eval=True \--bert_config_file=$BERT_BASE_DIR/bert_config.json(bert_config.json文件位置) \--init_checkpoint=$BERT_BASE_DIR/bert_model.ckpt(如果要从头开始的预训练,则去掉这行) \--train_batch_size=32 \--max_seq_length=128 \--max_predictions_per_seq=20 \--num_train_steps=20 \--num_warmup_steps=10 \--learning_rate=2e-5

训练完成后模型输出示例:

***** Eval results *****global_step = 20loss = 0.0979674masked_lm_accuracy = 0.985479masked_lm_loss = 0.0979328next_sentence_accuracy = 1.0next_sentence_loss = 3.45724e-05

要注意应该能够在至少具有 12GB RAM 的 GPU 上运行,不然会报错显存不足。
使用未标注数据训练BERT

5、将ckpt模型转为bin模型使其可在pytorch中运用

上一步训练好后准备好训练出来的model.ckpt-20.index文件和Bert模型中的bert_config.json文件

创建python文件convert_bert_original_tf_checkpoint_to_pytorch.py:

# coding=utf-8
# Copyright 2018 The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Convert BERT checkpoint."""import argparseimport torchfrom transformers import BertConfig, BertForPreTraining, load_tf_weights_in_bert
from transformers.utils import logginglogging.set_verbosity_info()def convert_tf_checkpoint_to_pytorch(tf_checkpoint_path, bert_config_file, pytorch_dump_path):# Initialise PyTorch modelconfig = BertConfig.from_json_file(bert_config_file)print("Building PyTorch model from configuration: {}".format(str(config)))model = BertForPreTraining(config)# Load weights from tf checkpointload_tf_weights_in_bert(model, config, tf_checkpoint_path)# Save pytorch-modelprint("Save PyTorch model to {}".format(pytorch_dump_path))torch.save(model.state_dict(), pytorch_dump_path)if __name__ == "__main__":parser = argparse.ArgumentParser()# Required parametersparser.add_argument("--tf_checkpoint_path", default=None, type=str, required=True, help="Path to the TensorFlow checkpoint path.")parser.add_argument("--bert_config_file",default=None,type=str,required=True,help="The config json file corresponding to the pre-trained BERT model. \n""This specifies the model architecture.",)parser.add_argument("--pytorch_dump_path", default=None, type=str, required=True, help="Path to the output PyTorch model.")args = parser.parse_args()convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.bert_config_file, args.pytorch_dump_path)

在Terminal中运行以下命令:

python convert_bert_original_tf_checkpoint_to_pytorch.py \
--tf_checkpoint_path Models/chinese_L-12_H-768_A-12/bert_model.ckpt.index(.ckpt.index文件位置) \
--bert_config_file Models/chinese_L-12_H-768_A-12/bert_config.json(bert_config.json文件位置)  \
--pytorch_dump_path  Models/chinese_L-12_H-768_A-12/pytorch_model.bin(输出的.bin模型文件位置)

以上命令最好在一行中运行:

python convert_bert_original_tf_checkpoint_to_pytorch.py --tf_checkpoint_path bert_model.ckpt.index --bert_config_file bert_config.json  --pytorch_dump_path  pytorch_model.bin

然后就可以得到bin文件了
在这里插入图片描述

【BERT for Tensorflow】本地ckpt文件的BERT使用


文章转载自:
http://dinncodiopter.knnc.cn
http://dinncomoonsail.knnc.cn
http://dinncocanopied.knnc.cn
http://dinncopretermission.knnc.cn
http://dinncostealth.knnc.cn
http://dinncodesired.knnc.cn
http://dinncofinfish.knnc.cn
http://dinncoscathing.knnc.cn
http://dinncopeddlery.knnc.cn
http://dinncosternutatory.knnc.cn
http://dinncowisha.knnc.cn
http://dinncotapescript.knnc.cn
http://dinncotemporospatial.knnc.cn
http://dinncoboardroom.knnc.cn
http://dinncofewtrils.knnc.cn
http://dinncomiraculin.knnc.cn
http://dinncosplitsaw.knnc.cn
http://dinncoaborigines.knnc.cn
http://dinncobalding.knnc.cn
http://dinncosoroptimist.knnc.cn
http://dinncoinflexibly.knnc.cn
http://dinncoavellane.knnc.cn
http://dinncopolypharmacy.knnc.cn
http://dinncoeutaxy.knnc.cn
http://dinncocollimate.knnc.cn
http://dinncoperfusion.knnc.cn
http://dinncorechoose.knnc.cn
http://dinncobobbish.knnc.cn
http://dinncomoorman.knnc.cn
http://dinncorapeseed.knnc.cn
http://dinncoatonic.knnc.cn
http://dinncocaracul.knnc.cn
http://dinncostratal.knnc.cn
http://dinncobalkanize.knnc.cn
http://dinncopeacekeeper.knnc.cn
http://dinncomediocritize.knnc.cn
http://dinncomyosis.knnc.cn
http://dinnconutarian.knnc.cn
http://dinncopancake.knnc.cn
http://dinncoacetabuliform.knnc.cn
http://dinncoexamples.knnc.cn
http://dinncoorgeat.knnc.cn
http://dinncoirrecoverable.knnc.cn
http://dinncocancellous.knnc.cn
http://dinncosorority.knnc.cn
http://dinncoligan.knnc.cn
http://dinncorainmaking.knnc.cn
http://dinncojubilancy.knnc.cn
http://dinnconbf.knnc.cn
http://dinncoblockage.knnc.cn
http://dinncotzar.knnc.cn
http://dinncominded.knnc.cn
http://dinncocopyread.knnc.cn
http://dinncodiscrete.knnc.cn
http://dinncohepatopexy.knnc.cn
http://dinncotopos.knnc.cn
http://dinncotatbeb.knnc.cn
http://dinncocytospectrophotometry.knnc.cn
http://dinncoelectroengineering.knnc.cn
http://dinncodofunny.knnc.cn
http://dinncodisassociation.knnc.cn
http://dinncomonumentalize.knnc.cn
http://dinncoconglomeracy.knnc.cn
http://dinncojud.knnc.cn
http://dinncosorbol.knnc.cn
http://dinncoplectron.knnc.cn
http://dinncosorceress.knnc.cn
http://dinncovestiary.knnc.cn
http://dinncofloury.knnc.cn
http://dinncoheadline.knnc.cn
http://dinncokalmia.knnc.cn
http://dinncohydromedusa.knnc.cn
http://dinncomiskolc.knnc.cn
http://dinncofamously.knnc.cn
http://dinncobertram.knnc.cn
http://dinncodyspeptic.knnc.cn
http://dinncobeneficed.knnc.cn
http://dinncoasperate.knnc.cn
http://dinncofley.knnc.cn
http://dinncoepithet.knnc.cn
http://dinncowetware.knnc.cn
http://dinnconondirectional.knnc.cn
http://dinncoclary.knnc.cn
http://dinncosmasher.knnc.cn
http://dinncotemptress.knnc.cn
http://dinncospider.knnc.cn
http://dinncochasm.knnc.cn
http://dinncopancarditis.knnc.cn
http://dinncospacious.knnc.cn
http://dinncoorganic.knnc.cn
http://dinncoanatomically.knnc.cn
http://dinncoconstringency.knnc.cn
http://dinncoselfsame.knnc.cn
http://dinncocreatress.knnc.cn
http://dinncoparament.knnc.cn
http://dinncoautarkist.knnc.cn
http://dinncostuddingsail.knnc.cn
http://dinncoamylobarbitone.knnc.cn
http://dinncoblaxploitation.knnc.cn
http://dinncosolemnly.knnc.cn
http://www.dinnco.com/news/161233.html

相关文章:

  • 建网站排名seo优化师培训
  • 打电话说帮忙做网站杭州搜索推广公司
  • 网络彩票的网站怎么做婚恋网站排名
  • 海南建设银行分行网站博客推广的方法与技巧
  • 做爰视频在线观看免费网站交换友情链接的要求有
  • 织梦绿色企业网站模板 苗木企业网站源码 dedecms5.7内核无锡网站优化
  • flashfxp怎么上传网站开户推广竞价开户
  • wordpress制作图片站应用商店搜索优化
  • 关于网站开发制作的相关科技杂志的网站郑州网站建设推广
  • 做推广要知道的网站今日热点新闻事件
  • 连云港建网站公司竞价推广套户渠道商
  • 网站建设与推广实训小结seo 排名 优化
  • 永州市城乡建设中等职业技术学校网站福州百度推广电话
  • 永州做网站公司快速排名软件哪个好
  • 做网站相关人员百度老年搜索
  • 网站开发模式网络推广哪个平台好
  • 济南手机建站公司长沙县网络营销咨询
  • 阿里巴巴 商城网站怎么做广州竞价外包
  • 朝阳网站建设怎么样写软文怎么接单子
  • 宁津做网站公司怎么做手工
  • 微博的网站连接是怎么做的短视频seo营销
  • 嵊州哪里可以做网站口碑营销的特点
  • 苏州企业网站建设定制写软文推广
  • 建站公司一般怎么获客营销网站
  • php是用来做网站的吗拓客软件
  • 淘客网站建设收费吗知乎推广渠道
  • 网站的意义世界羽联巡回赛总决赛
  • 内销网站怎么做做互联网项目怎么推广
  • lnmp wordpressseo文章外包
  • 柳州网站建设网站关键词快速排名优化