I am writing code inspired from https://www.tensorflow.org/addons/api_docs/python/tfa/seq2seq/BasicDecoder.
In the translation/generation we instantiate a BasicDecoder
decoder_instance = tfa.seq2seq.BasicDecoder(cell=decoder.rnn_cell, \
sampler=greedy_sampler, output_layer=decoder.fc)
and call this decoder with the followings args
outputs, _, _ = decoder_instance(decoder_embedding_matrix, \
start_tokens = start_tokens, end_token= end_token, initial_state=decoder_initial_state)
What should be start_tockens and end_token, what do they represent? An example in the BaseDecoder's signature gives :
Example using `tfa.seq2seq.GreedyEmbeddingSampler` for inference:
>>> sampler = tfa.seq2seq.GreedyEmbeddingSampler(embedding_layer)
>>> decoder = tfa.seq2seq.BasicDecoder(
... decoder_cell, sampler, output_layer, maximum_iterations=10)
>>>
>>> initial_state = decoder_cell.get_initial_state(batch_size=batch_size, dtype=tf.float32)
>>> start_tokens = tf.fill([batch_size], 1)
>>> end_token = 2
>>>
>>> output, state, lengths = decoder(
... None, start_tokens=start_tokens, end_token=end_token, initial_state=initial_state)
>>>
>>> output.sample_id.shape
TensorShape([4, 10])
For the translation task they are
start_tokens = tf.fill([inference_batch_size], targ_lang.word_index['<start>'])
end_token = targ_lang.word_index['<end>']
In my application, the input chain of characters has the form
next_char = tf.constant(['Glücklicherweise '])
input_chars = tf.strings.unicode_split(next_char, 'UTF-8')
input_ids = ids_from_chars(input_chars).to_tensor()
The model is trained to generate the next token. The generator should produce "lücklicherweise x" where x stands for the most probable (or some more elaborated search) next character.
