Commit 77bfa7e3f3f69213d6a67b9237f39d3de925a469
1 parent
af03fdef
query translate
Showing
4 changed files
with
31 additions
and
9 deletions
Show diff stats
config/config.yaml
| ... | ... | @@ -241,10 +241,10 @@ services: |
| 241 | 241 | infer_batch_size: 64 |
| 242 | 242 | sort_by_doc_length: true |
| 243 | 243 | length_sort_mode: "char" # char | token |
| 244 | - instruction: "Given a shopping query, rank product titles by relevance" | |
| 244 | + instruction: "rank products by given query" | |
| 245 | 245 | qwen3_transformers: |
| 246 | 246 | model_name: "Qwen/Qwen3-Reranker-0.6B" |
| 247 | - instruction: "Given a shopping query, rank product titles by relevance" | |
| 247 | + instruction: "rank products by given query" | |
| 248 | 248 | max_length: 8192 |
| 249 | 249 | batch_size: 64 |
| 250 | 250 | use_fp16: true | ... | ... |
config/config_loader.py
| ... | ... | @@ -67,6 +67,14 @@ class QueryConfig: |
| 67 | 67 | original_query_fallback_boost_when_translation_missing: float = 0.2 |
| 68 | 68 | tie_breaker_base_query: float = 0.9 |
| 69 | 69 | |
| 70 | + # Query-time translation model selection (configurable) | |
| 71 | + # - zh_to_en_model: model for zh -> en | |
| 72 | + # - en_to_zh_model: model for en -> zh | |
| 73 | + # - default_translation_model: fallback model for all other language pairs | |
| 74 | + zh_to_en_model: str = "opus-mt-zh-en" | |
| 75 | + en_to_zh_model: str = "opus-mt-en-zh" | |
| 76 | + default_translation_model: str = "nllb-200-distilled-600m" | |
| 77 | + | |
| 70 | 78 | |
| 71 | 79 | @dataclass |
| 72 | 80 | class SPUConfig: |
| ... | ... | @@ -262,6 +270,11 @@ class ConfigLoader: |
| 262 | 270 | text_strategy_cfg.get("original_query_fallback_boost_when_translation_missing", 0.2) |
| 263 | 271 | ), |
| 264 | 272 | tie_breaker_base_query=float(text_strategy_cfg.get("tie_breaker_base_query", 0.9)), |
| 273 | + zh_to_en_model=str(query_config_data.get("zh_to_en_model") or "opus-mt-zh-en"), | |
| 274 | + en_to_zh_model=str(query_config_data.get("en_to_zh_model") or "opus-mt-en-zh"), | |
| 275 | + default_translation_model=str( | |
| 276 | + query_config_data.get("default_translation_model") or "nllb-200-distilled-600m" | |
| 277 | + ), | |
| 265 | 278 | ) |
| 266 | 279 | |
| 267 | 280 | # Parse Function Score configuration | ... | ... |
docs/TODO.txt
| ... | ... | @@ -114,6 +114,10 @@ https://modelscope.cn/models/dengcao/Qwen3-Reranker-4B-GGUF/summary |
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | reranker 补充:nvidia/llama-nemotron-rerank-1b-v2 |
| 117 | +https://huggingface.co/nvidia/llama-nemotron-rerank-1b-v2 | |
| 118 | +后端推理也建议使用vLLM | |
| 119 | +注意搜索相关资料,挖掘我的特斯拉 T4 GPU 的性能,充分挖掘性能 | |
| 120 | +你有充足的自由度进行实验 | |
| 117 | 121 | encoder架构。 |
| 118 | 122 | 比较新。 |
| 119 | 123 | 性能更好。 | ... | ... |
query/query_parser.py
| ... | ... | @@ -152,15 +152,20 @@ class QueryParser: |
| 152 | 152 | return self._translator |
| 153 | 153 | |
| 154 | 154 | @staticmethod |
| 155 | - def _pick_query_translation_model(source_lang: str, target_lang: str) -> str: | |
| 156 | - """Pick the translation capability for query-time translation.""" | |
| 155 | + def _pick_query_translation_model(source_lang: str, target_lang: str, config: SearchConfig) -> str: | |
| 156 | + """Pick the translation capability for query-time translation (configurable).""" | |
| 157 | 157 | src = str(source_lang or "").strip().lower() |
| 158 | 158 | tgt = str(target_lang or "").strip().lower() |
| 159 | + | |
| 160 | + # Use dedicated models for zh<->en if configured | |
| 159 | 161 | if src == "zh" and tgt == "en": |
| 160 | - return "opus-mt-zh-en" | |
| 162 | + return config.query_config.zh_to_en_model | |
| 161 | 163 | if src == "en" and tgt == "zh": |
| 162 | - return "opus-mt-en-zh" | |
| 163 | - return "deepl" | |
| 164 | + return config.query_config.en_to_zh_model | |
| 165 | + | |
| 166 | + # For any other language pairs, fall back to the configurable default model. | |
| 167 | + # By default this is `nllb-200-distilled-600m` (multi-lingual local model). | |
| 168 | + return config.query_config.default_translation_model | |
| 164 | 169 | |
| 165 | 170 | def _simple_tokenize(self, text: str) -> List[str]: |
| 166 | 171 | """ |
| ... | ... | @@ -363,7 +368,7 @@ class QueryParser: |
| 363 | 368 | thread_name_prefix="query-translation-wait", |
| 364 | 369 | ) |
| 365 | 370 | for lang in target_langs: |
| 366 | - model_name = self._pick_query_translation_model(detected_lang, lang) | |
| 371 | + model_name = self._pick_query_translation_model(detected_lang, lang, self.config) | |
| 367 | 372 | log_debug( |
| 368 | 373 | f"Submitting query translation | source={detected_lang} target={lang} model={model_name}" |
| 369 | 374 | ) |
| ... | ... | @@ -377,7 +382,7 @@ class QueryParser: |
| 377 | 382 | ) |
| 378 | 383 | else: |
| 379 | 384 | for lang in target_langs: |
| 380 | - model_name = self._pick_query_translation_model(detected_lang, lang) | |
| 385 | + model_name = self._pick_query_translation_model(detected_lang, lang, self.config) | |
| 381 | 386 | log_debug( |
| 382 | 387 | f"Submitting query translation | source={detected_lang} target={lang} model={model_name}" |
| 383 | 388 | ) | ... | ... |