Skip to content

Commit

Permalink
transl_dropout
Browse files Browse the repository at this point in the history
  • Loading branch information
xd2333 committed May 30, 2024
1 parent ae86856 commit 3a27339
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
17 changes: 16 additions & 1 deletion GalTransl/Backend/SakuraTranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ def __init__(
self.transl_style = val
else:
self.transl_style = "流畅"

# transl_dropout
if val := config.getKey("gpt.transl_dropout"):
self.transl_dropout = val
else:
self.transl_dropout = 0
# 现在只有简体
self.opencc = OpenCC("t2s.json")

Expand Down Expand Up @@ -315,6 +319,11 @@ async def batch_translate(
)
num, trans_result = await self.translate(trans_list_split, dic_prompt)

if self.transl_dropout>0 and num==num_pre_request:
if self.transl_dropout<num:
num-=self.transl_dropout
trans_result=trans_result[:num]

i += num if num > 0 else 0
transl_step_count+=1
if transl_step_count>=self.save_steps:
Expand Down Expand Up @@ -345,6 +354,12 @@ def _del_previous_message(self) -> None:
if last_user_message:
self.chatbot.conversation["default"].append(last_user_message)
if last_assistant_message:
last_assistant_message["content"] = last_assistant_message["content"].replace("*EOF*", "").strip()
if self.transl_dropout>0:
sp=last_assistant_message["content"].split("\n")
if len(sp)>self.transl_dropout:
sp=sp[:0-self.transl_dropout]
last_assistant_message["content"]="\n".join(sp)
self.chatbot.conversation["default"].append(last_assistant_message)

def _del_last_answer(self):
Expand Down
31 changes: 17 additions & 14 deletions sampleProject/config.inc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@
# 程序设置
common:
saveLog: false # 是否记录日志到文件[True/False]
workersPerProject: 1 # 多线程,同时翻译的文件数量(单文件只能单线程)
workersPerProject: 1 # 多线程,同时翻译的**文件**数量(单文件只能单线程)
language: "ja2zh-cn" # 源语言2(to)目标语言。[zh-cn/zh-tw/en/ja/ko/ru/fr]
save_steps: 1 # 每翻译n次保存一次缓存,单个文件较大时可以调高到10-100来提升速度。[1-999]
linebreakSymbol: "\r\n" # 这个项目在json中使用的换行符,找问题和自动修复时用到,不影响翻译。
skipH: false # 跳过可能触发敏感词检测的句子。[True/False]
skipRetry: false # 开启则解析结果出错时跳过循环重试,直接用"Fail Translation"占位。[True/False]
retranslFail: false # 重启时重翻所有"Fail Translation"的句子。[True/False]
retranslFail: false # 重启时重翻所有显示为"Fail Translation"的句子。[True/False]
retranslKey: "" # 重启时主动重翻在problem或pre_jp中包含此关键字的句子,例如"残留日文"
gpt.numPerRequestTranslate: 10 # 单次翻译句子数量,推荐值 < 15
# 通用翻译设置
gpt.numPerRequestTranslate: 8 # 单次翻译句子数量,推荐值 < 15
gpt.streamOutputMode: true # 流式输出效果,多线程下无效。[True/False]
# NewBing/GPT4
gpt.enableProofRead: false # (NewBing/GPT4)是否开启译后校润。(不建议使用,很久未维护)[True/False]
gpt.numPerRequestProofRead: 7 # (NewBing/GPT4)单次校润句子数量,不建议修改
gpt.recordConfidence: false # (NewBing/GPT4)记录确信度、存疑句,GPT4 API关掉可节约token。(将废弃)[True/False]
# GPT3.5/GPT4
gpt.restoreContextMode: true # (GPT3.5/4)重启时恢复上一轮的译文前文。[True/False]
# Sakura/GalTransl
gpt.transl_dropout: 0 # (Sakura/Galtransl)(实验性)丢弃翻译结果末尾的n行,可能会提高上下文准确性。[0-2]
# GalTransl
gpt.transl_style: "流畅" # (GalTransl)翻译风格[流畅/文艺]
# 插件设置
plugin:
filePlugin: file_galtransl_json # 指定文件读取插件,默认使用file_galtransl_json
Expand All @@ -29,12 +34,11 @@ proxy:
enableProxy: false # 是否启用代理。[True/False]
proxies:
- address: http://127.0.0.1:7890
# 字典设置
# 字典设置,所有字典、字典内词条将按顺序从上到下替换
dictionary:
defaultDictFolder: Dict # 通用字典文件夹,相对于程序目录,也可填入绝对路径
usePreDictInName: false # 将译前字典用在name字段,可用于改名[True/False]
usePostDictInName: false # 将译后字典用在name字段,可用于汉化name[True/False]
# 所有字典、字典内词条将按顺序从上到下替换
# 译前字典
preDict:
- 01H字典_矫正_译前.txt # 用于口齿不清的矫正
Expand All @@ -51,26 +55,25 @@ dictionary:
- (project_dir)项目字典_译后.txt
# 翻译后端相关设置
backendSpecific:
GPT35: # GPT3.5 API/claude-3-sonnet第三方中转
GPT35: # GPT3.5 API
tokens:
- token: sk-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
endpoint: https://api.openai.com # OpenAI API请求的域名,使用转发或第三方API时修改
endpoint: https://api.openai.com # 使用转发或第三方API时修改
- token: sk-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
endpoint: ""
defaultEndpoint: https://api.openai.com # 默认 API 端点,一般不修改
rewriteModelName: "" # 强制使用指定的模型型号,可用于claude-3-sonnet第三方中转
GPT4: # GPT4 API/claude-3-opus第三方中转
rewriteModelName: "" # 使用指定的模型型号替换默认模型
GPT4: # GPT4 API/claude-3第三方中转
tokens:
- token: sk-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
endpoint: https://api.openai.com # 使用转发或第三方API时修改
defaultEndpoint: https://api.openai.com # 一般不修改
rewriteModelName: "" # 强制使用指定的模型型号,可用于claude-3-opus第三方中转
rewriteModelName: "" # 使用指定的模型型号替换默认模型
bingGPT4: # NewBing API
cookiePath:
- newbing_cookies/cookie1.json # 你的 cookies 文件,相对于项目目录
- newbing_cookies/cookie2.json # 你的 cookies 文件2,会自动切换
Sakura: # Sakura API
SakuraLLM: # Sakura/Galtransl API
endpoint: http://127.0.0.1:8080
rewriteModelName: "" # 使用指定的模型型号替换默认模型
# 自动问题分析配置
problemAnalyze:
problemList: # 要发现的问题清单
Expand Down

0 comments on commit 3a27339

Please sign in to comment.