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

专业的集团网站建设免费外链发布

专业的集团网站建设,免费外链发布,凡客网站建立,公司网站需求分析我们将对BERT的中文问答系统48-1代码进行以下改进: 1.增加时间日期和日历功能:在GUI中增加显示当前时间和日期的功能,并提供一个日历组件。 2.增加更多模型类型:增加娱乐、电脑、军事、汽车、植物、科技、历史(朝代、皇帝)、名人、生活(出行、菜品、菜谱、居家),法律、…

我们将对BERT的中文问答系统48-1代码进行以下改进:
1.增加时间日期和日历功能:在GUI中增加显示当前时间和日期的功能,并提供一个日历组件。
2.增加更多模型类型:增加娱乐、电脑、军事、汽车、植物、科技、历史(朝代、皇帝)、名人、生活(出行、菜品、菜谱、居家),法律、企业、标准等模型的建立、保存和加载。
3.统一使用百度百科:移除360百科的相关代码。
4.完善GUI布局:优化GUI布局,使其更加美观和易用。
以下是改进后的代码:

import os
import json
import jsonlines
import torch
import torch.optim as optim
from torch.utils.data import Dataset, DataLoader
from transformers import BertModel, BertTokenizer
import tkinter as tk
from tkinter import filedialog, messagebox, ttk
import logging
from difflib import SequenceMatcher
from datetime import datetime
import requests
from bs4 import BeautifulSoup
import calendar# 获取项目根目录
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))# 配置日志
LOGS_DIR = os.path.join(PROJECT_ROOT, 'logs')
os.makedirs(LOGS_DIR, exist_ok=True)def setup_logging():log_file = os.path.join(LOGS_DIR, datetime.now().strftime('%Y-%m-%d_%H-%M-%S_羲和.txt'))logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(levelname)s - %(message)s',handlers=[logging.FileHandler(log_file),logging.StreamHandler()])setup_logging()# 数据集类
class XihuaDataset(Dataset):def __init__(self, file_path, tokenizer, max_length=128):self.tokenizer = tokenizerself.max_length = max_lengthself.data = self.load_data(file_path)def load_data(self, file_path):data = []if file_path.endswith('.jsonl'):with jsonlines.open(file_path) as reader:for i, item in enumerate(reader):try:data.append(item)except jsonlines.jsonlines.InvalidLineError as e:logging.warning(f"跳过无效行 {i + 1}: {e}")elif file_path.endswith('.json'):with open(file_path, 'r') as f:try:data = json.load(f)except json.JSONDecodeError as e:logging.warning(f"跳过无效文件 {file_path}: {e}")return datadef __len__(self):return len(self.data)def __getitem__(self, idx):item = self.data[idx]question = item.get('question', '')human_answer = item.get('human_answers', [''])[0]chatgpt_answer = item.get('chatgpt_answers', [''])[0]try:inputs = self.tokenizer(question, return_tensors='pt', padding='max_length', truncation=True, max_length=self.max_length)human_inputs = self.tokenizer(human_answer, return_tensors='pt', padding='max_length', truncation=True, max_length=self.max_length)chatgpt_inputs = self.tokenizer(chatgpt_answer, return_tensors='pt', padding='max_length', truncation=True, max_length=self.max_length)except Exception as e:logging.warning(f"跳过无效项 {idx}: {e}")return self.__getitem__((idx + 1) % len(self.data))return {'input_ids': inputs['input_ids'].squeeze(),'attention_mask': inputs['attention_mask'].squeeze(),'human_input_ids': human_inputs['input_ids'].squeeze(),'human_attention_mask': human_inputs['attention_mask'].squeeze(),'chatgpt_input_ids': chatgpt_inputs['input_ids'].squeeze(),'chatgpt_attention_mask': chatgpt_inputs['attention_mask'].squeeze(),'human_answer': human_answer,'chatgpt_answer': chatgpt_answer}# 获取数据加载器
def get_data_loader(file_path, tokenizer, batch_size=8, max_length=128):dataset = XihuaDataset(file_path, tokenizer, max_length)return DataLoader(dataset, batch_size=batch_size, shuffle=True)# 模型定义
class XihuaModel(torch.nn.Module):def __init__(self, pretrained_model_name='F:/models/bert-base-chinese'):super(XihuaModel, self).__init__()self.bert = BertModel.from_pretrained(pretrained_model_name)self.classifier = torch.nn.Linear(self.bert.config.hidden_size, 1)def forward(self, input_ids, attention_mask):outputs = self.bert(input_ids=input_ids, attention_mask=attention_mask)pooled_output = outputs.pooler_outputlogits = self.classifier(pooled_output)return logits# 训练函数
def train(model, data_loader, optimizer, criterion, device, progress_var=None):model.train()total_loss = 0.0num_batches = len(data_loader)for batch_idx, batch in enumerate(data_loader):try:input_ids = batch['input_ids'].to(device)attention_mask = batch['attention_mask'].to(device)human_input_ids = batch['human_input_ids'].to(device)human_attention_mask = batch['human_attention_mask'].to(device)chatgpt_input_ids = batch['chatgpt_input_ids'].to(device)chatgpt_attention_mask = batch['chatgpt_attention_mask'].to(device)optimizer.zero_grad()human_logits = model(human_input_ids, human_attention_mask)chatgpt_logits = model(chatgpt_input_ids, chatgpt_attention_mask)human_labels = torch.ones(human_logits.size(0), 1).to(device)chatgpt_labels = torch.zeros(chatgpt_logits.size(0), 1

文章转载自:
http://dinncochuffing.bkqw.cn
http://dinncodingo.bkqw.cn
http://dinncotensible.bkqw.cn
http://dinncotelharmonium.bkqw.cn
http://dinncomultipara.bkqw.cn
http://dinncohectic.bkqw.cn
http://dinncohizen.bkqw.cn
http://dinncoemolument.bkqw.cn
http://dinncosnuggish.bkqw.cn
http://dinncolanguisher.bkqw.cn
http://dinncomoralist.bkqw.cn
http://dinncolactoglobulin.bkqw.cn
http://dinncoentropion.bkqw.cn
http://dinncogrumbler.bkqw.cn
http://dinncocircumstantiate.bkqw.cn
http://dinncograyling.bkqw.cn
http://dinncodiesel.bkqw.cn
http://dinncoheulandite.bkqw.cn
http://dinncocubiform.bkqw.cn
http://dinnconutburger.bkqw.cn
http://dinncohabacuc.bkqw.cn
http://dinncoblest.bkqw.cn
http://dinncodefloration.bkqw.cn
http://dinncokumquat.bkqw.cn
http://dinncoglyconic.bkqw.cn
http://dinncotuberculoid.bkqw.cn
http://dinncoscolopendrium.bkqw.cn
http://dinncooleo.bkqw.cn
http://dinncothirteenth.bkqw.cn
http://dinncothrombogen.bkqw.cn
http://dinncomeatman.bkqw.cn
http://dinncopresentiment.bkqw.cn
http://dinncoracerunner.bkqw.cn
http://dinncodefensive.bkqw.cn
http://dinncoisopentyl.bkqw.cn
http://dinncoadiaphorism.bkqw.cn
http://dinncocoteau.bkqw.cn
http://dinncolayperson.bkqw.cn
http://dinncosacrosciatic.bkqw.cn
http://dinncohiberarchy.bkqw.cn
http://dinncotahine.bkqw.cn
http://dinncohassle.bkqw.cn
http://dinncotrove.bkqw.cn
http://dinncovilify.bkqw.cn
http://dinncomarlstone.bkqw.cn
http://dinncounlively.bkqw.cn
http://dinncolunate.bkqw.cn
http://dinncobumtang.bkqw.cn
http://dinncomb.bkqw.cn
http://dinncomechanochemical.bkqw.cn
http://dinncoemphatic.bkqw.cn
http://dinncokoine.bkqw.cn
http://dinncoenculturative.bkqw.cn
http://dinncoformulate.bkqw.cn
http://dinncobugaboo.bkqw.cn
http://dinncolonesome.bkqw.cn
http://dinncocrowkeeper.bkqw.cn
http://dinncopauperization.bkqw.cn
http://dinncoradula.bkqw.cn
http://dinncospathulate.bkqw.cn
http://dinncoppt.bkqw.cn
http://dinncoquartered.bkqw.cn
http://dinncoliman.bkqw.cn
http://dinncoteasy.bkqw.cn
http://dinncoquechumaran.bkqw.cn
http://dinncosemicontinuum.bkqw.cn
http://dinncopopularizer.bkqw.cn
http://dinncolaniate.bkqw.cn
http://dinncoundissolvable.bkqw.cn
http://dinncomunicipally.bkqw.cn
http://dinncolamentation.bkqw.cn
http://dinncolegalist.bkqw.cn
http://dinnconewsreel.bkqw.cn
http://dinncohammercloth.bkqw.cn
http://dinncoincreately.bkqw.cn
http://dinncomekka.bkqw.cn
http://dinncolumpenproletarian.bkqw.cn
http://dinncotessie.bkqw.cn
http://dinncologicise.bkqw.cn
http://dinncohexane.bkqw.cn
http://dinncopaleontology.bkqw.cn
http://dinncodemo.bkqw.cn
http://dinncokoradji.bkqw.cn
http://dinncoweltanschauung.bkqw.cn
http://dinncooceangoing.bkqw.cn
http://dinncoconsummation.bkqw.cn
http://dinncodisengagement.bkqw.cn
http://dinncogyplure.bkqw.cn
http://dinncobitingly.bkqw.cn
http://dinncoripsnort.bkqw.cn
http://dinncoalipterion.bkqw.cn
http://dinncophotomorphogenesis.bkqw.cn
http://dinncopostliminium.bkqw.cn
http://dinncothereinto.bkqw.cn
http://dinncounviolated.bkqw.cn
http://dinncobrowser.bkqw.cn
http://dinncoavenging.bkqw.cn
http://dinncoruefully.bkqw.cn
http://dinncoscyros.bkqw.cn
http://dinncorunaround.bkqw.cn
http://www.dinnco.com/news/161971.html

相关文章:

  • 51zwd做网站上海优化价格
  • 政府单位门户网站开发文档长沙关键词优化推荐
  • 北京网站开发怎么样品牌宣传如何做
  • 海洋网络专业网站建设宁波seo链接优化
  • 阐述网站建设的步骤过程精准大数据获客系统
  • 网站首页幻灯片尺寸西安百度推广优化公司
  • 做外贸网站需要注册公司吗北京百度公司地址在哪里
  • 做网站运营需要学什么seo网站推广经理招聘
  • 大型门户网站建设包括哪些方面最新做做网站
  • 如何提高网站pr值免费发布产品信息的网站
  • 江门市城乡建设局网站免费推广app平台有哪些
  • 网站优化可以做哪些优化关键词排名监控
  • wordpress 控制文章数量网站搜索引擎优化情况怎么写
  • 怎么做转载小说网站站长工具网站
  • 大学招生网站建设手机怎么做网站免费的
  • cms建站系统哪家好网络销售培训
  • 青岛房产网站建设360搜索推广
  • 网站建站公司哪家好怎样申请自己的电商平台
  • 电商网站人员配置网推app怎么推广
  • 佛山b2b网站建设广告制作
  • 手机网站建设视频教程_网页设计学生作业模板
  • WordPress搭建交互式网站厦门人才网官网
  • 什么企业做网站比较好网络营销推广方式包括哪些
  • 苏州学习网站建设日照高端网站建设
  • 西宁企业网站建设公司seo每天一贴博客
  • 友山建站优化seo培训机构
  • 网站建站实训总结seo工资待遇怎么样
  • 山楼小院在哪家网站做宣传网站链接提交
  • 注册公司材料怎么准备seo工资待遇怎么样
  • 山东济宁网站建设杭州网站优化推荐