Generation API Reference¶
vietquill.generation.controllable_paraphraser.AutoModelForParaphraseGeneration(hub_id: str = None, device: str = None, **kwargs)
¶
Bases: BaseParaphraseGenerator
Paraphrase Generator using a single user-specified model without sentence/question splitting.
Initializes the Paraphrase Generator using a single model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hub_id
|
str
|
Path or HF repo ID for the model repository or checkpoint. |
None
|
device
|
str
|
Device to run the model on ('cuda' or 'cpu'). |
None
|
**kwargs
|
Additional keyword arguments passed to AutoModelForSeq2SeqLM.from_pretrained. |
{}
|
Source code in src/vietquill/generation/controllable_paraphraser/auto.py
paraphrase(text: str, **kwargs) -> List[str]
¶
Generates paraphrases with quality control constraints using the single loaded model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input text to paraphrase. |
required |
**kwargs
|
Generation parameters and control values. - semantic (int): Semantic control (0-100), default 90. - syntactic (int): Syntactic control (0-100), default 85. - lexical (int): Lexical control (0-100), default 80. - style (ParaphraseStyle | str): Style preset. Also sets decoding defaults (CONSERVATIVE: beam search, BALANCED/DIVERSE: nucleus sampling). - control_prefix (bool): Whether to prepend control prefix SEM_ SYN_ LEX_. Default True. - num_candidates (int): Number of sequences to return. - num_beams (int): Number of beams (1 with do_sample=True = plain sampling). - oversample (int): Extra sequences generated beyond num_candidates, default 2. - estimator: Quality estimator used with min_semantic; never loaded implicitly. - min_semantic (float): Drop candidates whose estimated semantic score is below this value (requires an estimator). - max_length (int): Max length. - and any other transformers.GenerationConfig parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of paraphrased strings. |
Source code in src/vietquill/generation/controllable_paraphraser/auto.py
paraphrases(texts: List[str], **kwargs) -> List[List[str]]
¶
Generates paraphrases for a batch of texts using the single loaded model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
List[str]
|
List of input texts to paraphrase. |
required |
**kwargs
|
Generation parameters and control values (same as paraphrase method). - batch_size (int, optional): Chunk size for batch processing. |
{}
|
Returns:
| Type | Description |
|---|---|
List[List[str]]
|
List of lists of paraphrased strings. |
Source code in src/vietquill/generation/controllable_paraphraser/auto.py
vietquill.generation.controllable_paraphraser.EnsembleModelForParaphraseGeneration(hub_id: str = None, device: str = None)
¶
Bases: BaseParaphraseGenerator
Quality Control Paraphraser with automatic routing between specialized sentence and question models.
Initializes the Ensemble Paraphraser with support for both sentence and question models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hub_id
|
str
|
Path or HF name for the unified model repo. |
None
|
device
|
str
|
Device to run the model on. |
None
|
Source code in src/vietquill/generation/controllable_paraphraser/ensemble.py
paraphrase(text: str, **kwargs) -> List[str]
¶
Generates paraphrases with quality control constraints. Automatically detects if the input is a question and routes to the corresponding model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input text to paraphrase. |
required |
**kwargs
|
Generation parameters and control values. - semantic (int): Semantic control (0-100), default 90. - syntactic (int): Syntactic control (0-100), default 85. - lexical (int): Lexical control (0-100), default 80. - style (ParaphraseStyle | str): Style preset. Also sets decoding defaults (CONSERVATIVE: beam search, BALANCED/DIVERSE: nucleus sampling). - num_candidates (int): Number of sequences to return. - num_beams (int): Number of beams (1 with do_sample=True = plain sampling). - oversample (int): Extra sequences generated beyond num_candidates, default 2. - estimator: Quality estimator used with min_semantic; never loaded implicitly. - min_semantic (float): Drop candidates whose estimated semantic score is below this value (requires an estimator). - max_length (int): Max length. - and any other transformers.GenerationConfig parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of paraphrased strings. |
Source code in src/vietquill/generation/controllable_paraphraser/ensemble.py
paraphrases(texts: List[str], **kwargs) -> List[List[str]]
¶
Generates paraphrases for a batch of texts. Automatically groups questions and sentences to run them through their respective models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
List[str]
|
List of input texts to paraphrase. |
required |
**kwargs
|
Generation parameters and control values (same as paraphrase method). - batch_size (int, optional): Chunk size for batch processing. |
{}
|
Returns:
| Type | Description |
|---|---|
List[List[str]]
|
List of lists of paraphrased strings matching the original text order. |
Source code in src/vietquill/generation/controllable_paraphraser/ensemble.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
vietquill.generation.controllable_paraphraser.ParaphraseStyle
¶
Bases: Enum
vietquill.generation.fewshot_paraphraser.MimicControl
¶
Bases: BaseModel
Represents a user-defined semantic or stylistic control dimension.
vietquill.generation.fewshot_paraphraser.MimicExample
¶
Bases: BaseModel
Demonstrates an input-output transformation under a specific configuration of controls.
vietquill.generation.fewshot_paraphraser.Mimic
¶
Bases: BaseModel
Reusable transformation specification containing intent, control dimensions, and demonstrations.
validate_example_controls() -> Mimic
¶
Validate that all control names present in examples are declared in controls.
Source code in src/vietquill/generation/fewshot_paraphraser/fewshot_paraphraser.py
vietquill.generation.fewshot_paraphraser.FewshotModelForControllableParaphraseGeneration(client: Optional[Any] = None, model: Optional[str] = None, api_key: Optional[str] = None, base_url: Optional[str] = None, temperature: float = 0.7, max_tokens: Optional[int] = None, top_p: Optional[float] = None, timeout: Optional[float] = None, **extra_default_kwargs)
¶
Few-shot controllable paraphrasing generator for VietQuill using the Mimic paradigm.
The generator infers transformation behavior from demonstration examples and generates paraphrases for new inputs according to a target output control specification. Powered by the OpenAI Python SDK and fully compatible with OpenRouter and any OpenAI-compatible endpoint.
Initialize FewshotModelForControllableParaphraseGeneration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Optional[Any]
|
Pre-configured OpenAI or OpenAI-compatible client instance. |
None
|
model
|
Optional[str]
|
Model identifier (e.g. 'gpt-4o-mini', 'qwen/qwen-2.5-72b-instruct', etc.). Defaults to 'openai/gpt-4o-mini' on OpenRouter and 'gpt-4o-mini' elsewhere. |
None
|
api_key
|
Optional[str]
|
API key if client is not directly provided. |
None
|
base_url
|
Optional[str]
|
Base URL for OpenAI-compatible providers (e.g. 'https://openrouter.ai/api/v1'). |
None
|
temperature
|
float
|
Sampling temperature for generation. |
0.7
|
max_tokens
|
Optional[int]
|
Maximum tokens to generate in response. |
None
|
top_p
|
Optional[float]
|
Top-p nucleus sampling parameter. |
None
|
timeout
|
Optional[float]
|
Request timeout in seconds. |
None
|
**extra_default_kwargs
|
Additional parameters forwarded to client.chat.completions.create. |
{}
|
Source code in src/vietquill/generation/fewshot_paraphraser/fewshot_paraphraser.py
build_messages(mimic: Mimic, input_text: str, output_control: Dict[str, ControlValue]) -> List[Dict[str, str]]
¶
Construct the Chat Completion messages payload (system and user messages).
Source code in src/vietquill/generation/fewshot_paraphraser/fewshot_paraphraser.py
build_prompt(mimic: Mimic, input_text: str, output_control: Dict[str, ControlValue]) -> str
¶
Construct the few-shot prompt for text transformation.
Source code in src/vietquill/generation/fewshot_paraphraser/fewshot_paraphraser.py
paraphrase(mimic: Mimic, input_text: str, output_control: Dict[str, ControlValue], temperature: Optional[float] = None, max_tokens: Optional[int] = None, **kwargs) -> str
¶
Generate a paraphrase for the input_text adhering to the target output_control.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mimic
|
Mimic
|
The Mimic specification containing intent, controls, and demonstrations. |
required |
input_text
|
str
|
The Vietnamese sentence or paragraph to paraphrase. |
required |
output_control
|
Dict[str, ControlValue]
|
Desired control values for the target output. |
required |
temperature
|
Optional[float]
|
Optional sampling temperature overriding default. |
None
|
max_tokens
|
Optional[int]
|
Optional token limit overriding default. |
None
|
**kwargs
|
Extra parameters passed to client.chat.completions.create. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The generated paraphrase text in Vietnamese. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input_text is empty or control names are undefined. |
Source code in src/vietquill/generation/fewshot_paraphraser/fewshot_paraphraser.py
validate(mimic: Mimic, input_text: str, output_control: Dict[str, ControlValue]) -> None
¶
Validate input parameters and verify consistency between controls and definitions.
Raises:
| Type | Description |
|---|---|
ValueError
|
If input_text is empty or if any control names in examples or output_control are not defined in mimic.controls. |
TypeError
|
If arguments are of incorrect types. |