shape issue in the dynamic_decode with GreedyEmbeddingHelper
Hello,
i'm trying dynamic_decode with GreedyEmbeddingHelper, but i got a error of shape:
ValueError: The shape for decoder_1/decoder/while/Merge_7:0 is not an invariant for the loop. It enters the loop with shape (1, 128), but has shape (?, 128) after one iteration. Provide shape invariants using either the shape_invariants` argument of tf.while_loop or set_shape() on the loop variables.
PS. 128 is embedding size
i tried batch_size with 2, work fine, but not with size 1.
hi, i have the same problem. did you get the solutions?
I got this exact same problem.
Can you provide a command that can regenerate the issue with this codebase? Also python version and tensorflow version may also help.
I use python3 + tensorflow1.4. And i got the same problem. Did you get solutions?
python 3.6 + tf 1.5 same here, batch_size = 2 works fine and batch_size = 1 raises the error
Same issue. Also, how does one perform inference for a single sequence if the greedy embedding helper does not accept batch size 1?
This workaround fixes batch size 1 (batch size 0 is still broken):
class FixedHelper(seq2seq.GreedyEmbeddingHelper):
def sample(self, *args, **kwargs):
result = super().sample(*args, **kwargs)
result.set_shape([batch_size])
return result
@tavianator Is batch_size = 1 for this case? I tried the value but it was already 1 and got same error
result = Tensor("decoder/decoder/while/BasicDecoderStep/ArgMax:0", shape=(1,), dtype=int32) befor set_shape
Same issue. Also, how does one perform inference for a single sequence if the greedy embedding helper does not accept batch size 1?
I think the best way to do that is to create a dummy sequence, like an empty one and then pass both of the single sentence appended by the empty one to the greedy embedding
I'm also having exactly this problem, with python 2.7.12 and tf 1.13.1.
I don't seem to get the FixedHelper workaround mentioned by @tavianator to work..
When replacing result = super().sample(*args, **kwargs) with result = super(tf.contrib.seq2seq.GreedyEmbeddingHelper, self).sample(*args, **kwargs),
i get "AttributeError: 'NoneType' object has no attribute 'set_shape'"
I used a batch size of 1.
@roholazandie, how could I best proceed adding this empty embedding? Should it be added to the initial_state of the following BasicDecoder, which is followed by dynamic_decode?
I found a solution to this problem, at this link.
The way to go is to set the start tokens in the following manner:
batch_size = tf.shape(self.inputs)[0:1]
start_tokens = tf.ones(batch_size, dtype = tf.int32) * <your start token idx>
Here self.inputs refers to the input tensor [edits: markup]