Generates text using the model, given the input data and generation parameters. Args: data (str): The input text for generation. paras (Optional[Dict[str, float]], optional): A dictionary of generation parameters. Defaults to None. Returns:
(
self, data: str, paras: Optional[Dict[str, float]] = None
)
| 142 | return input_ids, attention_mask |
| 143 | |
| 144 | def forward( |
| 145 | self, data: str, paras: Optional[Dict[str, float]] = None |
| 146 | ) -> List[str]: |
| 147 | """ |
| 148 | Generates text using the model, given the input data and generation parameters. |
| 149 | |
| 150 | Args: |
| 151 | data (str): The input text for generation. |
| 152 | paras (Optional[Dict[str, float]], optional): A dictionary of generation parameters. Defaults to None. |
| 153 | |
| 154 | Returns: |
| 155 | List[str]: The list of generated texts. |
| 156 | """ |
| 157 | input_ids, attention_mask = self.preprocess(data) |
| 158 | |
| 159 | if not paras: |
| 160 | paras = self.default_paras |
| 161 | |
| 162 | outputs = self.streaming_topk_search( |
| 163 | input_ids, |
| 164 | attention_mask, |
| 165 | temperature=paras["temperature"], |
| 166 | repetition_penalty=paras["repetition_penalty"], |
| 167 | top_k=paras["top_k"], |
| 168 | top_p=paras["top_p"], |
| 169 | max_iterations=paras["max_iterations"], |
| 170 | regulation_start=paras["regulation_start"], |
| 171 | length_penalty=paras["length_penalty"], |
| 172 | max_time=paras["max_time"], |
| 173 | ) |
| 174 | |
| 175 | preds = self.tokenizer.batch_decode(outputs) |
| 176 | |
| 177 | res = [self.postprocess_remove_prefix(pred) for pred in preds] |
| 178 | |
| 179 | return res |
| 180 | |
| 181 | def postprocess_remove_prefix(self, preds_i: str) -> str: |
| 182 | """ |
no test coverage detected