翻译后出现大片空白,公式发生诡异翻转
在提问之前...
- [x] 我已经搜索了现有的 issues
- [x] 我在提问题之前至少花费了 5 分钟来思考和准备
- [x] 我已经认真且完整的阅读了 wiki
- [x] 我已经认真检查了问题和网络环境无关(包括但不限于Google不可用,模型下载失败)
使用的环境
- **OS** : windows11 x86
- **python**: 3.11.9
- **pdf2zh** : 1.9.9
- **pip_list** :
Package Version
------------------------------ -----------
aiofiles 23.2.1
annotated-types 0.7.0
anyio 4.6.2.post1
azure-ai-translation-text 1.0.1
azure-core 1.32.0
BabelDOC 0.2.30
bitarray 3.3.0
bitstring 4.3.1
certifi 2024.8.30
cffi 1.17.1
charset-normalizer 3.4.0
click 8.1.7
click-default-group 1.2.4
colorama 0.4.6
coloredlogs 15.0.1
ConfigArgParse 1.7
contourpy 1.3.2
cryptography 44.0.0
cycler 0.12.1
decorator 5.1.1
deepl 1.18.0
Deprecated 1.2.18
distro 1.9.0
docformatter 1.7.5
et_xmlfile 2.0.0
fastapi 0.115.5
ffmpy 0.4.0
filelock 3.16.1
flatbuffers 24.3.25
fonttools 4.56.0
freetype-py 2.5.1
fsspec 2024.10.0
gradio 5.7.0
gradio_client 1.5.0
gradio_pdf 0.0.21
h11 0.14.0
httpcore 1.0.7
httpx 0.27.2
huggingface-hub 0.30.1
humanfriendly 10.0
idna 3.10
imageio 2.37.0
isodate 0.7.2
Jinja2 3.1.4
jiter 0.8.0
kiwisolver 1.4.8
lazy_loader 0.4
Levenshtein 0.27.1
lxml 5.3.1
markdown-it-py 3.0.0
MarkupSafe 2.1.5
matplotlib 3.10.1
mdurl 0.1.2
mpmath 1.3.0
msgpack 1.1.0
networkx 3.4.2
numpy 2.2.4
ollama 0.4.1
onnx 1.17.0
onnxruntime 1.20.1
openai 1.70.0
opencv-python 4.11.0.86
opencv-python-headless 4.10.0.84
openpyxl 3.1.5
orjson 3.10.16
packaging 24.2
pandas 2.2.3
pdf2zh 1.9.9
pdfminer.six 20250416
peewee 3.17.9
pikepdf 9.5.2
pillow 11.0.0
pip 25.0.1
protobuf 5.29.0
psutil 7.0.0
pyclipper 1.3.0.post6
pycosat 0.6.6
pycparser 2.22
pydantic 2.11.1
pydantic_core 2.33.0
pydub 0.25.1
pygame 2.6.1
Pygments 2.18.0
PyMuPDF 1.25.2
pyparsing 3.2.3
pyreadline3 3.5.4
PySocks 1.7.1
pyte 0.8.2
python-dateutil 2.9.0.post0
python-Levenshtein 0.27.1
python-multipart 0.0.12
pytz 2024.2
PyYAML 6.0.2
RapidFuzz 3.12.2
rapidocr-onnxruntime 1.4.4
regex 2024.11.6
requests 2.32.3
rich 13.9.4
ruff 0.8.0
safehttpx 0.1.1
scikit-image 0.25.2
scipy 1.15.2
semantic-version 2.10.0
shapely 2.0.7
shellingham 1.5.4
six 1.16.0
sniffio 1.3.1
socksio 1.0.0
starlette 0.41.3
sympy 1.13.3
tenacity 9.0.0
tencentcloud-sdk-python 3.0.1285
tencentcloud-sdk-python-common 3.0.1353
tencentcloud-sdk-python-tmt 3.0.1353
tifffile 2025.3.30
tiktoken 0.9.0
toml 0.10.2
tomlkit 0.12.0
toposort 1.10
tqdm 4.67.1
typer 0.13.1
typing_extensions 4.12.2
typing-inspection 0.4.0
tzdata 2024.2
untokenize 0.1.1
urllib3 2.2.3
uvicorn 0.32.1
wcwidth 0.2.13
websockets 12.0
win_unicode_console 0.5
wrapt 1.17.2
xinference-client 1.4.0
xsdata 24.12
请选择安装方式
pip
描述你的问题
-
一开始我是使用deepseek代理翻译,出现大段空白,且公式诡异翻转 后面改用默认的谷歌的翻译,亦是如此,但是诡异的是两次尝试都没有终端信息报错
-
目前已更新到最新版,仍然出错
-
之前看到其他的因为PDF浏览器打开不当导致的bug,所以我自己尝试使用多种PDF浏览器打开之,但是用了Edge\SumatraPDF\TEXworks打开都无济于事
-
后面请了朋友用Mac电脑上的Chorme浏览器打开依旧不行
如何复现
执行
pdf2zh .\icml01-ffq.pdf
或者
pdf2zh .\icml01-ffq.pdf -s deepseek
预期行为
希望看到正常的文字翻译,公式错乱倒是小事
相关 Logs
在PowerShell 7.5.1中运行得到:
PRTS G:\DownLoad_From_Edge\PDFs_From_Internet 20:15 ◆ <◆> System 10s
❖ pdf2zh .\icml01-ffq.pdf -s deepseek
not in git repo
Namespace(files=['.\\icml01-ffq.pdf'], debug=False, pages=None, vfont='', vchar='', lang_in='en', lang_out='zh', service='deepseek', output='', thread=4, interactive=False, share=False, flask=False, celery=False, authorized=None, prompt=None, compatible=False, onnx=None, serverport=None, dir=False, config=None, babeldoc=False, skip_subset_fonts=False, ignore_cache=False, mcp=False, sse=False)
[05/26/25 20:16:10] INFO INFO:pdf2zh.high_level:use font: high_level.py:423
C:/Users/区涛/.cache/babeldoc/fonts/SourceHanSerifCN-Regular.ttf
100%|████████████████████████████████████████████████████████████████████████████████████| 8/8 [00:08<00:00, 1.04s/it]
PRTS G:\DownLoad_From_Edge\PDFs_From_Internet 20:16 ◆ <◆> System 24s
❖ pdf2zh .\icml01-ffq.pdf
not in git repo
Namespace(files=['.\\icml01-ffq.pdf'], debug=False, pages=None, vfont='', vchar='', lang_in='en', lang_out='zh', service='google', output='', thread=4, interactive=False, share=False, flask=False, celery=False, authorized=None, prompt=None, compatible=False, onnx=None, serverport=None, dir=False, config=None, babeldoc=False, skip_subset_fonts=False, ignore_cache=False, mcp=False, sse=False)
[05/26/25 20:17:10] INFO INFO:pdf2zh.high_level:use font: high_level.py:423
C:/Users/区涛/.cache/babeldoc/fonts/SourceHanSerifCN-Regular.ttf
100%|████████████████████████████████████████████████████████████████████████████████████| 8/8 [00:49<00:00, 6.17s/it]
原始PDF文件
这里附上源下载网址:https://www.researchgate.net/publication/2933305_Friend-or-Foe_Q-learning_in_General-Sum_Games
还有别的吗?
请用2.0预览版重试
很抱歉,下载尝试后发现问题仍然没有彻底解决,这里面是我运行后得到的文件,虽然是没有空白了,但是文章内容全部翻转了
uv run babeldoc --files .\icml01-ffq_raw.pdf --openai --openai-model "deepseek" --openai-base-url "https://chat.deepseek.com" --openai-api-key "my-key"
注意
- 这里我没有启用中文翻译,只是简单的尝试了一下是否会出现bug
- 问题文件icml01-ffq_raw.zh.dual.pdf
- 终端信息如下(部分): [05/27/25 15:15:11] INFO INFO:babeldoc.document_il.backend.pdf_creater:Font subsetting completed pdf_creater.py:633 successfully [05/27/25 15:15:13] INFO INFO:babeldoc.document_il.backend.pdf_creater:PDF save with clean=True pdf_creater.py:748 completed successfully [05/27/25 15:15:16] INFO INFO:babeldoc.document_il.backend.pdf_creater:PDF save with clean=True pdf_creater.py:748 completed successfully INFO INFO:babeldoc.high_level:Peak memory usage: 1765.44 MB high_level.py:369 INFO INFO:babeldoc.high_level:finish translate: .\icml01-ffq_raw.pdf, cost: high_level.py:581 63.13802242279053 s INFO INFO:babeldoc.main:Translation results: main.py:430 Original PDF: .\icml01-ffq_raw.pdf Total time: 63.14 seconds Monolingual PDF: G:\DownLoad_From_Edge\PDFs_From_Internet\icml01-ffq_raw.zh.mono.pdf Dual-language PDF: G:\DownLoad_From_Edge\PDFs_From_Internet\icml01-ffq_raw.zh.dual.pdf Peak memory usage: 1765.44140625 MB translate ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸ 99/100 0:01:03 0:00:01 INFO INFO:babeldoc.translation_config:cleanup temp files: translation_config.py:254 D:\Temp\tmpljqaam58 translate ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸ 99/100 0:01:03 0:00:01 Parse PDF and Create Intermediate Representation (1/1) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8/8 0:00:01 0:00:00 DetectScannedFile (1/1) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8/8 0:00:00 0:00:00 Parse Page Layout (1/1) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8/8 0:00:05 0:00:00 Parse Paragraphs (1/1) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8/8 0:00:01 0:00:00 Parse Formulas and Styles (1/1) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8/8 0:00:00 0:00:00 Translate Paragraphs (1/1) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133/133 0:00:37 0:00:00 Typesetting (1/1) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8/8 0:00:00 0:00:00 Add Fonts (1/1) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 522/522 0:00:00 0:00:00 Generate drawing instructions (1/1) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8/8 0:00:00 0:00:00 Subset font (1/1) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1/1 0:00:02 0:00:00 Save PDF (1/1) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2/2 0:00:04 0:00:00 INFO INFO:babeldoc.main:Total tokens: 0 main.py:432 INFO INFO:babeldoc.main:Prompt tokens: 0 main.py:433 INFO INFO:babeldoc.main:Completion tokens: 0 main.py:434 INFO INFO:babeldoc.high_level:Waiting for translation to finish... high_level.py:323 INFO INFO:babeldoc.document_il.translator.translator:openai translate call translator.py:93 count: 151 INFO INFO:babeldoc.document_il.translator.translator:openai translate cache translator.py:96 call count: 0
顺便说一句,babeldoc中的README文件似乎过时了,因为实质上 --bing参数已经不被支持了,但是文档中仍然将其作为示例写出,这是不妥的
后面我启用了中文翻译选项
uv run babeldoc --files .\icml01-ffq_raw.pdf --lang-in "en" --lang-out "zh" --openai --openai-model "deepseek" --openai-base-url "https://chat.deepseek.com" --openai-api-key "my-key"
仍然出现翻转的英文?这就很奇怪了
- 同时附上终端信息文件如下:
顺便说一句,babeldoc中的README文件似乎过时了,因为实质上
--bing参数已经不被支持了,但是文档中仍然将其作为示例写出,这是不妥的
欢迎好心人发PR帮忙改。
由于BabelDOC的cli主要是给debug用的,所以README内容并没有活跃维护。实际上,BabelDOC整体的文档都存在严重过时问题,并且没有人力维护。
后面我启用了中文翻译选项
uv run babeldoc --files .\icml01-ffq_raw.pdf --lang-in "en" --lang-out "zh" --openai --openai-model "deepseek" --openai-base-url "https://chat.deepseek.com" --openai-api-key "my-key"仍然出现翻转的英文?这就很奇怪了
- 同时附上终端信息文件如下:
baseurl 是 https://api.deepseek.com/v1 你填写的baseurl是错的,请更正后重试。
更改为正确的baseurl后,仍然出现同样问题,没有正确翻译为中文,仍然是英文并且出现了反转
uv run babeldoc --files .\icml01-ffq_raw.pdf --lang-in "en" --lang-out "zh" --openai --openai-model "deepseek" --openai-base-url "https://api.deepseek.com/v1" --openai-api-key "my-key"
- 观察终端信息并在对照deepseek这两天的调用情况发现似乎是链接问题?deepseek没有被调用到。
- 但是奇怪的是,我的私钥没写错,在最新的pdf2zh里面是能使用的,所以不完全是链接问题。会不会是模型名称
--openai-model "deepseek"写错了?
观察到报错信息中有一句:
Error code: 400 - {'error': {'message': 'Model Not Exist', 'type': 'invalid_request_error', ...}}
- 这验证了我的猜想,于是按照以往的经验,修改为
--openai-model "deepseek-chat" - 这次终于可以正常(并非)运行了吧?
- 运行得到的pdf文档出现了最开始我说的大片空白的错误情形,这次终端也是没有报错
翻译后得到的文件
deepseek的调度情况
请使用最新pdf2zh 2.0预览版重试
https://github.com/Byaidu/PDFMathTranslate/issues/586#issuecomment-2909624958
描述问题:
在更新到 BabelDOC 0.3.54 后,使用 LLM 模型进行翻译时,仍然出现输出长度异常的警告,并触发回退机制。 仔细分析警告信息,发现问题似乎源自 LLM 翻译模块(il_translator_llm_only.py):
Translation result is too long or too short.
Input: 20, Output: 101
...
Fallback to simple translation. paragraph id: xJt6z
分析逻辑:
- 输入长度为 20 个 token / 字符?
- 输出结果却有 101 个 token —— 明显太长。
- BabelDOC 检测到不符合“合理翻译长度比”的规则(可能是自己定义的比如 0.5x ~ 2x 区间)。
- 触发了 fallback —— 回退为 简单翻译策略(如直接调用传统翻译 API 而非 LLM 推理)。
这表明当前 LLM 翻译模块在处理某段段落时,输出异常,系统选择降级为更稳定的翻译方案?但是降级后又不是不翻译了吧?(大概,我没看见源码,恕我无知)
反复尝试得到的一些结果
WARNING :babeldoc.document_il.midend.il_translator_llm_only:Tr il_translator_llm_only.py:444
anslation result is too long or too short. Input: 20, Output:101
WARNING :babeldoc.document_il.midend.il_translator_llm_only:Fa il_translator_llm_only.py:478
llback to simple translation. paragraph id: hdcpd
WARNING :babeldoc.document_il.midend.il_translator_llm_only:Tr il_translator_llm_only.py:444
anslation result is too long or too short. Input: 1, Output:3
这个问题是否已经得到解决?