| 212 | |
| 213 | # Plan to use this argument for all decoding in the future |
| 214 | class DecodingArgumentNew(object): |
| 215 | def __init__( self, |
| 216 | vocab_size, |
| 217 | start_id, |
| 218 | end_id, |
| 219 | max_seq_len, |
| 220 | beam_search_diversity_rate, |
| 221 | top_k, |
| 222 | top_p, |
| 223 | decoder_args): |
| 224 | ''' |
| 225 | The arguments of Decoding. |
| 226 | Decoding is the function which contains the whole translation process. |
| 227 | For example, the embedding lookup, position encoding, decoder, and |
| 228 | beam search or sampling to choose the token. |
| 229 | |
| 230 | Args: |
| 231 | vocab_size: The size of vocabulary of Decoding. |
| 232 | start_id: The id of start token in vocabulary. |
| 233 | end_id: The id of end token in vocabulary. |
| 234 | max_seq_len: The maximum length of sentence in translation. |
| 235 | decoder_args: The arguments of decoder layer. |
| 236 | ''' |
| 237 | |
| 238 | self.vocab_size = vocab_size |
| 239 | self.start_id = start_id |
| 240 | self.end_id = end_id |
| 241 | self.max_seq_len = max_seq_len |
| 242 | self.decoder_args = decoder_args |
| 243 | self.beam_search_diversity_rate = beam_search_diversity_rate |
| 244 | self.top_k = top_k |
| 245 | self.top_p = top_p |
| 246 | |
| 247 | def create_initializer(initializer_range=0.02, data_type=tf.float32): |
| 248 | return tf.truncated_normal_initializer(stddev=initializer_range, dtype=data_type) |
no outgoing calls
no test coverage detected