Hi @RyeToast
Forgive me for not answering your questions straight away. I hoped you will be able to complete this exercise on your own since the most of it is almost identical to the cell before the exercise.
So, if you have a fresh copy of the exercise, here are the steps (without revealing code) you need to make:
### START CODE HERE ###
# PROCESS THE SENTENCE TO TRANSLATE
# Convert the original string into a tensor
text =
Here the code is almost identical to the cell above after this comment:
# Convert it to a tensor
the only difference is that there we used eng_sentence
, while in your code you would use text
.
Second line asks you:
# Vectorize the text using the correct vectorizer
context =
Is again almost identical to the cell above after the comment:
# Vectorize it and pass it through the encoder
The difference is that there the variable is texts
while here we use text
(singular).
For the third line you have to implement:
# Get the encoded context (pass the context through the encoder)
# Hint: Remember you can get the encoder by using model.encoder
context =
This too is almost identical to the cell above, except what the hint asks you to pay attention to.
Now, after you processed the text, next step is to initialize the decoder and the loop.
So, for the fifth line you have:
# INITIAL STATE OF THE DECODER
# First token should be SOS token with shape (1,1)
next_token =
This line is completely identical to the cell above after this comment:
# Next token is Start-of-Sentence since you are starting fresh
For the sixth line you have:
# Initial hidden and cell states should be tensors of zeros with shape (1, UNITS)
state =
This again is almost identical to the:
# Hidden and Cell states of the LSTM can be mocked using uniform samples
Except that in the cell above the initial state was tf.random.uniform
while here you need tf.zeros
.
For the 7th line, you have:
# You are done when you draw a EOS token as next token (initial state is False)
done =
It should be completely identical to the cell above:
# You are not done until next token is EOS token
Now comes the loop part where we actually start to generate the translation. For this you have:
# Iterate for max_length iterations
for None in None(None):
As the code hint suggest, this loop should iterate at most max_length times. To achieve that you can use range()
function.
For the 9th line (or multiple lines, depends how you count), inside the loop, you have:
# Generate the next token
next_token, logit, state, done =
This line again is almost identical to the cell above after the comment:
# Generate next token
Except that here, the decoder is attribute of the model - model.decoder
and we do not use fixed temperature value, but we have temperature
as a parameter.
For the 10th line you have:
# If done then break out of the loop
if None:
None
Here we should check the done
variable, and to break out of the loop we use break
Python statement.
For the 11th line you have:
# Add next_token to the list of tokens
None.None(None)
Here we have a list (tokens
) initialized for us at the beginning, which we should append with the generated token (next_token
).
For the 12th line you have:
# Add logit to the list of logits
None.None(None)
### END CODE HERE ###
Here, again, we have a list (logits
) initialized for as at the beginning, which we should append with the logit output (logit
).
These are the steps needed for you to implement in order to make translation happen. Ask if any of those is not clear to you.
Cheers