-
Notifications
You must be signed in to change notification settings - Fork 503
/
translation.py
46 lines (34 loc) · 1.53 KB
/
translation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Inference code generated from the JSON schema spec in @huggingface/tasks.
#
# See:
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
from dataclasses import dataclass
from typing import Any, Dict, Literal, Optional
from .base import BaseInferenceType
TranslationGenerationTruncationStrategy = Literal["do_not_truncate", "longest_first", "only_first", "only_second"]
@dataclass
class TranslationGenerationParameters(BaseInferenceType):
"""Additional inference parameters
Additional inference parameters for Text2text Generation
"""
clean_up_tokenization_spaces: Optional[bool] = None
"""Whether to clean up the potential extra spaces in the text output."""
generate_parameters: Optional[Dict[str, Any]] = None
"""Additional parametrization of the text generation algorithm"""
truncation: Optional["TranslationGenerationTruncationStrategy"] = None
"""The truncation strategy to use"""
@dataclass
class TranslationInput(BaseInferenceType):
"""Inputs for Translation inference
Inputs for Text2text Generation inference
"""
inputs: str
"""The input text data"""
parameters: Optional[TranslationGenerationParameters] = None
"""Additional inference parameters"""
@dataclass
class TranslationOutput(BaseInferenceType):
"""Outputs of inference for the Translation task"""
translation_text: str
"""The translated text."""