• About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
TechTrendFeed
  • Home
  • Tech News
  • Cybersecurity
  • Software
  • Gaming
  • Machine Learning
  • Smart Home & IoT
No Result
View All Result
  • Home
  • Tech News
  • Cybersecurity
  • Software
  • Gaming
  • Machine Learning
  • Smart Home & IoT
No Result
View All Result
TechTrendFeed
No Result
View All Result

Why Transformers Want Positional Encoding For Time Sequence: A Visible Information

Admin by Admin
September 6, 2026
Home Machine Learning
Share on FacebookShare on Twitter


Whereas digging into basis fashions for time sequence, I spotted that I may not likely perceive them with out first understanding transformers. I didn’t wish to use these fashions as black packing containers, so I began tracing the concepts backward, from basis fashions to transformers, and from transformers to self-attention. What made the transition fascinating is that though transformers have been initially constructed for language, the core thought carries naturally to time sequence. The 2 modalities are very completely different, however they share one thing basic: each are sequences, and in each circumstances, order modifications which means.

In language, canine bites man could be very completely different from man bites canine.

Time sequence aren’t any completely different. A temperature of 30∘30^circ30∘ yesterday and 20∘20^circ20∘ right this moment tells a distinct story from 20∘20^circ20∘yesterday and 30∘30^circ30∘ right this moment. The values stands out as the identical, however their order modifications the which means of the sequence.

The query is that if self-attention seems to be in any respect observations directly, how does a transformer know which remark got here first, which got here later, or how far aside two observations are?

That query led me to positional encoding.

What stunned me most was how such a easy mathematical thought may give a Transformer a way of order. The precise strategies have developed significantly since then, however the underlying drawback stays the identical.

This text is my try to construct that instinct from the bottom up, beginning with a easy time sequence and following the trail from uncooked observations to self-attention and eventually to positional encoding.

From scalar observations to vector representations

Take into account a easy time sequence containing the temperature recorded over 5 weekdays:

Instance of time sequence: 5-day temperature historical past

Every remark xtx_txt​ is barely a scalar. A transformer, nevertheless, operates on vectors of dimensionality dmodeld_{mannequin}dmodel​. The scalar observations subsequently must be mapped into that illustration house first.

A easy method to do that is thru a discovered linear projection i.e. embedding:

et=Wext+bee_t = W_e x_t + b_eet​=We​xt​+be​

giving us a sequence of vector representations: e1,e2,e3,e4,e5e_1, e_2, e_3, e_4, e_5e1​,e2​,e3​,e4​,e5​

An embedding is a deep, summary illustration of the sequence within the type of a multidimensional numerical vector that encodes its options and that the mannequin understands. [1]

Every time sequence token is represented by a discovered embedding

Every ete_tet​ captures details about the noticed worth at that timestep, however at this level, it’s only a illustration of the remark.

The necessary phrase right here is discovered. The mannequin will not be given a predefined vector illustration for a temperature equivalent to 18∘18^circ18∘. The parameters WeW_eWe​ and beb_ebe​ are discovered throughout coaching in order that the ensuing representations grow to be helpful for the duty.

At this level, ete_tet​ represents what was noticed. It doesn’t but inform the mannequin the place that remark occurred within the sequence.

How self-attention builds context?

Self-attention permits every remark to make use of info from the remainder of the sequence.

Suppose we wish to replace Friday’s illustration. The mannequin first creates three discovered projections from each ete_tet​:

qt=WQet,okayt=WOkayet,vt=WVetq_t = W_Q e_t,qquad k_t = W_K e_t,qquad v_t = W_V e_tqt​=WQ​et​,okayt​=WOkay​et​,vt​=WV​et​
Question, key, and worth vectors are discovered within the self-attention block

The matrices WQW_QWQ​, WOkayW_KWOkay​ and WVW_VWV​ are additionally discovered throughout coaching. The mannequin will not be advised beforehand what a helpful question, key, or worth ought to appear to be.

For Friday, its question q5q_5q5​ is in contrast with the keys of all observations: okay1,okay2,okay3,okay4,okay5k_1, k_2, k_3, k_4, k_5okay1​,okay2​,okay3​,okay4​,okay5​.

Every comparability produces an consideration rating:

s5,j=q5⊤okayjdokays_{5,j} = frac{q_5^high k_j}{sqrt{d_k}}s5,j​=dokay​​q5⊤​okayj​​

which measures how related remark ‘j’ is when updating Friday’s illustration. The scaling issue dokaysqrt{d_k} dokay​​prevents the dot merchandise from rising too massive because the dimensionality of the question and key vectors will increase.

These scores are handed by a softmax perform to transform them into consideration weights:

α5,j=exp⁡(s5,j)∑j′exp⁡(s5,j′)alpha_{5,j} = frac{exp(s_{5,j})}{sum_{j’} exp(s_{5,j’})}α5,j​=∑j′​exp(s5,j′​)exp(s5,j​)​

Lastly, these weights are used to mix the worth vectors:

z5=∑jα5,jvj.z_5 = sum_j alpha_{5,j}v_j.z5​=j∑​α5,j​vj​.

So e5e_5e5​ is Friday’s illustration earlier than incorporating info from the remainder of the sequence, whereas z5z_5z5​ is its context-aware illustration after self-attention.

Briefly:

Queries and keys study which observations are related to at least one one other. Values carry the knowledge that’s mixed to type the brand new illustration.

What occurs if we shuffle the sequence?

Now comes the necessary query.

Suppose the identical 5 temperature observations are rearranged.

The values themselves haven’t modified; solely the order has. After the discovered projection, we nonetheless have the identical set of worth representations, simply rearranged.

Self-attention can nonetheless examine every illustration with all of the others. The identical question, key, and worth projections are utilized, and the identical sorts of pairwise relationships can nonetheless be computed.

What has disappeared is the temporal construction.

Nothing inside e(27∘)e(27^circ)e(27∘) says that it initially got here from Thursday. Nothing inside e(18∘)e(18^circ)e(18∘) says that it occurred after e(27∘)e(27^circ)e(27∘). Additionally, if Wednesday and Friday have the identical temperature worth, the discovered projection will map them to the identical embedding vector. With out positional info, the mannequin subsequently has no option to distinguish which embedding got here from Wednesday and which got here from Friday.

That is the important thing limitation:

Self-attention can study which observations are associated, however with out an extra positional sign, it has no built-in option to know the place these observations occurred within the sequence.

What ought to positional info inform the mannequin?

If self-attention doesn’t know the order of the observations, then the following query is: what sort of positional info could be helpful?

At a minimal, we’d need the mannequin to know:

  • Which place an remark belongs to?
    Place 2 needs to be distinguishable from place 20.

  • Which remark got here earlier than or after one other?
    The mannequin ought to have the ability to distinguish t−1t-1t−1 from t+1t+1t+1.

  • How far aside are two observations?
    In time sequence, the distinction between t−1t-1t−1, t−7,t-7,t−7, and t−30t-30t−30 may be necessary.

  • That close by positions are associated in a structured method.
    Place 10 and place 11 mustn’t appear to be two fully unrelated identifiers.

  • That the illustration stays helpful over longer sequences.
    Ideally, the positional scheme ought to nonetheless present significant construction because the sequence grows.

For time sequence, the third property is very helpful. A mannequin might care about an remark one step in the past due to short-term dependence, or seven steps in the past due to a weekly seasonal sample.

So positional info ought to do greater than merely assign a novel label to every timestep. It ought to give the mannequin a structured illustration of order and relative distance.

How can we signify place?

We now know what info is lacking. The following query is learn how to signify it.

A easy option to signify place could be to assign every timestep a quantity:

1,2,3,…1, 2, 3, ldots1,2,3,…

However feeding the uncooked place immediately into the mannequin will not be perfect. The values continue to grow with sequence size, and a single quantity doesn’t give the mannequin a wealthy illustration of positional relationships.

One of many authentic Transformer’s options was sinusoidal positional encoding, the place every place is represented utilizing sine and cosine capabilities at completely different frequencies.

Why sine and cosine?

Begin with the best two-dimensional instance:

pt=[sin⁡(t) cos⁡(t)]p_t = start{bmatrix} sin(t) cos(t) finish{bmatrix}pt​=[sin(t) cos(t)​]

As ttt modifications, the positional vector strikes easily round a circle that permits close by positions to have completely different however nonetheless associated representations.

Extra importantly, shifting ahead by the identical variety of steps produces the identical type of change within the positional illustration. For instance, an offset of seven positions has the identical mathematical relationship whether or not we transfer from place 3 to 10 or from place 20 to 27. That’s helpful for time sequence as a result of relative distance typically issues:

t−1,t−7,t−30t-1,qquad t-7,qquad t-30t−1,t−7,t−30

can signify very completely different temporal relationships.

The total sinusoidal positional encoding extends this concept throughout many dimensions:

PE(t,2i)=sin⁡(t100002i/dmannequin)PE(t,2i)= sinleft( frac{t}{10000^{2i/d_{textual content{mannequin}}}} proper)PE(t,2i)=sin(100002i/dmannequin​t​)
PE(t,2i+1)=cos⁡(t100002i/dmannequin)PE(t,2i+1)= cosleft( frac{t}{10000^{2i/d_{textual content{mannequin}}}} proper)PE(t,2i+1)=cos(100002i/dmannequin​t​)

Totally different dimensions use completely different frequencies. Some change shortly throughout close by positions, whereas others change far more slowly.

One helpful method to consider that is as many clocks operating at completely different speeds. Collectively, their readings give each place a structured positional signature.

So as a substitute of giving timestep (t) solely a quantity, we give it a vector:

pt∈Rdmannequinp_t in mathbb{R}^{d_{textual content{mannequin}}}pt​∈Rdmannequin​

that accommodates details about its place and its relationship to different positions.

Combining worth and place

After including positional info, every timestep is represented as:

ht=et+pth_t = e_t + p_tht​=et​+pt​

the place ete_tet​ represents the noticed worth and ptp_tpt​ represents its place within the sequence.

Self-attention now builds its queries and keys from this mixed illustration:

Q=HWQ,Okay=HWOkayQ = HW_Q,qquad Okay = HW_KQ=HWQ​,Okay=HWOkay​

So when the mannequin computes an consideration rating,

rating(i,j)=qi⊤okayj,textual content{rating}(i,j)=q_i^high k_j,rating(i,j)=qi⊤​okayj​,

the comparability is now not based mostly solely on the noticed values. The question and key vectors have been created from representations that already comprise positional info.

In consequence, the mannequin can study relationships that rely on each:

  • what was noticed, and

  • the place the observations occurred within the sequence.

For a time sequence, this implies the mannequin can probably study that an remark one timestep in the past needs to be handled in another way from one seven timesteps in the past, even when their values are comparable.

Positional encoding subsequently doesn’t inform the mannequin explicitly which lags are necessary. It offers self-attention the knowledge wanted to study which positional relationships matter for the duty.

Abstract

We began with a easy drawback: self-attention can examine each remark with each different remark, however by itself it doesn’t know the order wherein these observations occurred.

The answer is to counterpoint every worth illustration ete_tet​​ with a positional illustration ptp_tpt​​:

ht​=et​+pt​h_t​ = e_t ​+ p_t​ht​​=et​​+pt​​

Self-attention then builds its queries, keys, and values from hth_tht​​ fairly than from the worth illustration alone. This implies the eye mechanism can study relationships based mostly not solely on what was noticed, but in addition on the place that remark occurred within the sequence.

For usually sampled time sequence, this makes relationships equivalent to t−1, t−7, or t−24 accessible to the mannequin. A lag of 1 step might seize short-term dependence, whereas a lag of seven or twenty-four steps might correspond to a seasonal sample.

Positional encoding, nevertheless, represents sequence place, not essentially real-world time. If observations are irregularly spaced, being one place aside doesn’t at all times imply being one hour or at some point aside. That is the place richer temporal encodings and time options grow to be necessary.

Sinusoidal positional encoding is just one option to inject order right into a Transformer. Different approaches embrace discovered positional embeddings, the place the place vectors themselves are discovered throughout coaching, and relative positional encodings, which focus extra immediately on the space between two observations fairly than their absolute positions.

For time sequence, the issue can grow to be even richer. Sequence place is probably not sufficient: the mannequin may must know the precise timestamp, calendar results, periodicity, or irregular gaps between observations.

So the broader query will not be merely:

How will we inform a Transformer that that is place 7?

however fairly:

What notion of time does the mannequin really need for the duty?

···

And this brings me again to the place this exploration began: time-series basis fashions. Trendy architectures might use extra subtle approaches equivalent to rotary or discovered positional representations fairly than the unique sinusoidal formulation. However understanding the easy sinusoidal building offers us the muse for understanding why these strategies exist within the first place.

We now have now constructed the muse of why positional info is required, how it’s represented, and the way self-attention makes use of it. With this instinct in place, extra superior positional encoding strategies ought to really feel a lot simpler to know once we encounter them in future.

···

Observe: The figures on this article have been conceptually designed by the writer and generated and refined with the help of an AI image-generation device.

References

[1] Peixeiro, Marco. Time Sequence Forecasting Utilizing Basis Fashions: Learn how to Construct Excessive Accuracy Predictive Fashions. Manning, 2025.

[2] Davidson, Graeme, and Lei Ma. Time Sequence with PyTorch: Trendy Deep Studying Toolkit for Actual-World Forecasting Challenges. Packt Publishing, 2026.

Tags: EncodingGuidePositionalSeriesTimeTransformersVisual
Admin

Admin

Next Post
OpenAI brokers hijacked German web site earlier than Hugging Face hack, report claims

OpenAI brokers hijacked German web site earlier than Hugging Face hack, report claims

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Trending.

These 5 Easy Methods Helped Me Construct a Smarter House

These 5 Easy Methods Helped Me Construct a Smarter House

July 19, 2025
Scientists rework peacock feathers into tiny organic laser beams

Scientists rework peacock feathers into tiny organic laser beams

August 4, 2025
Discover a Software program Improvement Firm in Europe

Discover a Software program Improvement Firm in Europe

August 22, 2025
Arbitrage: Environment friendly Reasoning by way of Benefit-Conscious Hypothesis

Arbitrage: Environment friendly Reasoning by way of Benefit-Conscious Hypothesis

August 8, 2026
How A lot Does Error-Monitoring Software program Growth Value?

How A lot Does Error-Monitoring Software program Growth Value?

April 8, 2025

TechTrendFeed

Welcome to TechTrendFeed, your go-to source for the latest news and insights from the world of technology. Our mission is to bring you the most relevant and up-to-date information on everything tech-related, from machine learning and artificial intelligence to cybersecurity, gaming, and the exciting world of smart home technology and IoT.

Categories

  • Cybersecurity
  • Gaming
  • Machine Learning
  • Smart Home & IoT
  • Software
  • Tech News

Recent News

Why Transformers Want Positional Encoding For Time Sequence: A Visible Information

Why Transformers Want Positional Encoding For Time Sequence: A Visible Information

September 6, 2026
Elementor Professional WordPress Plugin Vulnerability Exploited to Hack Websites

Elementor Professional WordPress Plugin Vulnerability Exploited to Hack Websites

September 6, 2026
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us

© 2025 https://techtrendfeed.com/ - All Rights Reserved

No Result
View All Result
  • Home
  • Tech News
  • Cybersecurity
  • Software
  • Gaming
  • Machine Learning
  • Smart Home & IoT

© 2025 https://techtrendfeed.com/ - All Rights Reserved