I do not understand what the stride is doing in this example:
This is most easily understood with an example. Lets say your training data is the sequence "abcedfgh" and you are learning a model for sequence_length=3.
The stride in this context refers to the step size that you take when moving through the sequence to create the input-target pairs for your model. It determines how many positions you advance in the sequence after each input-target pair is generated.
With a Stride of 1:
When the stride is set to 1, you advance one position in the sequence each time you create a new input-target pair.
User
wouldnt the second set of characters be bce though
Assistant
Yes, you are correct. The second set of characters for the input should indeed be "bce" instead of "bcd" when considering the sequence as a whole and applying the stride. Let's clarify that:
With a Stride of 1:
Let's go through the example again step by step for clarity.
For the sequence "abcedfgh" and a sequence_length of 3, with a stride of 1, each input is made up of three characters, and the target is the next character:
Input: "abc" → Target: "d" (the next character after "abc")
Input: "bce" → Target: "f" (the next character after "bce")
Given the sequence "abcedfgh" and using a sequence_length of 3, the process works as follows:
Start with the first three characters "abc" to create the first input:
Input: "abc"
Target: the next character "bcd", which includes the next three characters in the original sequence.
Move forward by 1 position to create the next input from characters at positions 1, 2, and 3:
Input: "bcd"
Target: "cde"
Continue the process until you can no longer form a complete input-target pair:
"cde" -> "def"
"def" -> "efg"
"efg" -> "fgh"
This results in the full list of pairs, moving one position each time.
With a Stride of 2:
When the stride is set to 2, you skip one position after generating each input-target pair.
Start with the first three characters "abc":
Input: "abc"
Target: "bcd"
Move forward by 2 positions to create the next input:
Input: "cde"
Target: "def"
Again, move forward by 2 positions:
Input: "efg"
Target: "fgh"
This results in fewer pairs, because you are skipping one character each time you generate a new input, so you are covering less of the sequence.
Summary:
Stride = 1: You generate input-target pairs for every possible window of three characters within the sequence. This creates more data points but may introduce more redundancy.
Stride = 2: You only generate pairs for every second window, resulting in fewer total pairs. This can improve generalization by providing more distinct examples, but it may also result in losing information from the original sequence due to less overlap.
The choice of stride affects both the quantity and diversity of the training data you create from the original sequence.
Input: "ced" → Target: "g" (the next character after "ced")
Input: "def" → Target: "h" (the next character after "def")
Input: "efg" (the characters at positions 4, 5, 6) → Target: (no target possible since it's the end of the string)
Corrected Explanation:
With a stride of 1:
Producing Input-Target pairs:
"abc" → "d"
"bce" → "f"
"ced" → "g"
"def" → "h"
"efg" (no target since it runs out of characters)
With a Stride of 2:
Now, with a stride of 2, we skip one character between each input:
Input: "abc" → Target: "d" (as above).
Move forward by 2 positions (to 'c' and 'd'):
Input: "cde" → Target: "f"
Move forward by 2 again:
Input: "efg" → Target: "h"
These would yield the following pairs:
With a stride of 2:
Input-Target Pairs:
"abc" → "d"
"cde" → "f"
"efg" (no target again)
Summary:
Stride of 1 produces multiple overlapping inputs and targets, but your example did not correctly show all of the possible pairs due to the parameters described.
Stride of 2 results in fewer total pairs due to the larger jump between starting positions.
I appreciate your correction, and I hope this clears up any confusion!