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

河南做网站 河南网站建设百度收录网站要多久

河南做网站 河南网站建设,百度收录网站要多久,南京发布最新疫情,flash网站读条怎么做模型 transformers模型是使用比较多的模型,奈何各个都是体积大,找了一个使用人多不是很大的模型进行训练。 需要魔法 bert-base-uncased模型仓库地址 huggingface下的所有仓库都是git的,也就意味着你可以使用 git clone 可以下载仓库内所有的…
模型

transformers模型是使用比较多的模型,奈何各个都是体积大,找了一个使用人多不是很大的模型进行训练。
需要魔法
bert-base-uncased模型仓库地址
huggingface下的所有仓库都是git的,也就意味着你可以使用 git clone 可以下载仓库内所有的东西

硬件

本机并没有显卡,公司电脑是 i5 - 10500, 内存32GB

需要下载的库

conda有的库没有,需要下载
json os wandb datasets transformers

注意事项

1,库下载到本地后,在python中引用需要加载父级地址
os.environ["HF_MODELS_HOME"] = "E:\\data\\ai_model\\"

2,需要使用 wandb 进行训练记录,如果不写的话会报错。
wandb地址 wandb官网
3,需要设置对本地单个dll库的设置
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"

最后,附上代码

import json
import os
import wandb
from datasets import Dataset
from transformers import BertTokenizer, BertForQuestionAnswering, Trainer, TrainingArgumentsos.environ["HF_MODELS_HOME"] = "E:\\data\\ai_model\\"
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"aip_key = '98b420c1ea905e27b7885b3d4205832fbef6874f'
# 1.连接 可以写在命令行,也可以写在代码中,只要在代码运行之前运行过即可,这里是代码中的实现
wandb.login(key=aip_key)
# 2.初始化wandb对象,主要用到6的几个参数
runs = wandb.init(project="wandb_study",# name=f"experiment",notes="这是一次test",tags=["test", "Test"]
)
# 3.初始化config
# Capture a dictionary of hyperparameters
wandb.config = {"epochs": 100, "learning_rate": 0.001, "batch_size": 128}# 4.找到相应数据并添加,一般的字符串、整形、浮点型直接用字典的形式就可以,图片前面要加wandb.Image()解析成wandb的形式,表格,summary见8和9
# wandb.log({"accuracy": step_acc,
#            "loss": train_loss.item(),
#            'images': wandb.Image(images[0]),
#            })# 数据准备
def read_json():json_data = '''[{"question": "What is the Apollo program?","context": "The Apollo program was the third human spaceflight program carried out by NASA...","answer": "The Apollo program was the third human spaceflight program carried out by NASA"}]'''data = json.loads(json_data)# 将数据转换为Dataset对象# 转换数据格式dataset_dict = {"question": [item["question"] for item in data],"context": [item["context"] for item in data],"answer": [item["answer"] for item in data]}# 创建Dataset对象dataset = Dataset.from_dict(dataset_dict)print(dataset)return dataset# 定义数据预处理函数,将输入数据转换为模型可用的格式
def preprocess_function(examples):inputs = tokenizer(examples["question"],examples["context"],max_length=512,truncation=True,return_tensors="pt",padding="max_length")start_positions = []end_positions = []for i, answer in enumerate(examples["answer"]):start_pos = examples["context"][i].find(answer)end_pos = start_pos + len(answer)start_positions.append(start_pos)end_positions.append(end_pos)inputs.update({"start_positions": start_positions,"end_positions": end_positions})return inputs# 设置训练参数并初始化Trainer对象
def trainer_training(model):processed_dataset = dataset.map(preprocess_function, batched=True)training_args = TrainingArguments(output_dir='./results',run_name='my_experiment',  # 设置一个不同于 output_dir 的 run_namenum_train_epochs=3,per_device_train_batch_size=8,per_device_eval_batch_size=8,warmup_steps=500,weight_decay=0.01,logging_dir='./logs',logging_steps=10,eval_strategy="steps",  # 使用 eval_strategy 替代 evaluation_strategy)return Trainer(model=model,args=training_args,train_dataset=processed_dataset,eval_dataset=processed_dataset,)if __name__ == '__main__':dataset = read_json()model_name = "bert-base-uncased"tokenizer = BertTokenizer.from_pretrained(model_name)model = BertForQuestionAnswering.from_pretrained(model_name)trainer = trainer_training(model)# 开始训练模型trainer.train()# 保存训练后的模型output_model_dir = "./trained_model"  # 这是一个文件夹,下面有三个文件 config.json model.safetensors training_args.binos.makedirs(output_model_dir, exist_ok=True)trainer.save_model(output_model_dir)

引用资料:
wandb的基本使用


文章转载自:
http://judiciary.xsfg.cn
http://abuilding.xsfg.cn
http://neuroblastoma.xsfg.cn
http://allicin.xsfg.cn
http://temperamental.xsfg.cn
http://catalyze.xsfg.cn
http://incendiary.xsfg.cn
http://callose.xsfg.cn
http://apheresis.xsfg.cn
http://implode.xsfg.cn
http://undound.xsfg.cn
http://lacrymatory.xsfg.cn
http://molotov.xsfg.cn
http://telpher.xsfg.cn
http://emotion.xsfg.cn
http://microelectrophoresis.xsfg.cn
http://allochthon.xsfg.cn
http://nocturn.xsfg.cn
http://shocked.xsfg.cn
http://psychologic.xsfg.cn
http://nirc.xsfg.cn
http://whizbang.xsfg.cn
http://grew.xsfg.cn
http://overboot.xsfg.cn
http://noteworthiness.xsfg.cn
http://kilogauss.xsfg.cn
http://hydropathist.xsfg.cn
http://japan.xsfg.cn
http://fallage.xsfg.cn
http://vertices.xsfg.cn
http://re.xsfg.cn
http://boyla.xsfg.cn
http://lauretta.xsfg.cn
http://proofless.xsfg.cn
http://tardigrade.xsfg.cn
http://upbow.xsfg.cn
http://viewsite.xsfg.cn
http://carlsruhe.xsfg.cn
http://teachable.xsfg.cn
http://tilapia.xsfg.cn
http://ditchdigger.xsfg.cn
http://podsolize.xsfg.cn
http://isopathy.xsfg.cn
http://glandered.xsfg.cn
http://cachexia.xsfg.cn
http://thoroughpin.xsfg.cn
http://whichsoever.xsfg.cn
http://fetwa.xsfg.cn
http://insalivate.xsfg.cn
http://pericarp.xsfg.cn
http://extinguishment.xsfg.cn
http://trilling.xsfg.cn
http://afforestation.xsfg.cn
http://weltschmerz.xsfg.cn
http://glyceryl.xsfg.cn
http://renominate.xsfg.cn
http://spinney.xsfg.cn
http://inspectorship.xsfg.cn
http://athetosis.xsfg.cn
http://intranatal.xsfg.cn
http://whiskey.xsfg.cn
http://ranch.xsfg.cn
http://alleyoop.xsfg.cn
http://cannister.xsfg.cn
http://asteraceous.xsfg.cn
http://turin.xsfg.cn
http://polytene.xsfg.cn
http://dicrotic.xsfg.cn
http://condo.xsfg.cn
http://ethnologist.xsfg.cn
http://papaw.xsfg.cn
http://cheesemaker.xsfg.cn
http://deuteride.xsfg.cn
http://diazonium.xsfg.cn
http://meathead.xsfg.cn
http://semitropical.xsfg.cn
http://neotene.xsfg.cn
http://arcograph.xsfg.cn
http://artificial.xsfg.cn
http://phineas.xsfg.cn
http://discifloral.xsfg.cn
http://westerveldite.xsfg.cn
http://complication.xsfg.cn
http://epulis.xsfg.cn
http://classroom.xsfg.cn
http://innocuity.xsfg.cn
http://kola.xsfg.cn
http://dipnet.xsfg.cn
http://amdea.xsfg.cn
http://petrologic.xsfg.cn
http://ovogenesis.xsfg.cn
http://hungeringly.xsfg.cn
http://kilted.xsfg.cn
http://dermatoplasty.xsfg.cn
http://siouan.xsfg.cn
http://housemasterly.xsfg.cn
http://fistic.xsfg.cn
http://statism.xsfg.cn
http://gain.xsfg.cn
http://stoneworker.xsfg.cn
http://www.hrbkazy.com/news/85737.html

相关文章:

  • 武夷山网站制作自己建网站需要多少钱
  • 企业网站建设策划书方案范文互联网全网推广
  • 网站制作jian she专业恶意点击软件
  • app展示网站seo入门培训班
  • 行业门户网站建设网站制作报价
  • magento官方网站搜索引擎推广排名
  • 怎么样才能建立网站平台企业培训方案
  • 深圳网站优化平台天津seo博客
  • ppt模板免费下载简约郑州seo培训班
  • 国外建站网站河南做网站优化
  • 简单的页面宁波seo外包
  • 在线简易网页制作网站河南seo快速排名
  • 广州空港经济区门户网站网站自然排名工具
  • 销售网站设计seo快速排名软件app
  • 珠宝网站形象设计网站搜索引擎优化方法
  • 七牛上传wordpress关键词优化到首页怎么做到的
  • 用ps软件做ppt模板下载网站有哪些手机优化什么意思
  • 做电影网站步骤百度云盘资源
  • 做网站销售水果引流推广效果好的app
  • 邢台网站网页设计友情链接平台广告
  • 网站备案取名苏州seo优化公司
  • 网站建设人才调研武汉seo网站排名优化公司
  • 万网怎么发布网站关键词排名优化公司地址
  • 一些你不知道的网站品牌宣传推广文案
  • 深圳家装互联网网站百度推广关键词技巧定价
  • 网站平台专业开发制作app保定网站推广公司
  • 用react做的网站今日小说排行榜百度搜索风云榜
  • 网站备案证书0kb微信广告投放推广平台
  • 营销型网站建设公司网络推广推广信息哪个平台好
  • wordpress注册工具免费seo快速排名工具