Repository navigation
Expose translation control knobs #2038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c03e067
95ace5e
8953798
4fb2a98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,17 @@ | |
| "faith_handling_of_format": "Handling_of_Format", | ||
| } | ||
|
|
||
| _OUTPUT_COLUMN_DTYPES = { | ||
| "translation_time": "float64", | ||
| "faith_fluency": "float64", | ||
| "faith_accuracy": "float64", | ||
| "faith_idiomaticity": "float64", | ||
| "faith_terminology": "float64", | ||
| "faith_handling_of_format": "float64", | ||
| "faith_avg": "float64", | ||
| "faith_parse_failed": "bool", | ||
| } | ||
|
|
||
|
|
||
| @dataclass | ||
| class ReassemblyStage(ProcessingStage[DocumentBatch, DocumentBatch]): | ||
|
|
@@ -86,6 +97,21 @@ def process(self, batch: DocumentBatch) -> DocumentBatch: | |
| """Reassemble translated segments into full documents.""" | ||
| df = batch.to_pandas() | ||
|
|
||
| if df.empty: | ||
| logger.info("ReassemblyStage: no translated segment rows to reassemble") | ||
| base_cols = [col for col in df.columns if col not in _INTERNAL_COLUMNS] | ||
| out_df = df.loc[:, base_cols].copy() | ||
| for col in self.outputs()[1]: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it a bit fragile that it requires outputs() returning a tuple where index [1] contains the output column names
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree it looks a bit fragile but it follows the convention that should be used by text stages with |
||
| if col not in out_df.columns: | ||
| out_df[col] = pd.Series(dtype=_OUTPUT_COLUMN_DTYPES.get(col, "object")) | ||
| return DocumentBatch( | ||
| task_id=batch.task_id, | ||
| dataset_name=batch.dataset_name, | ||
| data=out_df, | ||
| _metadata=batch._metadata, | ||
| _stage_perf=batch._stage_perf, | ||
| ) | ||
|
|
||
| result_rows: list[dict[str, Any]] = [] | ||
|
|
||
| for _doc_id, doc_group in df.groupby("_seg_doc_id", sort=True): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,8 @@ class SegmentTranslationStage(ProcessingStage[DocumentBatch, DocumentBatch]): | |
| backend_type: str = "llm" | ||
| backend_config: dict = field(default_factory=dict) | ||
| generation_config: GenerationConfig | None = None | ||
| prompt_path: str | None = None | ||
| """Absolute local YAML prompt path, or ``None`` for the packaged prompt.""" | ||
| max_concurrent_requests: int = 64 | ||
| health_check: bool = True | ||
| """If True, verify the translation backend is reachable during ``setup()``.""" | ||
|
|
@@ -101,7 +103,8 @@ def outputs(self) -> tuple[list[str], list[str]]: | |
| def setup(self, worker_metadata: WorkerMetadata | None = None) -> None: # noqa: ARG002 | ||
| """Initialize the client or backend on the worker.""" | ||
| if not self._initialized: | ||
| self._system_prompt, self._user_template = load_prompt_template("translate.yaml") | ||
| prompt_file = self.prompt_path or "translate.yaml" | ||
| self._system_prompt, self._user_template = load_prompt_template(prompt_file) | ||
|
Comment on lines
+106
to
+107
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| if self.backend_type != "llm": | ||
| from nemo_curator.stages.text.experimental.translation.backends import get_backend | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if
prompt_path=""There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty string will go to "faith_eval.yaml".