docs: update inference prompts and client options to canonical instTrans format
Browse files
README.md
CHANGED
|
@@ -129,8 +129,11 @@ The following settings describe the released [`translate.py`](https://github.com
|
|
| 129 |
| Model ID | `IndexTeam/Index-Translate-9B`; `INDEX_MODEL` changes the default, and `--model` overrides it |
|
| 130 |
| Source language | `auto`; override with `--source` / `-s`; auto omits the source-language name from the prompt |
|
| 131 |
| Target language | `en`; override with `--target` / `-t` |
|
| 132 |
-
|
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
| 134 |
| Raw prompt | `--raw-prompt`; directly send input text without template wrapping |
|
| 135 |
| Endpoint | `http://127.0.0.1:8000/v1`; `OPENAI_BASE_URL` changes the default, and `--base-url` overrides it |
|
| 136 |
| API key | `EMPTY` for local serving; `OPENAI_API_KEY` changes the default, and `--api-key` overrides it |
|
|
@@ -142,7 +145,7 @@ The following settings describe the released [`translate.py`](https://github.com
|
|
| 142 |
|
| 143 |
The client maps supported short language codes to Chinese language names in the prompt. Provide the full language name for a code outside its mapping.
|
| 144 |
|
| 145 |
-
For standard translation:
|
| 146 |
|
| 147 |
```text
|
| 148 |
请将以下{source-language}文本翻译为{target-language},直接输出翻译结果,不要进行任何解释。
|
|
@@ -150,16 +153,19 @@ For standard translation:
|
|
| 150 |
{source-text}
|
| 151 |
```
|
| 152 |
|
| 153 |
-
|
| 154 |
|
| 155 |
```text
|
| 156 |
-
请将以下{source-language}
|
| 157 |
-
翻译要求:{instruction}
|
| 158 |
-
请严格遵循以下术语对应关系进行翻译:
|
| 159 |
-
- {src} -> {tgt}
|
| 160 |
-
直接输出翻译结果,不要进行任何解释。
|
| 161 |
|
|
|
|
| 162 |
{source-text}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
```
|
| 164 |
|
| 165 |
With `--source auto`, `{source-language}` is omitted. Prompt length, source text, and generated output all count toward the served context. Parameters left unspecified above are not assigned new fixed values by this model card.
|
|
@@ -216,15 +222,17 @@ text = response.choices[0].message.content or ""
|
|
| 216 |
if "</think>" in text: text = text.split("</think>", 1)[1]
|
| 217 |
print(text.strip().removeprefix("<think>").strip())
|
| 218 |
|
| 219 |
-
# 2.
|
| 220 |
-
prompt_with_constraints = """请将以下文
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
| 226 |
|
| 227 |
-
|
| 228 |
|
| 229 |
response = client.chat.completions.create(
|
| 230 |
model="IndexTeam/Index-Translate-2B",
|
|
@@ -252,17 +260,22 @@ python inference/llm/translate.py \
|
|
| 252 |
"你好,世界。今天天气不错。" --target en \
|
| 253 |
--model IndexTeam/Index-Translate-2B
|
| 254 |
|
| 255 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
python inference/llm/translate.py \
|
| 257 |
-
"
|
| 258 |
-
-
|
| 259 |
-
--instruction "保持专业严谨的技术文档风格" \
|
| 260 |
--model IndexTeam/Index-Translate-2B
|
| 261 |
|
| 262 |
-
#
|
| 263 |
python inference/llm/translate.py \
|
| 264 |
-
|
| 265 |
-
--
|
| 266 |
--model IndexTeam/Index-Translate-2B
|
| 267 |
```
|
| 268 |
|
|
|
|
| 129 |
| Model ID | `IndexTeam/Index-Translate-9B`; `INDEX_MODEL` changes the default, and `--model` overrides it |
|
| 130 |
| Source language | `auto`; override with `--source` / `-s`; auto omits the source-language name from the prompt |
|
| 131 |
| Target language | `en`; override with `--target` / `-t` |
|
| 132 |
+
| Hard constraints | `--hard` / `-H` (repeatable, e.g. format preservation, code/tag protection) |
|
| 133 |
+
| Soft constraints | `--soft` / `-S` (repeatable, e.g. style/tone adaptation, domain sense disambiguation) |
|
| 134 |
+
| Glossary | Terminology mappings with `--glossary` / `-g` (`src:tgt` or JSON path); formatted into canonical hard term constraints |
|
| 135 |
+
| Genre / Domain | Source text genre/domain with `--genre` / `-d` (default: `文本`, e.g. `专栏文章` / `学术论文` / `小说` / `结构化数据`) |
|
| 136 |
+
| Instruction | General instruction with `--instruction` / `-i` (formatted into instTrans constraints) |
|
| 137 |
| Raw prompt | `--raw-prompt`; directly send input text without template wrapping |
|
| 138 |
| Endpoint | `http://127.0.0.1:8000/v1`; `OPENAI_BASE_URL` changes the default, and `--base-url` overrides it |
|
| 139 |
| API key | `EMPTY` for local serving; `OPENAI_API_KEY` changes the default, and `--api-key` overrides it |
|
|
|
|
| 145 |
|
| 146 |
The client maps supported short language codes to Chinese language names in the prompt. Provide the full language name for a code outside its mapping.
|
| 147 |
|
| 148 |
+
For standard unconstrained translation:
|
| 149 |
|
| 150 |
```text
|
| 151 |
请将以下{source-language}文本翻译为{target-language},直接输出翻译结果,不要进行任何解释。
|
|
|
|
| 153 |
{source-text}
|
| 154 |
```
|
| 155 |
|
| 156 |
+
For constrained translation, the model follows the canonical **instTrans** format:
|
| 157 |
|
| 158 |
```text
|
| 159 |
+
请将以下{source-language}{genre}翻译成{target-language},并且严格遵循所有约束要求。
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
+
【源文】
|
| 162 |
{source-text}
|
| 163 |
+
|
| 164 |
+
【约束要求】
|
| 165 |
+
1. 【硬性要求】...
|
| 166 |
+
2. 【注意】...
|
| 167 |
+
|
| 168 |
+
只输出译文,不要有任何额外说明。
|
| 169 |
```
|
| 170 |
|
| 171 |
With `--source auto`, `{source-language}` is omitted. Prompt length, source text, and generated output all count toward the served context. Parameters left unspecified above are not assigned new fixed values by this model card.
|
|
|
|
| 222 |
if "</think>" in text: text = text.split("</think>", 1)[1]
|
| 223 |
print(text.strip().removeprefix("<think>").strip())
|
| 224 |
|
| 225 |
+
# 2. instTrans constrained translation (hard glossary + soft style constraints)
|
| 226 |
+
prompt_with_constraints = """请将以下专栏文章翻译成英语,并且严格遵循所有约束要求。
|
| 227 |
+
|
| 228 |
+
【源文】
|
| 229 |
+
王平仲采用了更加昂贵的碳纤维材料。碳纤维的好处就是它抗裂缝,而且能显著提升混凝土的刚性。
|
| 230 |
+
|
| 231 |
+
【约束要求】
|
| 232 |
+
1. 【硬性要求】专名/术语对照: 碳纤维→carbon fiber、抗裂缝→crack resistance、刚性→stiffness
|
| 233 |
+
2. 【注意】保持专业严谨的技术工程文档风格
|
| 234 |
|
| 235 |
+
只输出译文,不要有任何额外说明。"""
|
| 236 |
|
| 237 |
response = client.chat.completions.create(
|
| 238 |
model="IndexTeam/Index-Translate-2B",
|
|
|
|
| 260 |
"你好,世界。今天天气不错。" --target en \
|
| 261 |
--model IndexTeam/Index-Translate-2B
|
| 262 |
|
| 263 |
+
# Hard constraint: Terminology glossary (-g / --glossary)
|
| 264 |
+
python inference/llm/translate.py \
|
| 265 |
+
"王平仲采用了更加昂贵的碳纤维材料。碳纤维的好处就是它抗裂缝。" --target en \
|
| 266 |
+
-g "碳纤维:carbon fiber, 抗裂缝:crack resistance" \
|
| 267 |
+
--model IndexTeam/Index-Translate-2B
|
| 268 |
+
|
| 269 |
+
# Hard constraint: Structured data / JSON format preservation (-H / --hard)
|
| 270 |
python inference/llm/translate.py \
|
| 271 |
+
'{"user_id": 1024, "message": "您的订��已支付完成。"}' --target en \
|
| 272 |
+
-H "保留源文中的 JSON 格式标记不变" \
|
|
|
|
| 273 |
--model IndexTeam/Index-Translate-2B
|
| 274 |
|
| 275 |
+
# Soft constraint: Style (-S / --soft) & Genre (-d / --genre)
|
| 276 |
python inference/llm/translate.py \
|
| 277 |
+
"今天下午的会议临时取消了,改天我们再碰一下商量。" --target en \
|
| 278 |
+
-d "商务邮件" -S "调整为严谨、正式、礼貌的商务公文风格" \
|
| 279 |
--model IndexTeam/Index-Translate-2B
|
| 280 |
```
|
| 281 |
|