Skip to content

processes

Process for GenAI-driven translation.

GenAITranslationProcess

Bases: Process

Language-agnostic translation process using a generative GPT model.

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = None

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

CuneiformLuwianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'cune1239'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Cuneiform Luwian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

HieroglyphicLuwianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'hier1240'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Hieroglyphic Luwian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldPrussianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'prus1238'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Prussian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

LithuanianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'lith1251'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Lithuanian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

LatvianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'latv1249'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Latvian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

AlbanianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'gheg1238'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Albanian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

AkkadianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'akka1240'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Akkadian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

AncientGreekGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'anci1242'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Ancient Greek language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

BiblicalHebrewGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'anci1244'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Biblical Hebrew language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

ClassicalArabicGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'clas1259'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Classical Arabic language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

AvestanGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'aves1237'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Avestan language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

BactrianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'bact1239'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Bactrian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

SogdianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'sogd1245'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Sogdian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

BengaliGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'beng1280'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Bengali language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

CarianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'cari1274'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Carian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

ChurchSlavicGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'chur1257'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Church Slavic language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

ClassicalArmenianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'clas1256'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Classical Armenian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

ClassicalMandaicGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'clas1253'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Classical Mandaic language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

ClassicalMongolianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'mong1331'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Classical Mongolian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

ClassicalSyriacGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'clas1252'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Classical Syriac language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

ClassicalTibetanGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'clas1254'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Classical Tibetan language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

CopticGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'copt1239'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Coptic language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

DemoticGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'demo1234'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Demotic language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

EasternPanjabiGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'panj1256'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Eastern Panjabi language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

EdomiteGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'edom1234'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Edomite language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

GeezGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'geez1241'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Geez language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

GothicGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'goth1244'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Gothic language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

GujaratiGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'guja1252'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Gujarati language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

HindiGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'hind1269'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Hindi language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

KhariBoliGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'khad1239'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Khari Boli dialect of Hindi."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

BrajGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'braj1242'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Braj Bhasha language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

AwadhiGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'awad1243'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Awadhi language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

HittiteGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'hitt1242'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Hittite language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

KhotaneseGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'khot1251'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Khotanese language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

TumshuqeseGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'tums1237'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Tumshuqese language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

LateEgyptianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'late1256'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Late Egyptian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

LatinGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'lati1261'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Latin language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

LiteraryChineseGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'lite1248'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Literary Chinese language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

LycianAGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'lyci1241'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Lycian A language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

LydianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'lydi1241'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Lydian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MaharastriPrakritGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'maha1305'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Maharastri Prakrit language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MiddleArmenianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'midd1364'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Middle Armenian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MiddleBretonGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oldb1244'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Middle Breton language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MiddleChineseGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'midd1344'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Middle Chinese language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MiddleCornishGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'corn1251'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Middle Cornish language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MiddleEgyptianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'midd1369'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Middle Egyptian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MiddleEnglishGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'midd1317'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Middle English language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MiddleFrenchGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'midd1316'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Middle French language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MiddleHighGermanGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'midd1343'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Middle High German language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MiddleMongolGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'mong1329'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Middle Mongol language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MoabiteGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'moab1234'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Moabite language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OdiaGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oriy1255'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Odia language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OfficialAramaicGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'impe1235'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Official Aramaic (700-300 BCE) language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldBurmeseGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oldb1235'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Burmese language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldChineseGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oldc1244'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Chinese language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

BaihuaChineseGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'clas1255'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for Early Vernacular Chinese (Baihua)."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

ClassicalBurmeseGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'nucl1310'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Classical Burmese language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

TangutGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'tang1334'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Tangut (Xixia) language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

NewarGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'newa1246'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Newar (Classical Nepal Bhasa) language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MeiteiGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'mani1292'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Meitei (Classical Manipuri) language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

SgawKarenGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'sgaw1245'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Sgaw Karen language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MogholiGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'mogh1245'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Mogholi (Moghol) language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

NumidianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'numi1241'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Numidian (Ancient Berber) language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

TaitaGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'tait1247'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Cushitic Taita language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

HausaGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'haus1257'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Hausa language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldJurchenGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'jurc1239'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Jurchen language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldJapaneseGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'japo1237'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Japanese language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldHungarianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oldh1242'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Hungarian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

ChagataiGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'chag1247'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Chagatai language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldTurkicGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oldu1238'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Turkic language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldTamilGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oldt1248'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Tamil language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

AmmoniteGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'ammo1234'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Ammonite language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldAramaicGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'olda1246'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Aramaic (up to 700 BCE) language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldAramaicSamalianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'olda1245'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Aramaic–Samʾalian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MiddleAramaicGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'midd1366'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Middle Aramaic language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

HatranGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'hatr1234'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Hatran language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

JewishBabylonianAramaicGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'jewi1240'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Jewish Babylonian Aramaic language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

SamalianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'sama1234'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Samʾalian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldEgyptianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'olde1242'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Egyptian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldEnglishGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'olde1238'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old English (ca. 450-1100) language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldFrenchGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oldf1239'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old French (842-ca. 1400) language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldHighGermanGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oldh1241'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old High German (ca. 750-1050) language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

EarlyIrishGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oldi1245'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Irish language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MarathiGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'mara1378'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Marathi language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldNorseGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oldn1244'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Norse language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldPersianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oldp1254'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old Persian (ca. 600-400 B.C.) language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

OldMiddleWelshGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'oldw1239'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Old-Middle Welsh language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

ParthianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'part1239'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Parthian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MiddlePersianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'pahl1241'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Middle Persian language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

PalaicGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'pala1331'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Palaic language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

PaliGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'pali1273'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Pali language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

PhoenicianGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'phoe1239'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Phoenician language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

AssameseGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'assa1263'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Assamese language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

SinhalaGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'sinh1246'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Sinhala language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

SindhiGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'sind1272'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Sindhi language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

KashmiriGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'kash1277'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Kashmiri language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

BagriGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'bagr1243'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Bagri (Rajasthani) language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

ClassicalSanskritGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'clas1258'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Classical Sanskrit language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

VedicSanskritGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'vedi1234'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Vedic Sanskrit language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

TokharianAGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'toch1238'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Tokharian A language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

TokharianBGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'toch1237'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Tokharian B language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

UgariticGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'ugar1238'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Ugaritic language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

UrduGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'urdu1245'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Urdu language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

SauraseniPrakritGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'saur1252'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Sauraseni Prakrit language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

MagadhiPrakritGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'maga1260'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Magadhi Prakrit language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc

GandhariGenAITranslationProcess

Bases: GenAITranslationProcess

Language-specific translation process using a generative GPT model.

glottolog_id class-attribute instance-attribute

glottolog_id: Optional[str] = 'gand1259'

description class-attribute instance-attribute

description: str = (
    "Default textual translation process using a generative GPT model for the Gandhari language."
)

authorship_info class-attribute instance-attribute

authorship_info: str = 'CLTK'

process_id class-attribute

process_id: str = 'translation.genai'

prompt_builder class-attribute instance-attribute

prompt_builder: Optional[TranslationPromptBuilder] = None

target_language class-attribute instance-attribute

target_language: str = 'Modern US English'

target_language_id class-attribute instance-attribute

target_language_id: Optional[str] = 'en-US'

prompt_profile class-attribute instance-attribute

prompt_profile: Optional[str] = None

prompt_version class-attribute instance-attribute

prompt_version: Optional[str] = None

algorithm cached property

algorithm: Callable[..., Doc]

Return the translation generation function for this process.

run

run(input_doc: Doc) -> Doc

Run the configured GPT translation workflow.

Source code in cltk/translation/processes.py
def run(self, input_doc: Doc) -> Doc:
    """Run the configured GPT translation workflow."""
    output_doc: Doc = copy(input_doc)
    if not output_doc.words:
        msg = "Doc must have `words` with prior annotations before translation."
        bind_from_doc(output_doc).error(msg)
        raise ValueError(msg)
    target_language = self.target_language
    target_language_id = self.target_language_id
    try:
        meta = output_doc.metadata
        if isinstance(meta, dict):
            target_language = meta.get(
                "translation_target_language", target_language
            )
            target_language_id = meta.get(
                "translation_target_language_id", target_language_id
            )
    except Exception:
        pass
    prompt_builder = self.prompt_builder
    prompt_digest = None
    if prompt_builder is None and self.prompt_profile:
        template = PromptProfileRegistry.get_prompt(
            self.prompt_profile, self.process_id, self.prompt_version
        )
        prompt_digest = template.digest

        def _builder(
            lang: str,
            target: str,
            context: str,
            _template: PromptTemplate = template,
        ) -> PromptInfo:
            """Build a translation prompt from a profile template."""
            return build_prompt_info(
                _template,
                lang_or_dialect_name=lang,
                target_language=target,
                context=context,
            )

        prompt_builder = _builder
    output_doc = self.algorithm(
        output_doc,
        target_language=target_language,
        target_language_id=target_language_id,
        prompt_builder=prompt_builder,
        prompt_profile=self.prompt_profile,
        prompt_digest=prompt_digest,
        provenance_process=f"{self.process_id}:{self.__class__.__name__}",
    )
    return output_doc