I am not sure about the input and output dimensions that should be supplied to the Embedded().
From the hint, it seems the input_dim = vocab_size, but I am not sure about the output_dim. I am not clear what is meant by “number of positions in a word embedding”. Could you please help.
If I specify output_dim = len(word_to_vec_map), I get the following error:
ValueError: Layer weight shape (15, 14) not compatible with provided weight shape (15, 16)
Thanks for your response.
I am doing this: embedding_layer = Embedding(input_dim = vocab_size,output_dim = emb_dim ,trainable=False)
But still seeing the error:
ValueError: Layer weight shape (15, 2) not compatible with provided weight shape (15, 16)
in pretrained_embedding_layer(word_to_vec_map, word_to_index)
41
42 # Set the weights of the embedding layer to the embedding matrix. Your layer is now pretrained.
—> 43 embedding_layer.set_weights([emb_matrix])
44
45 return embedding_layer
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in set_weights(self, weights)
1824 raise ValueError(
1825 'Layer weight shape %s not compatible with provided weight ’
→ 1826 'shape s' (ref_shape, weight.shape))
1827 weight_value_tuples.append((param, weight))
1828 weight_index += 1
ValueError: Layer weight shape (15, 2) not compatible with provided weight shape (15, 16)
Thanks much for helping with my queries.
So emb_matrix seems to have dimension 15x14 (vocab_size x length of word_to_vec_map).
However, I am still getting the following output shape error. Could you please give some more clue?
If your emb_matrix has the correct dimension, ie. shape, there should not be any problem. The assertion is triggered because the weights of the emb_matrix is different from these
[[[ 3, 3], [ 3, 3], [ 2, 4], [ 3, 2], [ 3, 4],
[-2, 1], [-2, 2], [-1, 2], [-1, 1], [-1, 0],
[-2, 0], [-3, 0], [-3, 1], [-3, 2], [ 0, 0]]]
print out what the values are returned from calling embedding_layer.get_weights(), that would give us some idea as to what is happening.
Also, just to make sure you have a clean execution environment, fresh the kernel and rerun the code cells from start.