What a sequence model sees before it decides
Audit sequence windows with a row-by-row ledger for input availability, target horizons, and offline and live alignment.

A perfect tensor with the wrong last row
The tensor passes every check. It has shape (1, 4, 2), the entries are finite, and the columns have the expected floating-point type. The model receives a batch of one, with four steps and two features per step. In this hypothetical example, the decision log says 09:20:03 UTC. The last row in the tensor belongs to the bar that closes at 09:25. The row has borrowed nearly five minutes from the future, and the type checker has no reason to complain.
Suppose the approved input was supposed to contain rows zero through three. A builder computes the start from the first target row and forgets that its slice stops just before the end index. It shifts the start and end together, producing rows one through four. Both versions contain four rows and the same two columns. Every step still follows the previous one in chronological order. A quick plot even shows a smooth sequence. Only the comparison with the declared decision time exposes the mistake.
Changing the model architecture would leave that sequence intact. So would increasing the amount of validation data or replacing a training framework. To isolate this class of errors, record the identities of the rows in each example, then compare them with an answer you can derive without calling the window builder. Use a case where the wrong row contains a conspicuously different value, and keep the identity check even if other tests compare the numeric tensor. Two consecutive rows can have exactly the same feature values.
This article follows one hypothetical five-minute feed and one fixed decision throughout. The aim is to reconstruct what the model can see, when the experiment can score its answer, and when an execution simulator can start looking for a quote. The three questions belong to the same example and use different timestamps. A compact ledger can answer all three without reference to the internals of a recurrent network or a transformer. Once the ledger is sound, you can change the model and still know precisely which observations it received.
Give the decision a clock
A time column is useful only after you specify what it measures. A feed might stamp an aggregated bar with its opening time or the time at which the interval ends. In the example here, 09:20 identifies the end of the interval from 09:15 up to 09:20. That convention keeps aggregation intervals distinct. It still leaves open when the completed row was delivered and when the feature calculation finished. Converting everything to UTC helps with comparison, but it cannot recover any of those missing meanings. The discussion of market data timestamps covers those distinctions in more detail.
Keep event time and availability time as separate fields. Event time locates the observation in the process it describes. Availability time records when the version used by the model first became usable on its path to inference. In the hypothetical feed, each bar is usable two seconds after its close. Assume that constructing both features takes no additional time for this fixture. In a real system, that assumption would need measurement. A late validation pass or a secondary lookup can move the feature’s availability beyond that of the bar from which most of it was computed.
The decision cutoff for row three is 09:20:03 UTC. Its bar became usable at 09:20:02, which leaves one second in this simplified fixture. We allow observations whose usability time is at or before the cutoff. If events share the same recorded instant, implement that rule using an observable ordering, such as a sequence number within an ingestion log. If the log cannot resolve a tie, define a policy that excludes those tied observations from the snapshot. An inclusive timestamp comparison by itself can put an event before inference even if it arrived afterward.
The cutoff applies to each value and to the version of that value. Imagine that the provider revises the 09:20 bar at 09:22. A historian might store only the revised value under the original close time. A replay that consults the final history would then reconstruct a row with the correct identifier and the wrong contents. Preserve either the snapshots that were served or a version history that lets you retrieve the value as of the cutoff. Agree on this contract before writing the slices. Otherwise both the training builder and the streaming builder can pass their own tests while operating on different versions of the past.
A six-row ledger you can audit by hand
All values and times in this ledger are hypothetical. The grid is equally spaced and has no missing bars. The close is measured in arbitrary price units. The count is the number of updates recorded during the bar. Use those two columns, in that order, as unscaled features for the first test. The raw magnitudes make an unintended shift easy to spot.
| Row | Bar close UTC | Usable UTC | Close | Updates |
|---|---|---|---|---|
| 0 | 09:05 | 09:05:02 | 100 | 8 |
| 1 | 09:10 | 09:10:02 | 101 | 6 |
| 2 | 09:15 | 09:15:02 | 99 | 9 |
| 3 | 09:20 | 09:20:02 | 102 | 7 |
| 4 | 09:25 | 09:25:02 | 105 | 11 |
| 5 | 09:30 | 09:30:02 | 104 | 5 |
Let t = 3 be the last input row for the decision at 09:20:03. The four closed bars are t − 3 through t, which gives rows zero, one, two, and three. The expected input is [[100, 8], [101, 6], [99, 9], [102, 7]]. The two target rows are t + 1 and t + 2, or four and five. If the target consists of the changes in close relative to the final input close, the expected vector is [105 − 102, 104 − 102] = [3, 2] price units. The first step compares both closes at its specified horizon, as does the second. Using the change from row four to row five would answer a different question.
There is exactly one complete supervised example in this six-row fixture. A decision anchored one row earlier would lack one required historical bar. Advancing to row four would produce valid inputs from rows one through four if the decision moved to 09:25:03. Its label would need rows five and six, and row six is absent. A live inference path can face the latter situation routinely. Its output is eligible to be logged immediately, and scoring waits for the labels. A dataset loader that discards incomplete examples for training should leave this inference behavior available.
The reference close of 102 defines the statistical target. Now suppose the first eligible quote in the hypothetical execution feed arrives at 09:20:04 and has a bid of 102.1 and an ask of 102.3. A simulated market buy can first be considered against that quote under this fixture’s rules. The ask is a candidate execution reference under those rules, with fill and size still governed by the execution model. The label value of three measures a change from the earlier close. It does not express the result of buying at 102.3. Log the target reference and the earliest execution quote independently, including the quote’s own source and sequence.
The fixture assumes that 09:20:03 also marks the end of decision processing. If the snapshot closes at that time but the order is only ready at 09:20:05, the 09:20:04 quote arrived before the order could be sent. A simulator that starts its quote search at order readiness must look again. Retain both times so faster historical feature calculation cannot silently give the experiment earlier execution opportunities than the scheduled system has.
Count positions from a common origin
Choose the start of the input as position zero and write down the whole span used by an example. Here input_width = 4 counts input steps. label_width = 2 counts target steps. In the convention used in this article, shift = 2 measures the distance from the last input position to the last label position. The span therefore has input_width + shift = 6 positions. The first label is at position 6 − 2 = 4. The last input is at position 4 − 1 = 3, so the first label is one bar ahead of that input and the last label is two bars ahead. TensorFlow uses this same window convention in its time-series tutorial.
Take start row s. The input slice with an exclusive stop is [s, s + 4), and the target slice is [s + 4, s + 6). The decision is anchored to row s + 3. A builder that takes the label start, s + 4, as the last input produces the equal-shaped error from the opening. With zero-based indexing, a slice ending at s + 5 includes row s + 4. The row at the exclusive stop is never a member of the slice. Checking the first included index and the last included index catches a mistake that can be difficult to see by reading two successive slicing expressions.
For a variation, ask for two labels at horizons two and three. Keep the width of four and set the shift to three. The span now uses seven positions, the first label offset is five, and the last is six. Position four is skipped by both the input and the target. This gap is a deliberate forecasting specification. With a single label at horizon three, use the same shift and a label width of one. The last label stays at position six. Write the desired horizons before choosing the parameters, especially when an API or internal helper uses the same parameter name for a different distance.
For a hypothetical review of a helper, ask two people to work from opposite ends. One writes the full row list starting from s = 0. The other starts at the timestamp of the last input and names the desired observed closes to score. Compare their answers using timestamps and source row IDs. Agreement gives you an expected result independent of both the batch builder and any dataset adapter.
Sampling inside a window and stepping between windows
Two controls can produce the same number of input steps while changing which observations enter those steps. Sampling rate is the distance between successive positions inside one window, measured in rows of the base grid. Stride is the distance between successive window starts. In a hypothetical grid of eleven rows, take an input width of four, a sampling rate of two, and a stride of two. Starting at zero gives inputs [0, 2, 4, 6]. Starting at two gives [2, 4, 6, 8]. Starting at four gives [4, 6, 8, 10]. The three windows share positions even though none uses adjacent rows within the window.
With zero-based indices, the final input is at s + (4 − 1) × 2 = s + 6. Four sampled steps span six base intervals, which amount to thirty minutes on the five-minute grid. At stride two, starts are ten minutes apart. With stride one, starts would be five minutes apart and a window starting at one would use [1, 3, 5, 7]. Picking a stride changes how frequently the builder creates examples. A live scheduler can have a cadence of its own, which should be documented with comparable units.
Now keep the labels one and two base bars ahead of the final input. For start zero they are [7, 8], and for start two they are [9, 10]. Start four has a valid input window for inference but needs labels [11, 12] for training. If the intended horizon used the same spacing as the sampled inputs, one sampled step ahead would mean two base intervals. For the first window a two-step target on that sampled grid would be [8, 10]. Specify the grid on which each offset is measured. The difference changes the experiment even when the target shape agrees.
Keras documents equally spaced data along axis zero, a target indexed by the start of its input window, and distinct options for sampling inside windows and moving between starts. When using that helper, construct the target associated with start zero from rows seven and eight for this base-bar example. Feeding a vector already keyed by the decision row needs a deliberate remapping. Confirm which starts survive the target requirement in your adapter. Keras time-series data loading
Separate causal lookback from overlapping outcomes
Extend the original hypothetical six-row fixture with row six at 09:35, close 103, usable at 09:35:02. The decision anchored to row three uses inputs [0, 1, 2, 3] and target rows [4, 5]. The next decision, anchored to row four, uses inputs [1, 2, 3, 4] and target rows [5, 6]. For that second decision the reference close is 105, so its target vector is [104 − 105, 103 − 105] = [−1, −2] price units. Its row four input is permissible at 09:25:03 because the bar was usable one second earlier.
The inputs overlap at rows one, two, and three. The target vectors share the observed close at row five, although their values use different reference closes. Row four appears on the target side of the earlier example and the input side of the later one. All three relationships follow directly from the specification. Lookback overlap describes shared history available at two decision times. Target overlap describes shared realized information that becomes available after those decisions. Detect leakage by checking whether the relevant information was available when a decision was served or when the model was fitted.
Imagine reporting the errors for both horizons and counting four vector entries as four independent pieces of evidence. The entries involving row five can move together if its observed close changes. When many consecutive decisions and horizons refer to common events, even a large evaluation table may contain relatively few distinct observations from which to judge behavior. Report the number of decisions, the horizon positions, and the periods they cover. Group the analysis by decision interval or compare with a deliberately lower-frequency evaluation when you need a view less dominated by near-duplicate outcomes.
Compare label end times with the instant at which the training data is frozen. At 09:25:03 the outcome anchored to row three has its first component available and its second component pending. A system that fits only complete vectors cannot use the example at that moment. A system that trains with partially observed targets needs a separate rule, an explicit loss mask, and tests showing that unseen components make no contribution. The data model should keep label availability per component even if today’s training procedure consumes only complete vectors. It lets an auditor explain why a sample was deferred and when it became usable.
Split at the training freeze
For another hypothetical split, freeze training at 09:25:03 and make the decision anchored to row four the first evaluation case served with the frozen model and preprocessor. Assume they are ready at that instant. Decisions served earlier can supply training examples only when their complete labels were usable by the freeze. The row-three example ends at row five, whose value arrives at 09:30:02. Drop that example from this training set. In the tiny fixture, nothing remains for fitting a four-step input and a complete two-step target at this boundary. A real experiment would need earlier history. Fitting anyway would defeat the rule you wanted the fixture to test.
The first evaluation window reuses rows one through three, which were already observable before the freeze. Reusing those historical inputs is consistent with how a live buffer works. If the research design also calls for separate input histories to study sensitivity to adjacent contexts, record that as an additional evaluation decision and quantify how much data it removes. It is useful to keep decision membership, input membership, and outcome membership in separate fields so you can audit each boundary.
For a miniature normalization calculation independent of the supervised fixture, suppose the approved training fit rows have hypothetical closes 100, 101, and 99. Their mean is 100. Centering the later close 105 with the frozen mean yields 5. If you refit with that evaluation close included, the mean becomes 101.25 and the centered value becomes 3.75. Every downstream consumer receives a different value even though the row IDs and tensor shape match. The TensorFlow time-series tutorial fits normalization statistics on training data and applies them to the later partitions.
Choose whether the fitting population consists of unique approved training observations or repeated positions from all approved training windows. A central observation may appear several times in overlapped windows, while an edge observation appears once. Fitting on repeated positions changes the weighting and may be intentional. Preserve that choice and the fit row IDs with the fitted parameters. Use the same eligibility review for learned clipping bounds, imputation constants, and column selection. A preprocessor configured to update online needs its own timeline for updates, including whether the current observation updates the transform before or after inference. Feature availability and imputation explains how to inspect transformations whose inputs originate at several times.
Join symbols and releases by their first usable time
Keep 09:20:03 UTC as the decision cutoff and introduce a second hypothetical symbol. Its own 09:20 bar is usable at 09:20:06. Its 09:15 bar was usable at 09:15:04. A join on matching close times selects the 09:20 row from both symbols and creates a leak in just one column group. For a feature contract that permits carrying observations forward, the latest usable observation from the second symbol is its 09:15 bar, whose close time is five minutes and three seconds old at decision. Record the age relative to the event clock and distinguish it from the time since the record reached your system.
Add a hypothetical macro statistic for the previous calendar month. Its first release occurs today at 09:18:00, but the normalized record is available to your decision system at 09:20:08. At cutoff it is ineligible. If it is revised tomorrow, the newly released record becomes a different version and has its own usability time. Historical storage organised by reference period alone can make both writes appear to belong to the previous month. Use a key for the observation and another field for version availability, then test a lookup immediately before and after each boundary. A query for a past feature should be reproducible even after later values have arrived.
For the permitted carry-forward case, decide how much staleness a feature can tolerate. A hypothetical four-minute limit would make the second symbol unavailable at 09:20:03 despite the presence of a known older value. A six-minute limit would admit it and retain the age field. If that symbol is mandatory, suppress the decision when the candidate exceeds the agreed threshold. If it is optional, provide its missing indicator and apply the same rule in training. Avoid making the cutoff slip automatically while waiting for a delayed symbol. Waiting is a distinct policy with a new decision time and potentially a different opportunity to execute.
A joint tensor inherits the availability constraints of every source it contains. A useful audit writes one row per source contribution, with observation ID, version, event time, availability time, and the chosen action when a usable value cannot be found. Comparing only the main symbol’s last timestamp leaves delayed secondary inputs invisible.
Apply the same discipline to the earlier steps of the joint window. A design can store the secondary observation chosen when each primary bar was first processed, or rebuild the entire context as of the current cutoff. Those policies can produce different historical steps when an older record arrives late. For example, imagine the secondary 09:15 bar arrives at 09:19 instead of 09:15:04. It is visible by 09:20:03, but it could not have been selected at 09:15:03. A replay must reproduce whichever policy the streaming builder actually uses. In the stored-step design, changing a historical step would require an explicit update event.
Preserve the meaning of a missing interval
Suppose row two at 09:15 is missing from the hypothetical five-minute feed. A compact array of the available rows starts with times 09:05, 09:10, 09:20, and 09:25. Reading four adjacent positions no longer yields a window of four consecutive five-minute bars. The interval between the middle two positions is ten minutes. If the decision remains at 09:20:03, the compact sequence also needs an observation that arrives after the cutoff to make up its fourth step. What looks like an indexing fix changes both elapsed time and eligibility.
With a fixed clock grid, reserve the 09:15 position and decide explicitly how to encode it. One hypothetical policy emits a row containing a fill value and a missing indicator, with the 09:15 slot preserved. A padding mask can mark an entire timestep as unavailable when the model supports that treatment. A feature-level mask is useful when the main observation exists but one optional source is absent. Check the mask convention used by each consumer. A Boolean with a value of true can mean “keep” at one interface and “ignore” at another. If zero is a valid normalized value, using a zero fill alone leaves the distinction between absent and observed values ambiguous.
Test the behavior of the mask, including pooling and the loss, with an exaggerated hypothetical fill value. For a fully masked step, changing only that fill from zero to ten thousand should leave the valid output unchanged when the model’s contract guarantees that the step cannot contribute. If a convolution or a custom summary ingests masked positions before masking is applied, that test can reveal an unexpected contribution. Where the missingness itself is a feature, vary the fill while keeping the missing indicator fixed so the test isolates the fill mechanism.
An event-time sequence can deliberately retain only observations that arrive. In that design, include elapsed time or document that the model treats event positions as its unit of analysis. Then define target horizons explicitly in elapsed minutes or in future events. For a time-grid target, write down what happens when its endpoint is absent. Options include withholding the score or defining a later observation rule in advance and recording the resulting horizon. Quote or bar availability should be a property of the dataset design, with missing cases counted alongside scored cases. Otherwise the reported task can quietly become a task about periods in which the feed happened to be complete.
Decide who owns recurrent state
In a stateless setup, each hypothetical four-step example stands on its own. The model starts from its configured initial state for that example. A stateful setup can carry information across successive calls. That extends the effective input history beyond the four rows printed in the example ledger. Before adopting state carryover, specify which stream owns the state, which event sequence feeds it, and how to reconstruct it after a process restart. A clean tensor audit needs a state audit alongside it.
Consider a hypothetical batch with a sequence for symbol A in slot zero and symbol B in slot one. If the state mechanism binds a slot to its previous call, and the next batch swaps A and B, the A sequence begins with the state previously updated by B. The data for each sequence can still be locally sorted. Preserve slot-to-stream mapping across batches or manage state explicitly by stream identity. Verify the mapping at a partial batch or when one symbol misses a decision. Dropping a stream and compacting a batch can silently move another stream into its old slot.
There is a second issue with overlapping windows. If the application sends rows zero through three, keeps the final state, and then sends rows one through four, the recurrent computation consumes rows one, two, and three twice. Later evaluations will follow this repeated history when they reproduce the application, yet the system has diverged from the design of consuming each incoming row once. Choose between independent window replay and incremental updates when defining the inference protocol. For incremental updates, store the last processed row ID with the state and define what happens to duplicate and out-of-order arrivals.
Recurrent state belongs to a defined stream and a defined point in its history. At a boundary such as a restart, a stream change, or a fold with freshly fitted weights, make the reset and warm-up policy explicit. A hypothetical deployment that warms up using the preceding twenty eligible bars must replay those bars in order using the deployed weights and the deployed preprocessing parameters. A new fold cannot inherit state built by a different model during fitting. Test reset behavior by starting from two different prior runs and checking that the same approved warm-up and input produce the same state and output within the tolerance appropriate to the model.
Ask the offline and live paths for one golden sample
Choose the original decision at 09:20:03 and freeze its expected values as a golden sample, a hand-derived record used as an independent test oracle. The offline builder can receive the whole six-row fixture. The streaming builder receives arrivals in usability order and stops at the cutoff. Give both the same column contract. Compare their row identities before comparing arrays, then compare features, masks, ordering, and decision metadata. Compute the target separately from the two later rows and attach it only to the supervised explanation of the example.
In this hypothetical fixture the exact input values are small integers despite the floating-point storage, so exact equality is feasible. Once a preprocessor applies other formulas, choose a tolerance appropriate to the numerical range and compare the transform version as well. For a one-row test, delay row three’s arrival from 09:20:02 to 09:20:04 without changing the bar close. Under a policy that requires all four grid points and forbids a substitute for the current bar, both paths now withhold the 09:20:03 prediction. If only the streaming path withholds it, the offline builder is likely filtering by close time or consulting a value recorded after the cutoff.
Run a complementary test by changing row four’s hypothetical close from 105 to 115. The expected input still ends in [102, 7]. Its first label changes from 3 to 13, and its second component stays at 2. This test catches an accidental dependency of the input on the future, even if a later operation obscures the direct inclusion of row four. If the transformed input moves, inspect both the selection of rows and the fitting of the transform. A preprocessor fitted on the entire fixture could transmit the changed close to otherwise correctly sliced rows.
For a production-shaped parity test, send the same example through the actual offline and online entry points with fixture inputs and capture the tensors before model inference. Keep the expected sample in plain values so the test never uses the candidate window builder to compute its own expected answer. Then test the execution boundary with the 09:20:04 quote. Shape, type, finite values, and device placement still deserve checks. The semantic test answers the further question of whether the same permitted observations reached the system in the same roles.
Work a changed contract before you trust the abstraction
Return to the hypothetical original grid and anchor the decision to row four, where it moves to 09:25:03. Now require three input steps sampled every two base rows, and two target steps at horizons one and three base intervals. Before touching a loader, write the ledger by hand. Decide whether the six original rows suffice for the input, which labels are present, and when the example could first be scored in full. Assume a later hypothetical extension with row six closing at 09:35 with value 103 and row seven closing at 09:40 with value 107. Each bar follows the same two-second usability lag.
Start from the decision and subtract twice the sampling distance. The oldest input row is 4 − (3 − 1) × 2 = 0. The inputs are therefore [0, 2, 4], with feature pairs [[100, 8], [99, 9], [105, 11]]. The six original rows suffice for inference. The labels are rows 4 + 1 = 5 and 4 + 3 = 7. Their changes relative to the last input close are [104 − 105, 107 − 105] = [−1, 2]. Full scoring first becomes possible at 09:40:02. Row six is irrelevant to this target even though it lies inside the label span. A contiguous label slice of width two cannot describe exactly those requested horizons on the base grid. Select the explicit offsets or use a fixed output grid with a documented mask and test the mapping independently.
Now imagine the same input shape arriving at 09:25:01. The newest requested row four is still unavailable until 09:25:02. Under the exercise’s exact-input contract, the prediction waits or is suppressed according to the scheduling policy. A delayed prediction gets a new cutoff and execution reference. An engineering review can reproduce these expected outcomes from a short record that includes source versions, the grid, input offsets, label offsets, timing policy, and the scaler’s fit boundary. Keep one normal case, one delayed arrival, and one changed future observation with that record.
If you want a separate Forex source for study and testing, see the TradeAndRoll demo.



