Browse Source

第一次提交

main
majiahui@haimaqingfan.com 2 years ago
parent
commit
da9c1a383e
  1. 66
      New Folder/configuration_baichuan.py
  2. 18
      baichaun_13B_chat_predict.py
  3. 30
      ceshi_tonkes.py
  4. 41
      config_llama_api.py
  5. 9
      data/dataset_info.json
  6. 22
      deepspeed_v2.json
  7. 34
      deepspeed_v3.json
  8. 503
      gen_paper.py
  9. 30
      llama_to_hf.py
  10. 99
      predict_baichuan.py
  11. 212
      predict_llama.py
  12. 1
      predict_vllm.py
  13. 62
      request_10_paper.py
  14. 80
      requirements.txt
  15. 1
      run_train_freeze_llama.sh
  16. 4
      src/utils/common.py
  17. 15
      train_freeze.py
  18. 19
      train_freeze.sh
  19. 19
      train_freeze_baichuan_7b.sh
  20. 21
      train_freeze_deepspeed.sh
  21. 829
      生成英文写作数据.py

66
New Folder/configuration_baichuan.py

@ -0,0 +1,66 @@
# coding=utf-8
# Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
#
# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
# and OPT implementations in this library. It has been modified from its
# original forms to accommodate minor architectural differences compared
# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
#
# 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.
from transformers.configuration_utils import PretrainedConfig
from transformers.utils import logging
logger = logging.get_logger(__name__)
class BaiChuanConfig(PretrainedConfig):
model_type = "baichuan"
keys_to_ignore_at_inference = ["past_key_values"]
def __init__(
self,
vocab_size=64000,
hidden_size=4096,
intermediate_size=11008,
num_hidden_layers=32,
num_attention_heads=32,
hidden_act="silu",
max_position_embeddings=4096,
initializer_range=0.02,
rms_norm_eps=1e-6,
use_cache=True,
pad_token_id=0,
bos_token_id=1,
eos_token_id=2,
tie_word_embeddings=False,
**kwargs,
):
self.vocab_size = vocab_size
self.max_position_embeddings = max_position_embeddings
self.hidden_size = hidden_size
self.intermediate_size = intermediate_size
self.num_hidden_layers = num_hidden_layers
self.num_attention_heads = num_attention_heads
self.hidden_act = hidden_act
self.initializer_range = initializer_range
self.rms_norm_eps = rms_norm_eps
self.use_cache = use_cache
super().__init__(
pad_token_id=pad_token_id,
bos_token_id=bos_token_id,
eos_token_id=eos_token_id,
tie_word_embeddings=tie_word_embeddings,
**kwargs,
)

18
baichaun_13B_chat_predict.py

@ -0,0 +1,18 @@
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "2,3"
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation.utils import GenerationConfig
model_path = "/home/majiahui/project/models-llm/Baichuan-13B-Chat"
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=False, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto", torch_dtype=torch.float16, trust_remote_code=True)
model.generation_config = GenerationConfig.from_pretrained(model_path)
messages = []
# messages.append({"role": "user", "content": "把下面这段翻译成英文\n研究背景:\n\n随着全球能源需求的不断增加和化石燃料的日益枯竭,新能源技术的研究和应用已经成为全球性的热点问题。其中,燃料电池作为一种高效、清洁、可再生的新能源技术,已经成为国际上研究的热点之一。而其中,高温质子交换膜燃料电池(HT-PEMFC)由于具有高能量密度、高效率、低污染等优点,被广泛应用于航空航天、汽车、家庭等领域。\n\n然而,HT-PEMFC在启动过程中存在着一定的困难。由于燃料电池的运行需要一定的温度和湿度条件,因此在启动时需要先加热和湿化电池,以达到运行所需的条件。而传统的加热和湿化方法需要较长的时间,且能量消耗较大,因此需要寻找一种快速启动的方法,以提高燃料电池的运行效率和可靠性。\n\n研究意义:\n\n本研究旨在探究一种快速启动HT-PEMFC的方法,以提高其运行效率和可靠性。具体而言,本研究将采用仿真方法,研究在不同的温度和湿度条件下,利用燃料电池的内部能量来快速启动电池的可行性和效果,并分析其影响因素和优化方案。\n\n本研究的意义在于:\n\n1. 提高HT-PEMFC的运行效率和可靠性。采用快速启动方法可以减少启动时间和能量消耗,提高燃料电池的运行效率和可靠性。\n\n2. 探索新的启动方法。传统的加热和湿化方法存在能量消耗大、启动时间长等缺点,因此本研究探索一种新的快速启动方法,为燃料电池的应用提供新的思路和方法。\n\n3. 为燃料电池的应用提供技术支持。燃料电池作为一种新能源技术,其应用前景广阔。本研究为燃料电池的应用提供技术支持,有利于推动其产业化和普及。\n"})
messages.append({"role": "user", "content": ""})
response = model.chat(tokenizer, messages)
print(response)

30
ceshi_tonkes.py

File diff suppressed because one or more lines are too long

41
config_llama_api.py

@ -0,0 +1,41 @@
import math
class Config:
def __init__(self):
# 目录提取拼接相关参数
self.pantten_second_biaoti = '[2二ⅡⅠ][、.]\s{0,}?[\u4e00-\u9fa5]+'
self.pantten_other_biaoti = '[2-9二三四五六七八九ⅡⅢⅣⅤⅥⅦⅧⅨ][、.]\s{0,}?[\u4e00-\u9fa5]+'
self.pantten_biaoti = '[1-9一二三四五六七八九ⅠⅡⅢⅣⅤⅥⅦⅧⅨ][、.]\s{0,}?[\u4e00-\u9fa5a-zA-Z]+'
# chatgpt 接口相关参数
self.mulu_prompt = "生成目录#\n问:为论文题目《{}》生成目录,要求只有一级标题和二级标题,一级标题使用中文数字 例如一、xxx;二级标题使用阿拉伯数字 例如1.1 xxx;一级标题不少于7个;每个一级标题至少包含3个二级标题\n答:\n"
self.first_title_prompt = "生成论文小标题内容#\n问:论文题目是《{}》,目录是“{}”,请把其中的大标题“{}”的内容补充完整,补充内容字数在{}字左右\n答:\n"
self.small_title_prompt = "生成论文小标题内容#\n问:论文题目是《{}》,目录是“{}”,请把其中的小标题“{}”的内容补充完整,补充内容字数在{}字左右\n答:\n"
self.references_prompt = "论文题目是“{}”,目录是“{}”,请为这篇论文生成15篇左右的参考文献,要求其中有有中文参考文献不低于12篇,英文参考文献不低于2篇"
self.thank_prompt = "请以“{}”为题写一篇论文的致谢"
self.kaitibaogao_prompt = "请以《{}》为题目生成研究的主要的内容、背景、目的、意义,要求不少于1500字"
self.chinese_abstract_prompt = "生成论文摘要#\n"
self.english_abstract_prompt = "请把“{}”这段文字翻译成英文"
self.chinese_keyword_prompt = "请为“{}”这段论文摘要生成3-5个关键字"
self.english_keyword_prompt = "请把“{}”这几个关键字翻译成英文"
self.dabiaoti = ["", "", "", "", "", "", "", ""]
self.project_data_txt_path = "/home/majiahui/project2/LLaMA-Efficient-Tuning/new_data_txt_1"
# 流程相关参数
self.thanks = "致谢"
self.references = "参考文献"
self.excursus = "附录"
self.u = 3.5 # 均值μ
self.sig = math.sqrt(6.0)
self.zong_gradient = 6
self.paper_word_count = 12000
# flask port
self.flask_port = "14003"
# redis config
self.reids_ip = '192.168.31.145'
self.reids_port = 6379
self.reids_db = 7
self.reids_password = 'Zhicheng123*'

9
data/dataset_info.json

@ -103,5 +103,14 @@
"response": "",
"history": ""
}
},
"paper_data_v3_prompt": {
"file_name": "chatglm_train_3_prompt_llama.json"
},
"paper_data_v4_prompt": {
"file_name": "chatglm_train_4_prompt_llama.json"
},
"paper_data_v6_prompt": {
"file_name": "chatglm_train_6_prompt_llama.json"
}
}

22
deepspeed_v2.json

@ -0,0 +1,22 @@
{
"train_micro_batch_size_per_gpu": "auto",
"gradient_accumulation_steps": "auto",
"zero_allow_untested_optimizer": true,
"fp16": {
"enabled": true,
"loss_scale": 0,
"initial_scale_power": 16,
"loss_scale_window": 1000,
"hysteresis": 2,
"min_loss_scale": 1
},
"zero_optimization": {
"stage": 2,
"allgather_partitions": true,
"allgather_bucket_size": 1e5,
"overlap_comm": false,
"reduce_scatter": true,
"reduce_bucket_size": 1e5,
"contiguous_gradients" : true
}
}

34
deepspeed_v3.json

@ -0,0 +1,34 @@
{
"gradient_accumulation_steps": "auto",
"train_micro_batch_size_per_gpu": "auto",
"prescale_gradients": false,
"zero_allow_untested_optimizer": true,
"optimizer": {
"type": "AdamW",
"params": {
"lr": "auto",
"eps": "auto",
"betas": "auto",
"weight_decay": "auto"
}
},
"tensorboard": {
"enabled": true,
"output_path": "logs/",
"job_name": "openbuddy_llama-7b-pt"
},
"zero_optimization": {
"stage": 3,
"contiguous_gradients": false,
"allgather_bucket_size": 3e8,
"reduce_bucket_size": 3e8,
"overlap_comm": true,
"reduce_scatter": true
},
"steps_per_print": 16,
"gradient_clipping": 1.0,
"wall_clock_breakdown": true,
"bf16": {
"enabled": true
}
}

503
gen_paper.py

@ -0,0 +1,503 @@
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
from flask import Flask, jsonify
from flask import request
# from linshi import autotitle
import requests
import redis
import uuid
import json
from threading import Thread
import time
import re
import logging
from config_llama_api import Config
import numpy as np
import math
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
import torch
config = Config()
# model_path = '/home/majiahui/models-LLM/openbuddy-llama-7b-finetune'
# model_path = '/home/majiahui/models-LLM/openbuddy-openllama-7b-v5-fp16'
# model_path = '/home/majiahui/models-LLM/baichuan-vicuna-chinese-7b'
model_path = '/home/majiahui/models-LLM/openbuddy-llama-7b-finetune'
model = AutoModelForCausalLM.from_pretrained(
model_path,
device_map="auto",
trust_remote_code=True,
torch_dtype=torch.float16
# torch_dtype=torch.bfloat16
)
tokenizer = AutoTokenizer.from_pretrained(model_path,use_fast=False)
WEIGHTS_NAME = "adapter_model.bin"
checkpoint_dir = "/home/majiahui/project2/LLaMA-Efficient-Tuning/path_to_sft_checkpoint_paper_prompt_freeze_checkpoint_new_48000/checkpoint-16000"
weights_file = os.path.join(checkpoint_dir, WEIGHTS_NAME)
assert os.path.exists(weights_file), f"Provided path ({checkpoint_dir}) does not contain the pretrained weights."
model_state_dict = torch.load(weights_file, map_location="cuda")
model.load_state_dict(model_state_dict, strict=False) # skip missing keys
model = model.cuda()
redis_title = "redis_title"
pool = redis.ConnectionPool(host=config.reids_ip, port=config.reids_port, max_connections=50, db=config.reids_db)
redis_ = redis.Redis(connection_pool=pool, decode_responses=True)
app = Flask(__name__)
app.config["JSON_AS_ASCII"] = False
# mulu_prompt = "为论文题目“{}”生成目录,要求只有一级标题和二级标题,一级标题使用中文数字 例如一、xxx;二级标题使用阿拉伯数字 例如1.1 xxx;一级标题不少于7个;每个一级标题至少包含3个二级标题"
# first_title_prompt = "论文题目是“{}”,目录是“{}”,请把其中的大标题“{}”的内容补充完整,补充内容字数在{}字左右"
# small_title_prompt = "论文题目是“{}”,目录是“{}”,请把其中的小标题“{}”的内容补充完整,补充内容字数在{}字左右"
# references_prompt = "论文题目是“{}”,目录是“{}”,请为这篇论文生成15篇左右的参考文献,要求其中有有中文参考文献不低于12篇,英文参考文献不低于2篇"
# thank_prompt = "请以“{}”为题写一篇论文的致谢"
# kaitibaogao_prompt = "请以《{}》为题目生成研究的主要的内容、背景、目的、意义,要求不少于1500字"
# chinese_abstract_prompt = "请以《{}》为题目生成论文摘要,要求生成的字数在600字左右"
# english_abstract_prompt = "请把“{}”这段文字翻译成英文"
# chinese_keyword_prompt = "请为“{}”这段论文摘要生成3-5个关键字,使用阿拉伯数字作为序号标注,例如“1.xxx \\n2.xxx \\n3.xxx \\n4.xxx \\n5.xxx \\n"
# english_keyword_prompt = "请把“{}”这几个关键字翻译成英文"
def normal_distribution(x):
y = np.exp(-(x - config.u) ** 2 / (2 * config.sig ** 2)) / (math.sqrt(2 * math.pi) * config.sig)
return y
def request_chatglm(prompt):
do_sample = False
top_p = 0.7
temperature = 0.9
gen_kwargs = {"do_sample": do_sample, "top_p": top_p,
"temperature": temperature}
input_ids = tokenizer.encode(prompt, return_tensors='pt').to('cuda')
# input_txt_list = [prompt1,prompt2,prompt3]
#
# input_ids = tokenizer.batch_encode_plus(input_txt_list, return_tensors="pt",padding=True)["input_ids"].to('cuda')
# print(input_ids)
with torch.no_grad():
output_ids = model.generate(
input_ids=input_ids,
max_new_tokens=2000,
eos_token_id=tokenizer.eos_token_id,
**gen_kwargs
)
# print(output_ids)
output_ids = output_ids.tolist()
response = tokenizer.decode(output_ids[0][len(input_ids[0]):], skip_special_tokens=True)
return response
def chat_kaitibaogao(main_parameter):
response = request_chatglm(config.kaitibaogao_prompt.format(main_parameter[0]))
return response
def chat_abstract_keyword(main_parameter):
# 生成中文摘要
chinese_abstract = request_chatglm(config.chinese_abstract_prompt.format(main_parameter[0]))
# 生成英文的摘要
english_abstract = request_chatglm(config.english_abstract_prompt.format(chinese_abstract))
# 生成中文关键字
chinese_keyword = request_chatglm(config.chinese_keyword_prompt.format(chinese_abstract))
# 生成英文关键字
english_keyword = request_chatglm(config.english_keyword_prompt.format(chinese_keyword))
paper_abstract_keyword = {
"中文摘要": chinese_abstract,
"英文摘要": english_abstract,
"中文关键词": chinese_keyword,
"英文关键词": english_keyword
}
return paper_abstract_keyword
def chat_content(main_parameter):
'''
:param api_key:
:param uuid:
:param main_parameter:
:return:
'''
content_index = main_parameter[0]
title = main_parameter[1]
mulu = main_parameter[2]
subtitle = main_parameter[3]
prompt = main_parameter[4]
word_count = main_parameter[5]
if subtitle[:2] == "@@":
response = subtitle[2:]
else:
response = request_chatglm(prompt.format(title, mulu, subtitle, word_count))
if subtitle not in response:
response = subtitle + "\n" + response
print(prompt.format(title, mulu, subtitle, word_count), response)
return response
def chat_thanks(main_parameter):
'''
:param api_key:
:param uuid:
:param main_parameter:
:return:
'''
# title,
# thank_prompt
title = main_parameter[0]
prompt = main_parameter[1]
response = request_chatglm(prompt.format(title))
return response
def chat_references(main_parameter):
'''
:param api_key:
:param uuid:
:param main_parameter:
:return:
'''
# title,
# mulu,
# references_prompt
title = main_parameter[0]
mulu = main_parameter[1]
prompt = main_parameter[2]
response = request_chatglm(prompt.format(title, mulu))
# 加锁 读取resis并存储结果
return response
def small_title_tesk(small_title):
'''
顺序读取子任务
:return:
'''
task_type = small_title["task_type"]
main_parameter = small_title["main_parameter"]
# "task_type": "paper_content",
# "uuid": uuid,
# "main_parameter": [
# "task_type": "paper_content",
# "task_type": "chat_abstract",
# "task_type": "kaitibaogao",
if task_type == "kaitibaogao":
# result = chat_kaitibaogao(main_parameter)
result = ""
elif task_type == "chat_abstract":
# result= chat_abstract_keyword(main_parameter)
result = ""
elif task_type == "paper_content":
result = chat_content(main_parameter)
elif task_type == "thanks_task":
# result = chat_thanks(main_parameter)
result = ""
elif task_type == "references_task":
# result = chat_references(main_parameter)
result = ""
else:
result = ""
print(result, task_type, main_parameter)
return result, task_type
def main_prrcess(title):
mulu = request_chatglm(config.mulu_prompt.format(title))
mulu_list = mulu.split("\n")
mulu_list = [i.strip() for i in mulu_list if i != ""]
# mulu_str = "@".join(mulu_list)
mulu_list_bool = []
for i in mulu_list:
result_biaoti_list = re.findall(config.pantten_biaoti, i)
if result_biaoti_list != []:
mulu_list_bool.append((i, "一级标题"))
else:
mulu_list_bool.append((i, "二级标题"))
mulu_list_bool_part = mulu_list_bool[:3]
if mulu_list_bool_part[0][1] != "一级标题":
redis_.lpush(redis_title, json.dumps({"id": uuid, "title": title}, ensure_ascii=False)) # 加入redis
redis_.persist(redis_title)
return
if mulu_list_bool_part[0][1] == mulu_list_bool_part[1][1] == mulu_list_bool_part[2][1] == "一级标题":
redis_.lpush(redis_title, json.dumps({"id": uuid, "title": title}, ensure_ascii=False)) # 加入redis
redis_.persist(redis_title)
return
table_of_contents = []
thanks_references_bool_table = mulu_list_bool[-5:]
# thanks = "致谢"
# references = "参考文献"
for i in thanks_references_bool_table:
if config.references in i[0]:
mulu_list_bool.remove(i)
if config.thanks in i[0]:
mulu_list_bool.remove(i)
if config.excursus in i[0]:
mulu_list_bool.remove(i)
title_key = ""
# for i in mulu_list_bool:
# if i[1] == "一级标题":
# table_of_contents["@@" + i[0]] = []
# title_key = "@@" + i[0]
# else:
# table_of_contents[title_key].append(i[0])
for i in mulu_list_bool:
if i[1] == "一级标题":
paper_dan = {
"title": "@@" + i[0],
"small_title": [],
"word_count": 0
}
table_of_contents.append(paper_dan)
else:
table_of_contents[-1]["small_title"].append(i[0])
x_list = [0]
y_list = [normal_distribution(0)]
gradient = config.zong_gradient / len(table_of_contents)
for i in range(len(table_of_contents) - 1):
x_gradient = x_list[-1] + gradient
x_list.append(x_gradient)
y_list.append(normal_distribution(x_list[-1]))
dan_gradient = config.paper_word_count / sum(y_list)
for i in range(len(y_list)):
table_of_contents[i]["word_count"] = dan_gradient * y_list[i]
print(table_of_contents)
print(len(table_of_contents))
table_of_contents_new = []
for dabiaoti_index in range(len(table_of_contents)):
dabiaoti_dict = table_of_contents[dabiaoti_index]
table_of_contents_new.append([dabiaoti_dict["title"], 0])
for xiaobiaoti in dabiaoti_dict["small_title"]:
table_of_contents_new.append(
[xiaobiaoti, int(dabiaoti_dict["word_count"] / len(dabiaoti_dict["small_title"]))])
small_task_list = []
# api_key,
# index,
# title,
# mulu,
# subtitle,
# prompt
kaitibaogao_task = {
"task_type": "kaitibaogao",
"uuid": uuid,
"main_parameter": [title]
}
chat_abstract_task = {
"task_type": "chat_abstract",
"uuid": uuid,
"main_parameter": [title]
}
small_task_list.append(kaitibaogao_task)
small_task_list.append(chat_abstract_task)
content_index = 0
while True:
if content_index == len(table_of_contents_new):
break
subtitle, word_count = table_of_contents_new[content_index]
prompt = config.small_title_prompt
print(table_of_contents_new[1][0])
if content_index == 0 and table_of_contents_new[1][0][:2] == "@@" and subtitle[:2] == "@@":
subtitle, prompt, word_count = subtitle[2:], config.first_title_prompt, 800
if content_index == len(table_of_contents_new) - 1 and subtitle[:2] == "@@":
subtitle, prompt, word_count = subtitle[2:], config.first_title_prompt, 800
print("请求的所有参数",
content_index,
title,
subtitle,
prompt,
word_count)
paper_content = {
"task_type": "paper_content",
"uuid": uuid,
"main_parameter": [
content_index,
title,
mulu,
subtitle,
prompt,
word_count
]
}
small_task_list.append(paper_content)
content_index += 1
thanks_task = {
"task_type": "thanks_task",
"uuid": uuid,
"main_parameter": [
title,
config.thank_prompt
]
}
references_task = {
"task_type": "references_task",
"uuid": uuid,
"main_parameter": [
title,
mulu,
config.references_prompt
]
}
small_task_list.append(thanks_task)
small_task_list.append(references_task)
res = {
"num_small_task": len(small_task_list),
"tasking_num": 0,
"标题": title,
"目录": mulu,
"开题报告": "",
"任务书": "",
"中文摘要": "",
"英文摘要": "",
"中文关键词": "",
"英文关键词": "",
"正文": "",
"致谢": "",
"参考文献": "",
"table_of_contents": [""] * len(table_of_contents_new)
}
for small_task in small_task_list:
result, task_type = small_title_tesk(small_task)
if task_type == "kaitibaogao":
res["开题报告"] = result
elif task_type == "chat_abstract":
for i in result:
res[i] = result[i]
elif task_type == "paper_content":
content_index = small_task["main_parameter"][0]
res["table_of_contents"][content_index] = result
elif task_type == "thanks_task":
res["致谢"] = result
elif task_type == "references_task":
res["参考文献"] = result
return res
def classify(): # 调用模型,设置最大batch_size
while True:
if redis_.llen(redis_title) == 0: # 若队列中没有元素就继续获取
time.sleep(3)
continue
query = redis_.lpop(redis_title).decode('UTF-8') # 获取query的text
query = json.loads(query)
uuid = query['id']
texts = query["text"]
response = main_prrcess(texts)
print("res", response)
return_text = str({"texts": response, "probabilities": None, "status_code": 200})
uuid_path = os.path.join(config.project_data_txt_path, uuid)
os.makedirs(uuid_path)
paper_content_path = os.path.join(uuid_path, "paper_content.json")
print(uuid)
with open(paper_content_path, "w") as outfile:
json.dump(response, outfile)
save_word_paper = os.path.join(uuid_path, "paper.docx")
save_word_paper_start = os.path.join(uuid_path, "paper_start.docx")
os.system(
"java -Dfile.encoding=UTF-8 -jar '/home/majiahui/projert/chatglm/aiXieZuoPro.jar' '{}' '{}' '{}'".format(
paper_content_path,
save_word_paper,
save_word_paper_start))
redis_.set(uuid, return_text, 28800)
@app.route("/predict", methods=["POST"])
def handle_query():
print(request.remote_addr)
texts = request.json["texts"]
if texts is None:
return_text = {"texts": "输入了空值", "probabilities": None, "status_code": 402}
return jsonify(return_text)
id_ = str(uuid.uuid1()) # 为query生成唯一标识
d = {'id': id_, 'text': texts} # 绑定文本和query id
redis_.rpush(redis_title, json.dumps(d)) # 加入redis
while True:
result = redis_.get(id_) # 获取该query的模型结果
if result is not None:
result_text = {'code': "200", 'data': result.decode('UTF-8')}
break
else:
time.sleep(1)
return jsonify(result_text) # 返回结果
t = Thread(target=classify)
t.start()
if __name__ == "__main__":
fh = logging.FileHandler(mode='a', encoding='utf-8', filename='chitchat.log')
logging.basicConfig(
handlers=[fh],
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
)
app.run(host="0.0.0.0", port=15000, threaded=True, debug=False)

30
llama_to_hf.py

@ -0,0 +1,30 @@
import os
import sys
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
if __name__ == "__main__":
exportPath = sys.argv[1] if (sys.argv[1] is not None) else "baichuan-fp32.flm"
model_path = '/home/majiahui/project/models-llm/openbuddy-llama-7b-v1.4-fp16'
model = AutoModelForCausalLM.from_pretrained(
model_path,
device_map="auto",
trust_remote_code=True,
torch_dtype=torch.float16
# torch_dtype=torch.bfloat16
)
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=False)
# special_tokens_dict = {"pad_token": "<unk>"}
# tokenizer.add_special_tokens(special_tokens_dict)
WEIGHTS_NAME = "adapter_model.bin"
checkpoint_dir = "/home/majiahui/project/LLaMA-Efficient-Tuning/path_to_sft_openbuddy_llama_paper_checkpoint_prompt_freeze_checkpoint/checkpoint-168000"
weights_file = os.path.join(checkpoint_dir, WEIGHTS_NAME)
assert os.path.exists(weights_file), f"Provided path ({checkpoint_dir}) does not contain the pretrained weights."
model_state_dict = torch.load(weights_file, map_location="cuda")
model.load_state_dict(model_state_dict, strict=False) # skip missing keys
device = torch.device("cpu")
model = model.to(device)
model.save_pretrained(exportPath)

99
predict_baichuan.py

@ -0,0 +1,99 @@
import os
import torch
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
import time
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = "/home/majiahui/models-LLM/baichuan-7B"
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto", trust_remote_code=True, torch_dtype=torch.float16)
WEIGHTS_NAME = "adapter_model.bin"
checkpoint_dir = "/home/majiahui/project2/LLaMA-Efficient-Tuning/path_to_sft_checkpoint_paper_prompt_freeze_baichuan/checkpoint-23000"
weights_file = os.path.join(checkpoint_dir, WEIGHTS_NAME)
assert os.path.exists(weights_file), f"Provided path ({checkpoint_dir}) does not contain the pretrained weights."
model_state_dict = torch.load(weights_file, map_location="cpu")
model.load_state_dict(model_state_dict, strict=False) # skip missing keys
model = model.cuda()
# prompt = '''论文题目是“马克思恩格斯婚姻家庭观及当代价值研究”,目录是“一、引言\\n\\n1.1 研究背景\\n\\n1.2 研究意义\\n\\n1.3 研究目的\\n\\n二、马克思恩格斯婚姻家庭观综述\\n\\n2.1 马克思恩格斯婚姻家庭观的形成与发展\\n\\n2.2 马克思恩格斯婚姻家庭观的核心思想\\n\\n2.3 马克思恩格斯婚姻家庭观的现实意义\\n\\n三、马克思恩格斯婚姻家庭观的当代价值\\n\\n3.1 当代婚姻家庭问题的现状\\n\\n3.2 马克思恩格斯婚姻家庭观对当代婚姻家庭问题的启示\\n\\n3.3 马克思恩格斯婚姻家庭观的当代应用价值\\n\\n四、马克思恩格斯婚姻家庭观的局限性及其超越\\n\\n4.1 马克思恩格斯婚姻家庭观的局限性\\n\\n4.2 马克思恩格斯婚姻家庭观的超越\\n\\n4.3 马克思恩格斯婚姻家庭观的未来发展方向\\n\\n五、结论\\n\\n5.1 研究结论\\n\\n5.2 研究不足与展望\\n\\n参考文献”,请把其中的小标题“5.1 研究结论”的内容补充完整,补充内容字数在700字左右
# '''
# prompt = "帮我写一个请假条"
# prompt = "生成论文小标题内容#论文题目是“大学生村官管理研究”,目录是“一、大学生村官管理现状分析\\n1.1 村官数量及分布情况\\n1.2 村官岗位设置及职责\\n1.3 村官工作绩效评估\\n\\n二、大学生村官管理存在的问题\\n2.1 村官队伍结构不合理\\n2.2 村官工作能力不足\\n2.3 村官管理制度不健全\\n\\n三、大学生村官管理对策研究\\n3.1 加强村官队伍建设\\n3.2 提高村官工作能力\\n3.3 完善村官管理制度\\n\\n四、大学生村官管理案例分析\\n4.1 案例一:某村大学生村官工作情况分析\\n4.2 案例二:某村大学生村官管理策略探讨\\n\\n五、大学生村官管理的未来发展趋势\\n5.1 多元化村官队伍建设\\n5.2 信息化村官管理模式\\n5.3 村官职业化发展\\n\\n六、大学生村官管理的政策建议\\n6.1 加强对大学生村官的培训和管理\\n6.2 完善大学生村官管理制度\\n6.3 提高大学生村官的待遇和福利\\n\\n七、结论与展望”,请把其中的小标题“3.3 完善村官管理制度”的内容补充完整,补充内容字数在800字左右"
# prompt = "生成论文小标题内容#论文题目是“埃及申诺达三世时期的科普特人研究”,目录是“一、研究背景和意义\\n1.1 埃及申诺达三世时期的历史背景\\n1.2 科普特人在埃及的历史地位\\n1.3 研究意义和目的\\n\\n二、科普特人的社会生活\\n2.1 科普特人的宗教信仰\\n2.2 科普特人的语言和文化\\n2.3 科普特人的职业和经济状况\\n\\n三、科普特人的艺术和文学\\n3.1 科普特人的绘画和雕塑艺术\\n3.2 科普特人的文学作品\\n3.3 科普特人的音乐和舞蹈艺术\\n\\n四、科普特人的建筑和工程技术\\n4.1 科普特人的建筑风格和特点\\n4.2 科普特人的水利工程和农业技术\\n4.3 科普特人的金属加工和制造技术\\n\\n五、科普特人的医学和药物\\n5.1 科普特人的医学理论和实践\\n5.2 科普特人的药物和草药疗法\\n5.3 科普特人的医疗机构和医疗制度\\n\\n六、科普特人的教育和学术\\n6.1 科普特人的教育体系和教育内容\\n6.2 科普特人的学术研究和学术成就\\n6.3 科普特人的知识传承和学术交流\\n\\n七、科普特人的社会活动和组织\\n7.1 科普特人的社会组织和文化团体\\n7.2 科普特人的慈善和公益活动\\n7.3 科普特人的政治参与和社会影响”,请把其中的小标题“3.2 科普特人的文学作品”的内容补充完整,补充内容字数在1100字左右"
# prompt = "生成目录#论文题目为“基于红细胞分布宽度建立乙肝相关慢加急性肝衰竭不良预后的优化预测模型”,以“研究建立一种基于红细胞分布宽度的乙肝相关慢加急性肝衰竭不良预后的优化预测模型,包括数据收集、特征选择、模型构建等方面的研究。最终成果是验证所设计模型对于乙肝相关慢加急性肝衰竭不良预后的预测能力,并对模型进行优化,提高预测准确性和可靠性。”为论文的研究方向,为论文生成目录,要求只有一级标题和二级标题,一级标题使用中文数字 例如一、xxx;二级标题使用阿拉伯数字 例如1.1 xxx;一级标题不少于7个;每个一级标题至少包含3个二级标题"
prompt = "生成论文小标题内容#论文题目是“多无人艇一致性自主编队控制研究”,目录是“一、引言\\n 1.1 研究背景\\n 1.2 研究意义\\n 1.3 国内外研究现状\\n\\n二、多无人艇编队控制技术综述\\n 2.1 多无人艇编队控制技术分类\\n 2.2 多无人艇编队控制技术研究现状\\n 2.3 多无人艇编队控制技术存在的问题\\n\\n三、多无人艇一致性控制方法研究\\n 3.1 一致性控制方法分类\\n 3.2 多无人艇一致性控制方法研究现状\\n 3.3 多无人艇一致性控制方法存在的问题\\n\\n四、多无人艇一致性自主编队控制方法研究\\n 4.1 自主编队控制方法分类\\n 4.2 多无人艇一致性自主编队控制方法研究现状\\n 4.3 多无人艇一致性自主编队控制方法存在的问题\\n\\n五、多无人艇一致性自主编队控制仿真实验\\n 5.1 实验设计\\n 5.2 实验结果分析\\n 5.3 实验结论\\n\\n六、总结与展望\\n 6.1 研究成果总结\\n 6.2 研究不足与改进方向\\n 6.3 发展前景与应用价值”,请把其中的小标题“3.3 多无人艇一致性控制方法存在的问题”的内容补充完整,补充内容字数在700字左右"
# prompt = "生成论文小标题内容#论文题目是“家庭化流动对流动人口就业的影响”,目录是“一、研究背景和意义\\n1.1 流动人口和家庭化流动的概念\\n1.2 流动人口就业现状分析\\n1.3 家庭化流动的影响因素\\n\\n二、家庭化流动对流动人口就业的影响\\n2.1 家庭化流动对流动人口就业机会的影响\\n2.2 家庭化流动对流动人口就业稳定性的影响\\n2.3 家庭化流动对流动人口就业满意度的影响\\n\\n三、家庭化流动对流动人口就业的政策建议\\n3.1 完善流动人口就业政策\\n3.2 加强家庭化流动人口的社会保障\\n3.3 推进家庭化流动人口的职业培训\\n\\n四、案例分析\\n4.1 湖南省某县家庭化流动人口就业情况分析\\n4.2 广东省某市家庭化流动人口就业政策效果分析\\n4.3 河北省某区家庭化流动人口就业满意度调查\\n\\n五、结论与展望\\n5.1 结论\\n5.2 展望”,请把其中的小标题“3.2 加强家庭化流动人口的社会保障”的内容补充完整,补充内容字数在900字左右"
# prompt = "翻译摘要#请把“本文研究了相干光通信中以太网视频传输系统的关键技术。首先,介绍了相干光通信的基本原理和应用领域,指出了其在高速数据传输中的优势。然后,分析了以太网视频传输系统的特点和需求,包括高带宽、低延迟、高可靠性等。接着,针对传输过程中可能出现的干扰和衰减等问题,提出了多种解决方案,如光纤衰减补偿、信号增强等。此外,还介绍了基于光放大器的信号放大技术和基于光纤光栅的光谱成像技术,以及它们在以太网视频传输系统中的应用。最后,根据系统需求和技术特点,设计了一套完整的以太网视频传输系统,并进行了实验验证。结果表明,该系统具有高带宽、低延迟、高可靠性等优点,可以满足实际应用需求。本文的研究成果对于推动相干光通信技术的发展和应用具有重要意义。”这段文字翻译成英文"
# prompt = "请写出以《列宁军事理论及其在中国的应用与发展研究》为课题的国内外研究状况综述,字数在800字左右"
# prompt = "以“专利间接侵权责任认定制度研究”为论文题目,写一个论文简短总结,要求在300字以内"
# prompt = "请把“1. 老年长期护理模式\\n2. 问题分析\\n3. 解决方案\\n4. 国际比较与分析\\n5. 改进措施”这几个关键字翻译成英文"
# prompt = "请为“本研究旨在探究基于领导成员交换理论的团队绩效。通过对团队成员之间的领导成员交换关系进行分析,研究团队绩效的影响因素。本研究采用问卷调查法,对不同类型的团队进行调查,以了解不同领导成员交换关系对团队绩效的影响。\\n\\n研究结果表明,领导成员交换关系对团队绩效具有显著影响。在高质量的领导成员交换关系下,团队绩效显著提高。此外,团队成员之间的信任程度、沟通效果、合作精神等因素也对团队绩效产生重要影响。\\n\\n本研究还发现,不同类型的团队对领导成员交换关系的需求也不同。在高度协作的团队中,领导成员交换关系对团队绩效的影响更为显著。而在需要高度专业技能的团队中,领导成员交换关系的影响相对较小。\\n\\n综上所述,基于领导成员交换理论的团队绩效研究对于提高团队绩效具有重要意义。在实践中,团队领导者应该注重领导成员交换关系的建立和维护,以提高团队绩效。此外,团队成员之间的信任程度、沟通效果、合作精神等因素也应该得到重视,以促进团队的协作和合作,提高团队绩效。”这段论文摘要生成3-5个关键字,使用阿拉伯数字作为序号标注,例如“1.xxx \\n2.xxx \\n3.xxx \\n4.xxx \\n5.xxx \\n”"
# prompt = "请帮我生成《眼底图像中微小目标检测算法的研究与实现》为题目的研究内容,包括整体简介和分最少三个方面总结"
# prompt = "生成6点本篇论文应完成的主要内容#请根据题目为《ATP软件可靠性混沌预测研究》,和研究内容为“整体简介:\\n本研究旨在探讨ATP软件的可靠性混沌预测方法,以提高软件开发过程中的可靠性和稳定性。通过对ATP软件的历史数据进行分析,结合混沌理论,建立混沌预测模型,以实现对ATP软件可靠性的预测和控制。\\n\\n分三个方面总结:\\n1. 历史数据分析:通过对ATP软件的历史数据进行分析,包括软件开发过程中的各个环节,如需求分析、设计、编码、测试等,以及软件发布后的使用情况,如稳定性、故障率等,分析软件可靠性的影响因素和规律,为后续建立混沌预测模型提供数据支持。\\n\\n2. 混沌预测模型建立:基于ATP软件的历史数据和混沌理论,建立混沌预测模型,通过对历史数据的拟合和验证,优化模型参数,提高预测精度。同时,结合软件开发过程中的实际情况,不断修正和完善模型,以适应不同的软件开发环境和需求。\\n\\n3. 可靠性控制策略实现:基于混沌预测模型,制定可靠性控制策略,包括对软件开发过程中的各个环节进行监控和调整,对软件发布后的使用情况进行实时监测和反馈,及时发现和解决潜在问题,提高软件的可靠性和稳定性。同时,通过对控制策略的不断优化和改进,不断提高软件开发过程中的效率和质量。”总结出至少6点本篇论文应完成的主要内容,使用阿拉伯数字排列"
# prompt = "生成论文摘要#论文题目是“度假型酒店式公寓项目策划研究”,目录是“一、项目概述\\n1.1 项目背景\\n1.2 项目定位\\n1.3 项目规划\\n\\n二、市场调研\\n2.1 目标客群分析\\n2.2 竞争对手分析\\n2.3 市场需求分析\\n\\n三、设计方案\\n3.1 客房设计\\n3.2 公共空间设计\\n3.3 营销策略设计\\n\\n四、运营管理\\n4.1 人员组织架构\\n4.2 运营流程规划\\n4.3 财务预算与管理\\n\\n五、风险分析\\n5.1 市场风险\\n5.2 技术风险\\n5.3 政策风险\\n\\n六、社会效益\\n6.1 社会影响评估\\n6.2 环保建设\\n6.3 社区责任履行\\n\\n七、总结与展望\\n7.1 项目总结\\n7.2 未来发展展望”,生成论文摘要,要求生成的字数在600字左右"
# prompt = "生成目录#为论文题目“试论杭州“西溪”名称的含义、演变及其原因”生成目录,要求只有一级标题和二级标题,一级标题使用中文数字 例如一、xxx;二级标题使用阿拉伯数字 例如1.1 xxx;一级标题不少于7个;每个一级标题至少包含3个二级标题"
# prompt = "生成目录#为论文题目“中西部地区公共就业服务水平省际差距研究”生成目录,要求只有一级标题和二级标题,一级标题使用中文数字 例如一、xxx;二级标题使用阿拉伯数字 例如1.1 xxx;一级标题不少于7个;每个一级标题至少包含3个二级标题"
# prompt = "生成课题的研究背景和意义#请分别写出以《农村小学少先队活动研究》为课题,以“研究农村小学少先队的活动内容、组织方式和效果,探讨如何提高少先队员的思想品德和综合素质。通过实地调研和问卷调查等方法,分析少先队活动的现状和问题,提出相应的改进措施。最终成果是设计出一套适合农村小学少先队开展的活动方案,有效促进少先队员的全面发展和成长。”为论文的研究方向,生成论文的研究背景和意义,字数不少于1000字"
# prompt = "生成论文小标题内容#论文题目是“黄土高原刺槐人工林土壤磷组分及其有效性对穿透雨改变的响应”,目录是“一、绪论\\n1.1 研究背景\\n1.2 研究意义\\n1.3 国内外研究现状\\n\\n二、材料与方法\\n2.1 研究区域及样地选择\\n2.2 采样与处理\\n2.3 土壤理化性质测定\\n2.4 磷组分测定\\n2.5 数据处理方法\\n\\n三、土壤磷组分及其有效性\\n3.1 土壤磷组分特征\\n3.2 土壤磷有效性特征\\n3.3 土壤磷组分与有效性的相关性\\n\\n四、穿透雨对土壤磷组分及其有效性的影响\\n4.1 穿透雨对土壤磷组分的影响\\n4.2 穿透雨对土壤磷有效性的影响\\n4.3 穿透雨对土壤磷组分与有效性的相关性影响\\n\\n五、讨论\\n5.1 黄土高原刺槐人工林土壤磷组分及其有效性的特征\\n5.2 穿透雨对土壤磷组分及其有效性的影响机制\\n5.3 黄土高原刺槐人工林土壤磷管理的建议\\n\\n六、结论\\n\\n七、参考文献”,请把其中的小标题“3.1 土壤磷组分特征”的内容补充完整,补充内容字数在900字左右"
# t1 = time.time()
# for i in range(50):
# print("#####################################################################")
# print(f"## {i}")
# print("#####################################################################")
# res, history = model.chat(tokenizer, prompt, history=[], top_p=0.7, temperature=0.3)
#
# print(res)
# t2 = time.time()
#
# print(t2 -t1)
num_beams = 1
do_sample = True
top_p = 0.7
temperature = 0.95
gen_kwargs = {"num_beams": num_beams, "do_sample": do_sample, "top_p": top_p,
"temperature": temperature}
t1 = time.time()
input_ids = tokenizer.encode([prompt], return_tensors='pt').to('cuda:0')
output_ids = model.generate(
input_ids=input_ids,
max_new_tokens=1400,
eos_token_id=tokenizer.eos_token_id,
**gen_kwargs
)
print(tokenizer.decode(output_ids[0][len(input_ids[0]):], skip_special_tokens=True))
t2 = time.time()
print(t2 -t1)

212
predict_llama.py

@ -0,0 +1,212 @@
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
import torch
from peft import get_peft_model, LoraConfig, TaskType, PeftModel
import time
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
import torch
# model_path = '/home/majiahui/models-LLM/openbuddy-llama-7b-finetune-v1'
# model_path = '/home/majiahui/models-LLM/openbuddy-openllama-7b-v5-fp16'
# model_path = '/home/majiahui/models-LLM/baichuan-vicuna-chinese-7b'
model_path = '/home/majiahui/project/models-llm/openbuddy-llama-7b-v1.4-fp16'
# model_path = "/home/majiahui/project/models-llm/openbuddy-llama-7b-finetune"
model = AutoModelForCausalLM.from_pretrained(
model_path,
device_map="auto",
trust_remote_code=True,
torch_dtype=torch.float16
# torch_dtype=torch.bfloat16
)
tokenizer = AutoTokenizer.from_pretrained(model_path,use_fast=False)
# special_tokens_dict = {"pad_token": "<unk>"}
# tokenizer.add_special_tokens(special_tokens_dict)
# WEIGHTS_NAME = "adapter_model.bin"
# checkpoint_dir = "/home/majiahui/project/LLaMA-Efficient-Tuning/path_to_sft_openbuddy_llama_paper_checkpoint_prompt_freeze_checkpoint/checkpoint-168000"
# weights_file = os.path.join(checkpoint_dir, WEIGHTS_NAME)
# assert os.path.exists(weights_file), f"Provided path ({checkpoint_dir}) does not contain the pretrained weights."
# model_state_dict = torch.load(weights_file, map_location="cuda")
# model.load_state_dict(model_state_dict, strict=False) # skip missing keys
# model = model.cuda()
'''
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_path = 'OpenBuddy/openbuddy-openllama-7b-v5-fp16'
model = AutoModelForCausalLM.from_pretrained(
model_path,
device_map="auto",
trust_remote_code=True,
torch_dtype=torch.float16)
tokenizer = AutoTokenizer.from_pretrained(model_path)
with open('../system.prompt', 'r', encoding='utf-8') as f:
prompt = f.read()
prompt += "\n\nUser: Write a poem about yourself.\nAssistant:"
input_ids = tokenizer.encode(prompt, return_tensors='pt').to('cuda')
with torch.no_grad():
output_ids = model.generate(
input_ids=input_ids,
max_new_tokens=100,
eos_token_id=tokenizer.eos_token_id)
print(tokenizer.decode(output_ids[0], skip_special_tokens=True))
'''
# prompt = '''论文题目是“大型商业建筑人员疏散设计研究”,目录是“一、引言
# 1.1 研究背景
# 1.2 研究意义
# 1.3 研究现状
#
# 二、大型商业建筑人员疏散设计概述
# 2.1 人员疏散设计的定义
# 2.2 人员疏散设计的基本原理
# 2.3 人员疏散设计的主要要素
#
# 三、大型商业建筑人员疏散设计的现状
# 3.1 大型商业建筑人员疏散设计的发展历程
# 3.2 大型商业建筑人员疏散设计的现状
# 3.3 大型商业建筑人员疏散设计存在的问题
#
# 四、大型商业建筑人员疏散设计的实施方法
# 4.1 人员疏散设计的实施流程
# 4.2 人员疏散设计的实施方法
# 4.3 人员疏散设计的实施效果
#
# 五、大型商业建筑人员疏散设计的应用案例分析
# 5.1 案例分析
# 5.2 案例分析的启示
# 5.3 案例分析的优缺点
#
# 六、结论
# 6.1 研究结论
# 6.2 研究展望
#
# 参考文献”,请把其中的小标题“2.1 人员疏散设计的定义”的内容补充完整,补充内容字数在800字左右'''
# prompt = '''论文题目是“马克思恩格斯婚姻家庭观及当代价值研究”,目录是“一、引言\\n\\n1.1 研究背景\\n\\n1.2 研究意义\\n\\n1.3 研究目的\\n\\n二、马克思恩格斯婚姻家庭观综述\\n\\n2.1 马克思恩格斯婚姻家庭观的形成与发展\\n\\n2.2 马克思恩格斯婚姻家庭观的核心思想\\n\\n2.3 马克思恩格斯婚姻家庭观的现实意义\\n\\n三、马克思恩格斯婚姻家庭观的当代价值\\n\\n3.1 当代婚姻家庭问题的现状\\n\\n3.2 马克思恩格斯婚姻家庭观对当代婚姻家庭问题的启示\\n\\n3.3 马克思恩格斯婚姻家庭观的当代应用价值\\n\\n四、马克思恩格斯婚姻家庭观的局限性及其超越\\n\\n4.1 马克思恩格斯婚姻家庭观的局限性\\n\\n4.2 马克思恩格斯婚姻家庭观的超越\\n\\n4.3 马克思恩格斯婚姻家庭观的未来发展方向\\n\\n五、结论\\n\\n5.1 研究结论\\n\\n5.2 研究不足与展望\\n\\n参考文献”,请把其中的小标题“5.1 研究结论”的内容补充完整,补充内容字数在700字左右
# '''
# prompt = "问:帮我写一个请假条\n答:"
# prompt1 = "问:帮我写一个论文题目\n答:"
prompt_en = '''Question: generate the table of contents for the paper title "Research on the Adaptability of Large Class Children under the Connection between Young and Primary Schools", which requires only the first level title and the second level title, and the first level title uses Chinese numerals, such as one, xxx; The secondary title uses Arabic numerals, such as 1.1 xxx; At least 7 first level titles; Each first level title should contain at least 3 second level titles.
Answer:
'''
prompt_0 = "生成目录#\n问:为论文题目《幼小衔接下大班幼儿适应性的研究》生成目录,要求只有一级标题和二级标题,一级标题使用中文数字 例如一、xxx;二级标题使用阿拉伯数字 例如1.1 xxx;一级标题不少于7个;每个一级标题至少包含3个二级标题\n答:\n"
prompt = "生成论文小标题内容#问:论文题目是“大学生村官管理研究”,目录是“一、大学生村官管理现状分析\\n1.1 村官数量及分布情况\\n1.2 村官岗位设置及职责\\n1.3 村官工作绩效评估\\n\\n二、大学生村官管理存在的问题\\n2.1 村官队伍结构不合理\\n2.2 村官工作能力不足\\n2.3 村官管理制度不健全\\n\\n三、大学生村官管理对策研究\\n3.1 加强村官队伍建设\\n3.2 提高村官工作能力\\n3.3 完善村官管理制度\\n\\n四、大学生村官管理案例分析\\n4.1 案例一:某村大学生村官工作情况分析\\n4.2 案例二:某村大学生村官管理策略探讨\\n\\n五、大学生村官管理的未来发展趋势\\n5.1 多元化村官队伍建设\\n5.2 信息化村官管理模式\\n5.3 村官职业化发展\\n\\n六、大学生村官管理的政策建议\\n6.1 加强对大学生村官的培训和管理\\n6.2 完善大学生村官管理制度\\n6.3 提高大学生村官的待遇和福利\\n\\n七、结论与展望”,请把其中的小标题“3.3 完善村官管理制度”的内容补充完整,补充内容字数在800字左右\n答:\n"
#
prompt1 = "生成论文小标题内容#问:论文题目是“埃及申诺达三世时期的科普特人研究”,目录是“一、研究背景和意义\\n1.1 埃及申诺达三世时期的历史背景\\n1.2 科普特人在埃及的历史地位\\n1.3 研究意义和目的\\n\\n二、科普特人的社会生活\\n2.1 科普特人的宗教信仰\\n2.2 科普特人的语言和文化\\n2.3 科普特人的职业和经济状况\\n\\n三、科普特人的艺术和文学\\n3.1 科普特人的绘画和雕塑艺术\\n3.2 科普特人的文学作品\\n3.3 科普特人的音乐和舞蹈艺术\\n\\n四、科普特人的建筑和工程技术\\n4.1 科普特人的建筑风格和特点\\n4.2 科普特人的水利工程和农业技术\\n4.3 科普特人的金属加工和制造技术\\n\\n五、科普特人的医学和药物\\n5.1 科普特人的医学理论和实践\\n5.2 科普特人的药物和草药疗法\\n5.3 科普特人的医疗机构和医疗制度\\n\\n六、科普特人的教育和学术\\n6.1 科普特人的教育体系和教育内容\\n6.2 科普特人的学术研究和学术成就\\n6.3 科普特人的知识传承和学术交流\\n\\n七、科普特人的社会活动和组织\\n7.1 科普特人的社会组织和文化团体\\n7.2 科普特人的慈善和公益活动\\n7.3 科普特人的政治参与和社会影响”,请把其中的小标题“3.2 科普特人的文学作品”的内容补充完整,补充内容字数在1100字左右\n答:\n"
#
prompt2 = "生成目录#问:论文题目为“基于红细胞分布宽度建立乙肝相关慢加急性肝衰竭不良预后的优化预测模型”,以“研究建立一种基于红细胞分布宽度的乙肝相关慢加急性肝衰竭不良预后的优化预测模型,包括数据收集、特征选择、模型构建等方面的研究。最终成果是验证所设计模型对于乙肝相关慢加急性肝衰竭不良预后的预测能力,并对模型进行优化,提高预测准确性和可靠性。”为论文的研究方向,为论文生成目录,要求只有一级标题和二级标题,一级标题使用中文数字 例如一、xxx;二级标题使用阿拉伯数字 例如1.1 xxx;一级标题不少于7个;每个一级标题至少包含3个二级标题\n答:\n"
prompt3 = "生成论文小标题内容#问:论文题目是“多无人艇一致性自主编队控制研究”,目录是“一、引言\\n 1.1 研究背景\\n 1.2 研究意义\\n 1.3 国内外研究现状\\n\\n二、多无人艇编队控制技术综述\\n 2.1 多无人艇编队控制技术分类\\n 2.2 多无人艇编队控制技术研究现状\\n 2.3 多无人艇编队控制技术存在的问题\\n\\n三、多无人艇一致性控制方法研究\\n 3.1 一致性控制方法分类\\n 3.2 多无人艇一致性控制方法研究现状\\n 3.3 多无人艇一致性控制方法存在的问题\\n\\n四、多无人艇一致性自主编队控制方法研究\\n 4.1 自主编队控制方法分类\\n 4.2 多无人艇一致性自主编队控制方法研究现状\\n 4.3 多无人艇一致性自主编队控制方法存在的问题\\n\\n五、多无人艇一致性自主编队控制仿真实验\\n 5.1 实验设计\\n 5.2 实验结果分析\\n 5.3 实验结论\\n\\n六、总结与展望\\n 6.1 研究成果总结\\n 6.2 研究不足与改进方向\\n 6.3 发展前景与应用价值”,请把其中的小标题“3.3 多无人艇一致性控制方法存在的问题”的内容补充完整,补充内容字数在700字左右\n答:\n"
# prompt = "生成论文小标题内容#论文题目是“家庭化流动对流动人口就业的影响”,目录是“一、研究背景和意义\\n1.1 流动人口和家庭化流动的概念\\n1.2 流动人口就业现状分析\\n1.3 家庭化流动的影响因素\\n\\n二、家庭化流动对流动人口就业的影响\\n2.1 家庭化流动对流动人口就业机会的影响\\n2.2 家庭化流动对流动人口就业稳定性的影响\\n2.3 家庭化流动对流动人口就业满意度的影响\\n\\n三、家庭化流动对流动人口就业的政策建议\\n3.1 完善流动人口就业政策\\n3.2 加强家庭化流动人口的社会保障\\n3.3 推进家庭化流动人口的职业培训\\n\\n四、案例分析\\n4.1 湖南省某县家庭化流动人口就业情况分析\\n4.2 广东省某市家庭化流动人口就业政策效果分析\\n4.3 河北省某区家庭化流动人口就业满意度调查\\n\\n五、结论与展望\\n5.1 结论\\n5.2 展望”,请把其中的小标题“3.2 加强家庭化流动人口的社会保障”的内容补充完整,补充内容字数在900字左右"
# prompt = "翻译摘要#请把“本文研究了相干光通信中以太网视频传输系统的关键技术。首先,介绍了相干光通信的基本原理和应用领域,指出了其在高速数据传输中的优势。然后,分析了以太网视频传输系统的特点和需求,包括高带宽、低延迟、高可靠性等。接着,针对传输过程中可能出现的干扰和衰减等问题,提出了多种解决方案,如光纤衰减补偿、信号增强等。此外,还介绍了基于光放大器的信号放大技术和基于光纤光栅的光谱成像技术,以及它们在以太网视频传输系统中的应用。最后,根据系统需求和技术特点,设计了一套完整的以太网视频传输系统,并进行了实验验证。结果表明,该系统具有高带宽、低延迟、高可靠性等优点,可以满足实际应用需求。本文的研究成果对于推动相干光通信技术的发展和应用具有重要意义。”这段文字翻译成英文"
prompt = "翻译摘要#请把“研究背景:\n\n随着全球能源需求的不断增加和化石燃料的日益枯竭,新能源技术的研究和应用已经成为全球性的热点问题。其中,燃料电池作为一种高效、清洁、可再生的新能源技术,已经成为国际上研究的热点之一。而其中,高温质子交换膜燃料电池(HT-PEMFC)由于具有高能量密度、高效率、低污染等优点,被广泛应用于航空航天、汽车、家庭等领域。\n\n然而,HT-PEMFC在启动过程中存在着一定的困难。由于燃料电池的运行需要一定的温度和湿度条件,因此在启动时需要先加热和湿化电池,以达到运行所需的条件。而传统的加热和湿化方法需要较长的时间,且能量消耗较大,因此需要寻找一种快速启动的方法,以提高燃料电池的运行效率和可靠性。\n\n研究意义:\n\n本研究旨在探究一种快速启动HT-PEMFC的方法,以提高其运行效率和可靠性。具体而言,本研究将采用仿真方法,研究在不同的温度和湿度条件下,利用燃料电池的内部能量来快速启动电池的可行性和效果,并分析其影响因素和优化方案。\n\n本研究的意义在于:\n\n1. 提高HT-PEMFC的运行效率和可靠性。采用快速启动方法可以减少启动时间和能量消耗,提高燃料电池的运行效率和可靠性。\n\n2. 探索新的启动方法。传统的加热和湿化方法存在能量消耗大、启动时间长等缺点,因此本研究探索一种新的快速启动方法,为燃料电池的应用提供新的思路和方法。\n\n3. 为燃料电池的应用提供技术支持。燃料电池作为一种新能源技术,其应用前景广阔。本研究为燃料电池的应用提供技术支持,有利于推动其产业化和普及。\n”这段文字翻译成英文"
# prompt = "请写出以《列宁军事理论及其在中国的应用与发展研究》为课题的国内外研究状况综述,字数在800字左右"
# prompt = "以“专利间接侵权责任认定制度研究”为论文题目,写一个论文简短总结,要求在300字以内"
# prompt = "请把“1. 老年长期护理模式\\n2. 问题分析\\n3. 解决方案\\n4. 国际比较与分析\\n5. 改进措施”这几个关键字翻译成英文"
# prompt = "请为“本研究旨在探究基于领导成员交换理论的团队绩效。通过对团队成员之间的领导成员交换关系进行分析,研究团队绩效的影响因素。本研究采用问卷调查法,对不同类型的团队进行调查,以了解不同领导成员交换关系对团队绩效的影响。\\n\\n研究结果表明,领导成员交换关系对团队绩效具有显著影响。在高质量的领导成员交换关系下,团队绩效显著提高。此外,团队成员之间的信任程度、沟通效果、合作精神等因素也对团队绩效产生重要影响。\\n\\n本研究还发现,不同类型的团队对领导成员交换关系的需求也不同。在高度协作的团队中,领导成员交换关系对团队绩效的影响更为显著。而在需要高度专业技能的团队中,领导成员交换关系的影响相对较小。\\n\\n综上所述,基于领导成员交换理论的团队绩效研究对于提高团队绩效具有重要意义。在实践中,团队领导者应该注重领导成员交换关系的建立和维护,以提高团队绩效。此外,团队成员之间的信任程度、沟通效果、合作精神等因素也应该得到重视,以促进团队的协作和合作,提高团队绩效。”这段论文摘要生成3-5个关键字,使用阿拉伯数字作为序号标注,例如“1.xxx \\n2.xxx \\n3.xxx \\n4.xxx \\n5.xxx \\n”"
# prompt = "请帮我生成《眼底图像中微小目标检测算法的研究与实现》为题目的研究内容,包括整体简介和分最少三个方面总结"
# prompt = "生成6点本篇论文应完成的主要内容#请根据题目为《ATP软件可靠性混沌预测研究》,和研究内容为“整体简介:\\n本研究旨在探讨ATP软件的可靠性混沌预测方法,以提高软件开发过程中的可靠性和稳定性。通过对ATP软件的历史数据进行分析,结合混沌理论,建立混沌预测模型,以实现对ATP软件可靠性的预测和控制。\\n\\n分三个方面总结:\\n1. 历史数据分析:通过对ATP软件的历史数据进行分析,包括软件开发过程中的各个环节,如需求分析、设计、编码、测试等,以及软件发布后的使用情况,如稳定性、故障率等,分析软件可靠性的影响因素和规律,为后续建立混沌预测模型提供数据支持。\\n\\n2. 混沌预测模型建立:基于ATP软件的历史数据和混沌理论,建立混沌预测模型,通过对历史数据的拟合和验证,优化模型参数,提高预测精度。同时,结合软件开发过程中的实际情况,不断修正和完善模型,以适应不同的软件开发环境和需求。\\n\\n3. 可靠性控制策略实现:基于混沌预测模型,制定可靠性控制策略,包括对软件开发过程中的各个环节进行监控和调整,对软件发布后的使用情况进行实时监测和反馈,及时发现和解决潜在问题,提高软件的可靠性和稳定性。同时,通过对控制策略的不断优化和改进,不断提高软件开发过程中的效率和质量。”总结出至少6点本篇论文应完成的主要内容,使用阿拉伯数字排列"
# prompt = "生成论文摘要#论文题目是“度假型酒店式公寓项目策划研究”,目录是“一、项目概述\\n1.1 项目背景\\n1.2 项目定位\\n1.3 项目规划\\n\\n二、市场调研\\n2.1 目标客群分析\\n2.2 竞争对手分析\\n2.3 市场需求分析\\n\\n三、设计方案\\n3.1 客房设计\\n3.2 公共空间设计\\n3.3 营销策略设计\\n\\n四、运营管理\\n4.1 人员组织架构\\n4.2 运营流程规划\\n4.3 财务预算与管理\\n\\n五、风险分析\\n5.1 市场风险\\n5.2 技术风险\\n5.3 政策风险\\n\\n六、社会效益\\n6.1 社会影响评估\\n6.2 环保建设\\n6.3 社区责任履行\\n\\n七、总结与展望\\n7.1 项目总结\\n7.2 未来发展展望”,生成论文摘要,要求生成的字数在600字左右"
# prompt = "生成目录#为论文题目“试论杭州“西溪”名称的含义、演变及其原因”生成目录,要求只有一级标题和二级标题,一级标题使用中文数字 例如一、xxx;二级标题使用阿拉伯数字 例如1.1 xxx;一级标题不少于7个;每个一级标题至少包含3个二级标题"
# prompt = "生成目录#为论文题目“中西部地区公共就业服务水平省际差距研究”生成目录,要求只有一级标题和二级标题,一级标题使用中文数字 例如一、xxx;二级标题使用阿拉伯数字 例如1.1 xxx;一级标题不少于7个;每个一级标题至少包含3个二级标题"
# prompt = "生成课题的研究背景和意义#请分别写出以《农村小学少先队活动研究》为课题,以“研究农村小学少先队的活动内容、组织方式和效果,探讨如何提高少先队员的思想品德和综合素质。通过实地调研和问卷调查等方法,分析少先队活动的现状和问题,提出相应的改进措施。最终成果是设计出一套适合农村小学少先队开展的活动方案,有效促进少先队员的全面发展和成长。”为论文的研究方向,生成论文的研究背景和意义,字数不少于1000字"
# prompt = "生成论文小标题内容#论文题目是“黄土高原刺槐人工林土壤磷组分及其有效性对穿透雨改变的响应”,目录是“一、绪论\\n1.1 研究背景\\n1.2 研究意义\\n1.3 国内外研究现状\\n\\n二、材料与方法\\n2.1 研究区域及样地选择\\n2.2 采样与处理\\n2.3 土壤理化性质测定\\n2.4 磷组分测定\\n2.5 数据处理方法\\n\\n三、土壤磷组分及其有效性\\n3.1 土壤磷组分特征\\n3.2 土壤磷有效性特征\\n3.3 土壤磷组分与有效性的相关性\\n\\n四、穿透雨对土壤磷组分及其有效性的影响\\n4.1 穿透雨对土壤磷组分的影响\\n4.2 穿透雨对土壤磷有效性的影响\\n4.3 穿透雨对土壤磷组分与有效性的相关性影响\\n\\n五、讨论\\n5.1 黄土高原刺槐人工林土壤磷组分及其有效性的特征\\n5.2 穿透雨对土壤磷组分及其有效性的影响机制\\n5.3 黄土高原刺槐人工林土壤磷管理的建议\\n\\n六、结论\\n\\n七、参考文献”,请把其中的小标题“3.1 土壤磷组分特征”的内容补充完整,补充内容字数在900字左右"
# prompt = "问:根据核心内容“七夕给女朋友发的情书”,生成不少于1000字中文情书\n答:\n"
# t1 = time.time()
# for i in range(50):
# print("#####################################################################")
# print(f"## {i}")
# print("#####################################################################")
# res, history = model.chat(tokenizer, prompt, history=[], top_p=0.7, temperature=0.3)
#
# print(res)
# t2 = time.time()
#
# print(t2 -t1)
# num_beams = 1
do_sample = True
top_p = 0.7
temperature = 0.9
gen_kwargs = {"do_sample": do_sample, "top_p": top_p,
"temperature": temperature}
t1 = time.time()
for i in range(3):
print("#####################################################################")
print(f"## {i}")
print("#####################################################################")
input_ids = tokenizer.encode(prompt, return_tensors='pt').to('cuda')
# input_txt_list = [prompt1,prompt2,prompt3]
#
# input_ids = tokenizer.batch_encode_plus(input_txt_list, return_tensors="pt",padding=True)["input_ids"].to('cuda')
# print(input_ids)
with torch.no_grad():
output_ids = model.generate(
input_ids=input_ids,
max_new_tokens=2000,
eos_token_id=tokenizer.eos_token_id,
**gen_kwargs
)
# print(output_ids)
output_ids = output_ids.tolist()
print(tokenizer.decode(output_ids[0][len(input_ids[0]):], skip_special_tokens=True))
# for j in range(len(input_txt_list)):
# print("#####################################################################")
# print(f"## {i,j}")
# print("#####################################################################")
#
# print(tokenizer.decode(output_ids[j][len(input_ids[j]):], skip_special_tokens=True))
##########################
# streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
# instruction = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: {} ASSISTANT:"
# prompt = instruction.format("How can I improve my time management skills?") # user message
# prompt = "小明的爸爸有3个儿子,三儿子叫大狗,二儿子叫二猫,三儿子叫什么?"
# generate_ids = model.generate(tokenizer(prompt, return_tensors='pt').input_ids.cuda(), max_new_tokens=2048)
# print(generate_ids)
# print(tokenizer.decode(generate_ids[0], skip_special_tokens=True))
#
# t2 = time.time()
#
# print(t2 -t1)

1
predict_vllm.py

@ -0,0 +1 @@
from vllm import LLM, SamplingParams

62
request_10_paper.py

@ -0,0 +1,62 @@
import requests
import json
# def request_api_chatgpt(text):
#
# url = "http://192.168.31.74:15000/predict"
# data = {
# "texts": text
# }
# response = requests.post(url,
# data=json.dumps(data),
# timeout=1800)
#
# return response
url = "http://192.168.31.74:15000/predict"
def dialog_line_parse(text):
"""
将数据输入模型进行分析并输出结果
:param url: 模型url
:param text: 进入模型的数据
:return: 模型返回结果
"""
data = {
"texts": text
}
response = requests.post(
url,
json=data
)
if response.status_code == 200:
return response.json()
else:
# logger.error(
# "【{}】 Failed to get a proper response from remote "
# "server. Status Code: {}. Response: {}"
# "".format(url, response.status_code, response.text)
# )
print("{}】 Failed to get a proper response from remote "
"server. Status Code: {}. Response: {}"
"".format(url, response.status_code, response.text))
print(text)
return []
title_list = ["幼小衔接下大班幼儿适应性的研究",
"基于51单片机的智能温控风扇设计",
"基于matlab的值指纹识别系统设计",
"财务舞弊的成因及防范措施研究",
"不孕症患者焦虑症状态及其影响因素",
"消费者网络购物影响因素分析",
"论恶意差评行为的法律定性与法律责任",
"一例急性心肌梗死患者冠脉术后的护理",
"上海财政扶持民办高等教育的问题及对策",
"生鲜冷链物流配送选址-路径优化问题研究"]
for i in title_list:
print(i)
dialog_line_parse(i)

80
requirements.txt

@ -1,14 +1,66 @@
torch>=1.13.1
protobuf
cpm_kernels
sentencepiece
transformers>=4.29.1
datasets>=2.12.0
accelerate>=0.19.0
peft>=0.3.0
trl>=0.4.4
jieba
rouge_chinese
nltk
gradio
mdtex2html
aiosignal==1.3.1
anyio==3.7.0
attrs==23.1.0
certifi==2023.5.7
charset-normalizer==3.1.0
click==8.1.3
cmake==3.26.4
exceptiongroup==1.1.1
fastapi==0.98.0
filelock==3.12.2
frozenlist==1.3.3
fsspec==2023.6.0
grpcio==1.51.3
h11==0.14.0
huggingface-hub==0.15.1
idna==3.4
importlib-resources==5.12.0
Jinja2==3.1.2
jsonschema==4.17.3
lit==16.0.6
MarkupSafe==2.1.3
mpmath==1.3.0
msgpack==1.0.5
mypy-extensions==1.0.0
networkx==3.1
ninja==1.11.1
numpy==1.24.4
nvidia-cublas-cu11==11.10.3.66
nvidia-cuda-cupti-cu11==11.7.101
nvidia-cuda-nvrtc-cu11==11.7.99
nvidia-cuda-runtime-cu11==11.7.99
nvidia-cudnn-cu11==8.5.0.96
nvidia-cufft-cu11==10.9.0.58
nvidia-curand-cu11==10.2.10.91
nvidia-cusolver-cu11==11.4.0.1
nvidia-cusparse-cu11==11.7.4.91
nvidia-nccl-cu11==2.14.3
nvidia-nvtx-cu11==11.7.91
packaging==23.1
pkgutil_resolve_name==1.3.10
protobuf==4.23.3
psutil==5.9.5
pydantic==1.10.9
pyre-extensions==0.0.29
pyrsistent==0.19.3
PyYAML==6.0
ray==2.5.1
regex==2023.6.3
requests==2.31.0
safetensors==0.3.1
sentencepiece==0.1.99
sniffio==1.3.0
starlette==0.27.0
sympy==1.12
tokenizers==0.13.3
torch==2.0.1
tqdm==4.65.0
transformers==4.30.2
triton==2.0.0
typing-inspect==0.9.0
typing_extensions==4.6.3
urllib3==2.0.3
uvicorn==0.22.0
vllm==0.1.1
xformers==0.0.20
zipp==3.15.0

1
run_train_freeze_llama.sh

@ -0,0 +1 @@
nohup bash train_freeze.sh > myout_llama.file 2>&1 &

4
src/utils/common.py

@ -211,6 +211,7 @@ def load_pretrained(
config=config,
torch_dtype=torch.bfloat16 if model_args.compute_dtype == torch.bfloat16 else torch.float16,
low_cpu_mem_usage=True,
device_map="auto",
**config_kwargs
)
model = prepare_model_for_training(model, finetuning_args.finetuning_type) if is_trainable else model
@ -513,7 +514,8 @@ def preprocess_data(
def print_supervised_dataset_example(example):
print("input_ids:\n{}".format(example["input_ids"]))
print("inputs:\n{}".format(tokenizer.decode(example["input_ids"])))
# tokenizer.decode(output_ids[0], skip_special_tokens=True)
print("inputs:\n{}".format(tokenizer.decode(example["input_ids"], skip_special_tokens=True)))
print("label_ids:\n{}".format(example["labels"]))
print("labels:\n{}".format(
tokenizer.decode([d if d != IGNORE_INDEX else tokenizer.pad_token_id for d in example["labels"]]))

15
train_freeze.py

@ -0,0 +1,15 @@
# CUDA_VISIBLE_DEVICES=2 python src/train_sft.py \
# --do_train \
# --dataset paper_data_v3_prompt \
# --dataset_dir /home/majiahui/projert/ChatGLM-Efficient-Tuning/data \
# --finetuning_type freeze \
# --max_source_length 700 \
# --max_target_length 1400 \
# --output_dir path_to_sft_checkpoint_paper_prompt_freeze \
# --per_device_train_batch_size 1 \
# --lr_scheduler_type cosine \
# --logging_steps 10 \
# --save_steps 2000 \
# --learning_rate 1e-4 \
# --num_train_epochs 5.0 \
# --fp16

19
train_freeze.sh

@ -0,0 +1,19 @@
CUDA_VISIBLE_DEVICES=1,2,3 python src/train_sft.py \
--model_name_or_path /home/majiahui/project/models-llm/openbuddy-llama-7b-v1.4-fp16/ \
--do_train \
--dataset paper_data_v6_prompt \
--dataset_dir /home/majiahui/project/LLaMA-Efficient-Tuning/data \
--finetuning_type freeze \
--max_source_length 700 \
--max_target_length 1400 \
--output_dir path_to_sft_openbuddy_llama_paper_checkpoint_prompt_freeze_checkpoint_data_v6 \
--overwrite_cache \
--per_device_train_batch_size 2 \
--gradient_accumulation_steps 1 \
--lr_scheduler_type cosine \
--logging_steps 10 \
--save_steps 6000 \
--learning_rate 5e-5 \
--num_train_epochs 3.0 \
--plot_loss \
--fp16 \

19
train_freeze_baichuan_7b.sh

@ -0,0 +1,19 @@
CUDA_VISIBLE_DEVICES=2,3 python src/train_sft.py \
--model_name_or_path /home/majiahui/models-LLM/baichuan-7B \
--do_train \
--dataset paper_data_v3_prompt \
--dataset_dir /home/majiahui/project2/LLaMA-Efficient-Tuning/data \
--finetuning_type freeze \
--max_source_length 700 \
--max_target_length 1400 \
--output_dir path_to_sft_checkpoint_paper_prompt_freeze_baichuan \
--overwrite_cache \
--per_device_train_batch_size 1 \
--gradient_accumulation_steps 1 \
--lr_scheduler_type cosine \
--logging_steps 10 \
--save_steps 1000 \
--learning_rate 5e-5 \
--num_train_epochs 3.0 \
--plot_loss \
--fp16

21
train_freeze_deepspeed.sh

@ -0,0 +1,21 @@
CUDA_VISIBLE_DEVICES=0,1,2 deepspeed --num_gpus=3 src/train_sft.py \
--deepspeed deepspeed_v2.json \
--model_name_or_path /home/majiahui/models-LLM/openbuddy-llama-7b-v1.4-fp16/ \
--do_train \
--dataset paper_data_v3_prompt \
--dataset_dir /home/majiahui/project2/LLaMA-Efficient-Tuning/data \
--finetuning_type freeze \
--max_source_length 700 \
--max_target_length 1400 \
--output_dir path_to_sft_checkpoint_paper_prompt_freeze_deepspeed \
--overwrite_cache \
--per_device_train_batch_size 2 \
--gradient_accumulation_steps 1 \
--lr_scheduler_type cosine \
--logging_steps 10 \
--save_steps 4000 \
--learning_rate 1e-5 \
--num_train_epochs 3.0 \
--plot_loss \
--fp16 \
--checkpoint_dir /home/majiahui/project2/LLaMA-Efficient-Tuning/path_to_sft_checkpoint_paper_prompt_freeze/checkpoint-104000

829
生成英文写作数据.py

@ -57,7 +57,7 @@ prompt_tpye_dict = {
"en-prompt": "Write a brief summary of the English paper titled ‘{$title}’, with a requirement of no more than {$wordnum} words"
},
"生成课题的国内外研究状况综述#\n": {
"data_tpye": "Generate a brief summary of the paper#\n",
"data_tpye": "A Summary of Research Status at Home and Abroad on Generated Topics#\n",
"title": "请写出以《(.*)》为课题的国内外研究状况综述",
"en-prompt": "Please provide an English summary of the research status of ‘{$title}’ at home and abroad, with a word count of around {$wordnum} words"
},
@ -134,7 +134,7 @@ with open("data/llama_t/chatglm_dev_4_prompt_llama.json") as f:
data = json.loads(f.read())
data_new = []
for i in tqdm(data[:10]):
for i in tqdm(data):
data_dan_dict = {}
instruction = i["instruction"]
input_ = i["input"]
@ -142,444 +142,436 @@ for i in tqdm(data[:10]):
try:
if instruction == "生成论文来源的背景#\n":
dan_dict = prompt_tpye_dict["生成论文来源的背景#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
en_title = predict_baichuan(title)
# en_output = predict_baichuan(i["output"])
#
# en_output_list = str(en_output).split(" ")
# zishu = len(en_output_list)//100 * 100
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "200")
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成研究内容#\n":
dan_dict = prompt_tpye_dict["生成研究内容#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
en_title = predict_baichuan(title)
# en_output = predict_baichuan(i["output"])
en_prompt = en_prompt.replace("{$title}", en_title)
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
data_dan_dict["en_title"] = en_title
data_dan_dict["en_hexin"] = ""
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成目录#\n":
dan_dict = prompt_tpye_dict["生成目录#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
en_title = predict_baichuan(title)
# en_output = predict_baichuan(i["output"])
en_prompt = en_prompt.replace("{$title}", en_title)
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成课题的研究背景和意义#\n":
dan_dict = prompt_tpye_dict["生成课题的研究背景和意义#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
en_title = predict_baichuan(title)
# en_output = predict_baichuan(i["output"])
#
# en_output_list = str(en_output).split(" ")
# zishu = len(en_output_list)//100 * 100
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "1000")
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成致谢#\n":
dan_dict = prompt_tpye_dict["生成致谢#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
en_title = predict_baichuan(title)
# en_output = predict_baichuan(i["output"])
en_prompt = en_prompt.replace("{$title}", en_title)
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成论文简短总结#\n":
dan_dict = prompt_tpye_dict["生成论文简短总结#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
en_title = predict_baichuan(title)
# en_output = predict_baichuan(i["output"])
# elif instruction == "生成研究内容#\n":
# dan_dict = prompt_tpye_dict["生成研究内容#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# data_tpye = dan_dict["data_tpye"]
#
# en_output_list = str(en_output).split(" ")
# zishu = len(en_output_list)//100 * 100
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "300")
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成课题的国内外研究状况综述#\n":
dan_dict = prompt_tpye_dict["生成课题的国内外研究状况综述#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
en_title = predict_baichuan(title)
# en_output = predict_baichuan(i["output"])
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# en_output_list = str(en_output).split(" ")
# zishu = len(en_output_list)//100 * 100
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "800")
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成6点本篇论文应完成的主要内容#\n":
dan_dict = prompt_tpye_dict["生成6点本篇论文应完成的主要内容#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
opening_report_main_content = dan_dict["opening_report_main_content"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
opening_report_main_content_re = re.findall(opening_report_main_content, input_)
opening_report_main_content = opening_report_main_content_re[0]
opening_report_main_content = opening_report_main_content.replace("\\n", "\n")
en_title = predict_baichuan(title)
en_opening_report_main_content = predict_baichuan(opening_report_main_content)
# en_output = predict_baichuan(i["output"])
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$opening_report_main_content}", en_opening_report_main_content)
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成参考文献#\n":
dan_dict = prompt_tpye_dict["生成参考文献#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
catalogue_str = dan_dict["catalogue_str"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
catalogue_str_re = re.findall(catalogue_str, input_)
catalogue_str = catalogue_str_re[0]
catalogue_str = catalogue_str.replace("\\n", "\n")
en_title = predict_baichuan(title)
en_catalogue_str = predict_baichuan(catalogue_str)
# en_output = predict_baichuan(i["output"])
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$catalogue_str}", en_catalogue_str)
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成论文小标题内容#\n":
print(1)
dan_dict = prompt_tpye_dict["生成论文小标题内容#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
catalogue_str = dan_dict["catalogue_str"]
smell_title = dan_dict["smell-title"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
catalogue_str_re = re.findall(catalogue_str, input_)
catalogue_str = catalogue_str_re[0]
catalogue_str = catalogue_str.replace("\\n", "\n")
smell_title_re = re.findall(smell_title, input_)
print(smell_title_re)
if smell_title_re == []:
continue
smell_title = smell_title_re[0]
smell_title = smell_title.replace("\\n", "\n")
en_title = predict_baichuan(title)
en_catalogue_str = predict_baichuan(catalogue_str)
en_smell_title = predict_baichuan(smell_title)
# en_output = predict_baichuan(i["output"])
# en_title = predict_baichuan(title)
# # en_output = predict_baichuan(i["output"])
#
# en_output_list = str(en_output).split(" ")
# zishu = len(en_output_list)//100 * 100
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$catalogue_str}", en_catalogue_str).replace("{$secondray_title}", en_smell_title).replace("{$wordnum}", "800")
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成论文摘要#\n":
dan_dict = prompt_tpye_dict["生成论文摘要#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
catalogue_str = dan_dict["catalogue_str"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
catalogue_str_re = re.findall(catalogue_str, input_)
catalogue_str = catalogue_str_re[0]
catalogue_str = catalogue_str.replace("\\n", "\n")
en_title = predict_baichuan(title)
en_catalogue_str = predict_baichuan(catalogue_str)
# en_output = predict_baichuan(i["output"])
# en_prompt = en_prompt.replace("{$title}", en_title)
#
# en_output_list = str(en_output).split(" ")
# zishu = len(en_output_list)//100 * 100
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$catalogue_str}", en_catalogue_str).replace("{$wordnum}", "400")
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成关键字#\n":
dan_dict = prompt_tpye_dict["生成关键字#\n"]
en_prompt = dan_dict["en-prompt"]
abstract = dan_dict["abstract"]
catalogue_str = dan_dict["catalogue_str"]
data_tpye = dan_dict["data_tpye"]
abstract_re = re.findall(abstract, input_)
abstract = abstract_re[0]
abstract = abstract.replace("\\n", "\n")
en_abstract = predict_baichuan(abstract)
# en_output = predict_baichuan(i["output"])
en_prompt = en_prompt.replace("{$abstract}", en_abstract)
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成论文来源的背景-核心内容#\n":
dan_dict = prompt_tpye_dict["生成论文来源的背景-核心内容#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
hexin = dan_dict["hexin"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
hexin_re = re.findall(hexin, input_)
hexin = hexin_re[0]
hexin = hexin.replace("\\n", "\n")
en_title = predict_baichuan(title)
en_hexin = predict_baichuan(hexin)
# en_output = predict_baichuan(i["output"])
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# en_output_list = str(en_output).split(" ")
# zishu = len(en_output_list)//100 * 100
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "200").replace("{$this->core_content}", en_hexin)
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成研究内容-核心内容#\n":
dan_dict = prompt_tpye_dict["生成研究内容-核心内容#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
hexin = dan_dict["hexin"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
hexin_re = re.findall(hexin, input_)
hexin = hexin_re[0]
hexin = hexin.replace("\\n", "\n")
en_title = predict_baichuan(title)
en_hexin = predict_baichuan(hexin)
# en_output = predict_baichuan(i["output"])
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$this->core_content}", en_hexin)
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成目录-核心内容#\n":
dan_dict = prompt_tpye_dict["生成目录-核心内容#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
hexin = dan_dict["hexin"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
hexin_re = re.findall(hexin, input_)
hexin = hexin_re[0]
hexin = hexin.replace("\\n", "\n")
en_title = predict_baichuan(title)
en_hexin = predict_baichuan(hexin)
# en_output = predict_baichuan(i["output"])
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$this->core_content}", en_hexin)
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成课题的研究背景和意义-核心内容#\n":
dan_dict = prompt_tpye_dict["生成课题的研究背景和意义-核心内容#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
hexin = dan_dict["hexin"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
hexin_re = re.findall(hexin, input_)
hexin = hexin_re[0]
hexin = hexin.replace("\\n", "\n")
en_title = predict_baichuan(title)
en_hexin = predict_baichuan(hexin)
# en_output = predict_baichuan(i["output"])
# data_new.append(data_dan_dict)
#
# en_output_list = str(en_output).split(" ")
# zishu = len(en_output_list)//100 * 100
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "1000").replace("{$this->core_content}", en_hexin)
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
elif instruction == "生成论文简短总结-核心内容#\n":
dan_dict = prompt_tpye_dict["生成论文简短总结-核心内容#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
hexin = dan_dict["hexin"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
hexin_re = re.findall(hexin, input_)
hexin = hexin_re[0]
hexin = hexin.replace("\\n", "\n")
en_title = predict_baichuan(title)
en_hexin = predict_baichuan(hexin)
# en_output = predict_baichuan(i["output"])
#
# en_output_list = str(en_output).split(" ")
# zishu = len(en_output_list)//100 * 100
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "300").replace("{$this->core_content}", en_hexin)
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)
# elif instruction == "生成目录#\n":
# dan_dict = prompt_tpye_dict["生成目录#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# en_title = predict_baichuan(title)
# # en_output = predict_baichuan(i["output"])
#
# en_prompt = en_prompt.replace("{$title}", en_title)
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成课题的研究背景和意义#\n":
# dan_dict = prompt_tpye_dict["生成课题的研究背景和意义#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# en_title = predict_baichuan(title)
# # en_output = predict_baichuan(i["output"])
# #
# # en_output_list = str(en_output).split(" ")
# # zishu = len(en_output_list)//100 * 100
#
# en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "1000")
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成致谢#\n":
# dan_dict = prompt_tpye_dict["生成致谢#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# en_title = predict_baichuan(title)
# # en_output = predict_baichuan(i["output"])
#
# en_prompt = en_prompt.replace("{$title}", en_title)
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成论文简短总结#\n":
# dan_dict = prompt_tpye_dict["生成论文简短总结#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# en_title = predict_baichuan(title)
# # en_output = predict_baichuan(i["output"])
# #
# # en_output_list = str(en_output).split(" ")
# # zishu = len(en_output_list)//100 * 100
#
# en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "300")
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成课题的国内外研究状况综述#\n":
# dan_dict = prompt_tpye_dict["生成课题的国内外研究状况综述#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# en_title = predict_baichuan(title)
# # en_output = predict_baichuan(i["output"])
# #
# # en_output_list = str(en_output).split(" ")
# # zishu = len(en_output_list)//100 * 100
#
# en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "800")
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成6点本篇论文应完成的主要内容#\n":
# dan_dict = prompt_tpye_dict["生成6点本篇论文应完成的主要内容#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# opening_report_main_content = dan_dict["opening_report_main_content"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# opening_report_main_content_re = re.findall(opening_report_main_content, input_)
# opening_report_main_content = opening_report_main_content_re[0]
# opening_report_main_content = opening_report_main_content.replace("\\n", "\n")
#
# en_title = predict_baichuan(title)
# en_opening_report_main_content = predict_baichuan(opening_report_main_content)
# # en_output = predict_baichuan(i["output"])
#
# en_prompt = en_prompt.replace("{$title}", en_title).replace("{$opening_report_main_content}", en_opening_report_main_content)
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成参考文献#\n":
# dan_dict = prompt_tpye_dict["生成参考文献#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# catalogue_str = dan_dict["catalogue_str"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# catalogue_str_re = re.findall(catalogue_str, input_)
# catalogue_str = catalogue_str_re[0]
# catalogue_str = catalogue_str.replace("\\n", "\n")
#
# en_title = predict_baichuan(title)
# en_catalogue_str = predict_baichuan(catalogue_str)
# # en_output = predict_baichuan(i["output"])
#
# en_prompt = en_prompt.replace("{$title}", en_title).replace("{$catalogue_str}", en_catalogue_str)
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成论文小标题内容#\n":
# print(1)
# dan_dict = prompt_tpye_dict["生成论文小标题内容#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# catalogue_str = dan_dict["catalogue_str"]
# smell_title = dan_dict["smell-title"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# catalogue_str_re = re.findall(catalogue_str, input_)
# catalogue_str = catalogue_str_re[0]
# catalogue_str = catalogue_str.replace("\\n", "\n")
#
# smell_title_re = re.findall(smell_title, input_)
# print(smell_title_re)
# if smell_title_re == []:
# continue
# smell_title = smell_title_re[0]
# smell_title = smell_title.replace("\\n", "\n")
#
# en_title = predict_baichuan(title)
# en_catalogue_str = predict_baichuan(catalogue_str)
# en_smell_title = predict_baichuan(smell_title)
# # en_output = predict_baichuan(i["output"])
# #
# # en_output_list = str(en_output).split(" ")
# # zishu = len(en_output_list)//100 * 100
#
# en_prompt = en_prompt.replace("{$title}", en_title).replace("{$catalogue_str}", en_catalogue_str).replace("{$secondray_title}", en_smell_title).replace("{$wordnum}", "800")
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成论文摘要#\n":
# dan_dict = prompt_tpye_dict["生成论文摘要#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# catalogue_str = dan_dict["catalogue_str"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# catalogue_str_re = re.findall(catalogue_str, input_)
# catalogue_str = catalogue_str_re[0]
# catalogue_str = catalogue_str.replace("\\n", "\n")
#
# en_title = predict_baichuan(title)
# en_catalogue_str = predict_baichuan(catalogue_str)
# # en_output = predict_baichuan(i["output"])
# #
# # en_output_list = str(en_output).split(" ")
# # zishu = len(en_output_list)//100 * 100
#
# en_prompt = en_prompt.replace("{$title}", en_title).replace("{$catalogue_str}", en_catalogue_str).replace("{$wordnum}", "400")
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成关键字#\n":
# dan_dict = prompt_tpye_dict["生成关键字#\n"]
# en_prompt = dan_dict["en-prompt"]
# abstract = dan_dict["abstract"]
# catalogue_str = dan_dict["catalogue_str"]
# data_tpye = dan_dict["data_tpye"]
#
# abstract_re = re.findall(abstract, input_)
# abstract = abstract_re[0]
# abstract = abstract.replace("\\n", "\n")
#
# en_abstract = predict_baichuan(abstract)
# # en_output = predict_baichuan(i["output"])
#
# en_prompt = en_prompt.replace("{$abstract}", en_abstract)
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成论文来源的背景-核心内容#\n":
# dan_dict = prompt_tpye_dict["生成论文来源的背景-核心内容#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# hexin = dan_dict["hexin"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# hexin_re = re.findall(hexin, input_)
# hexin = hexin_re[0]
# hexin = hexin.replace("\\n", "\n")
#
# en_title = predict_baichuan(title)
# en_hexin = predict_baichuan(hexin)
# # en_output = predict_baichuan(i["output"])
# #
# # en_output_list = str(en_output).split(" ")
# # zishu = len(en_output_list)//100 * 100
#
# en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "200").replace("{$this->core_content}", en_hexin)
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成研究内容-核心内容#\n":
# dan_dict = prompt_tpye_dict["生成研究内容-核心内容#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# hexin = dan_dict["hexin"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# hexin_re = re.findall(hexin, input_)
# hexin = hexin_re[0]
# hexin = hexin.replace("\\n", "\n")
#
# en_title = predict_baichuan(title)
# en_hexin = predict_baichuan(hexin)
# # en_output = predict_baichuan(i["output"])
#
# en_prompt = en_prompt.replace("{$title}", en_title).replace("{$this->core_content}", en_hexin)
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成目录-核心内容#\n":
# dan_dict = prompt_tpye_dict["生成目录-核心内容#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# hexin = dan_dict["hexin"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# hexin_re = re.findall(hexin, input_)
# hexin = hexin_re[0]
# hexin = hexin.replace("\\n", "\n")
#
# en_title = predict_baichuan(title)
# en_hexin = predict_baichuan(hexin)
# # en_output = predict_baichuan(i["output"])
#
# en_prompt = en_prompt.replace("{$title}", en_title).replace("{$this->core_content}", en_hexin)
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成课题的研究背景和意义-核心内容#\n":
# dan_dict = prompt_tpye_dict["生成课题的研究背景和意义-核心内容#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# hexin = dan_dict["hexin"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# hexin_re = re.findall(hexin, input_)
# hexin = hexin_re[0]
# hexin = hexin.replace("\\n", "\n")
#
# en_title = predict_baichuan(title)
# en_hexin = predict_baichuan(hexin)
# # en_output = predict_baichuan(i["output"])
# #
# # en_output_list = str(en_output).split(" ")
# # zishu = len(en_output_list)//100 * 100
#
# en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "1000").replace("{$this->core_content}", en_hexin)
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
#
# elif instruction == "生成论文简短总结-核心内容#\n":
# dan_dict = prompt_tpye_dict["生成论文简短总结-核心内容#\n"]
# en_prompt = dan_dict["en-prompt"]
# title = dan_dict["title"]
# hexin = dan_dict["hexin"]
# data_tpye = dan_dict["data_tpye"]
#
# title_re = re.findall(title, input_)
# title = title_re[0]
#
# hexin_re = re.findall(hexin, input_)
# hexin = hexin_re[0]
# hexin = hexin.replace("\\n", "\n")
#
# en_title = predict_baichuan(title)
# en_hexin = predict_baichuan(hexin)
# # en_output = predict_baichuan(i["output"])
# #
# # en_output_list = str(en_output).split(" ")
# # zishu = len(en_output_list)//100 * 100
#
# en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "300").replace("{$this->core_content}", en_hexin)
#
# data_dan_dict["instruction"] = data_tpye
# data_dan_dict["input"] = en_prompt
# # data_dan_dict["output"] = en_output
#
# data_new.append(data_dan_dict)
elif instruction == "生成课题的国内外研究状况综述-核心内容#\n":
if instruction == "生成课题的国内外研究状况综述-核心内容#\n":
dan_dict = prompt_tpye_dict["生成课题的国内外研究状况综述-核心内容#\n"]
en_prompt = dan_dict["en-prompt"]
title = dan_dict["title"]
hexin = dan_dict["hexin"]
data_tpye = dan_dict["data_tpye"]
title_re = re.findall(title, input_)
title = title_re[0]
@ -595,10 +587,9 @@ for i in tqdm(data[:10]):
# en_output_list = str(en_output).split(" ")
# zishu = len(en_output_list)//100 * 100
en_prompt = en_prompt.replace("{$title}", en_title).replace("{$wordnum}", "800").replace("{$this->core_content}", en_hexin)
data_dan_dict["instruction"] = data_tpye
data_dan_dict["input"] = en_prompt
data_dan_dict["en_title"] = en_title
data_dan_dict["en_hexin"] = en_hexin
# data_dan_dict["output"] = en_output
data_new.append(data_dan_dict)

Loading…
Cancel
Save