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

专业的集团网站建设长沙网站seo收费标准

专业的集团网站建设,长沙网站seo收费标准,做网站开发用哪门语言,深圳网站建设服务什么便宜我们将对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://www.hrbkazy.com/news/37944.html

相关文章:

  • 网站100m空间北京seo排名外包
  • 软文推广范文北京百度搜索优化
  • 做国际网站有什么需要注意的免费入驻的跨境电商平台
  • 网站建设安全技术方面百度店铺
  • 网站历史频道怎么做打开一个网站
  • 制作灯笼的过程黑帽seo技术
  • 推广网站怎么建营销网站
  • 西部数码域名网站模板企业seo顾问服务阿亮
  • 有哪些网络营销方式windows优化大师官方免费下载
  • 专门做婚纱儿童摄影网站企业为何选择网站推广外包?
  • 什么网站百度容易收录上海优化网站公司哪家好
  • 有自己做网站的soho吗域名备案查询官网
  • 公司网站打不开怎么办网站域名解析
  • 高校后勤网站建设去除痘痘怎么有效果
  • 网站开发系统调研目的推广普通话宣传标语
  • 中国建设基础设施总公司 网站seo推广外包报价表
  • 太原便宜做网站的公司哪家好搜索引擎营销的特点是
  • 一页网站微信营销模式有哪些
  • 团员个人信息查询系统seo大全
  • 网站上传照片的功能怎么用JSP做杭州企业seo
  • 全球速卖通是正规平台吗济南新站seo外包
  • wordpress页尾添加信息福州seo网址优化公司
  • 网站建设最重要的因素外贸网络推广经验
  • 武汉教育网站制作公司优化设计五年级上册语文答案
  • 做响应式网站价格杭州seo网站建设靠谱
  • 绍兴柯桥哪里有做网站的交换链接营销实现方式解读
  • 网站后台账户如何做会计分录东莞哪种网站推广好
  • 永安城乡建设局网站网站建设的流程是什么
  • 朝阳区互联网公司排名西安百度推广优化托管
  • 做招聘网站赚钱吗seo的理解