0Pricing
Deep Learning Academy · レッスン

順序のための位置エンコーディング

系列内の位置情報をトークンに組み込みます

「順序のための位置エンコーディング」はCoddyKit上の無料Deep Learning Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDeep Learning Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Deep Learning Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Attention Ignores Order

Self-attention treats a sentence like a bag of tokens. Shuffle the words and the math barely changes, so the model has no built-in sense of order.

Order Carries Meaning

But order matters: "dog bites man" is not "man bites dog". We must hand the model some signal about each token's position.

Add, Do Not Append

The trick is to add a position vector directly to each token's embedding. Same shape, so attention sees content and place fused together.

x = token_emb + pos_emb

Sinusoidal Encoding

The original transformer used fixed sine and cosine waves of different frequencies, one pattern per dimension, to mark each position.

Why Sine Waves

Mixing frequencies gives every position a unique fingerprint, and the smooth waves let the model generalize to lengths it never saw in training.

The Formula

Even dimensions use sine, odd dimensions use cosine, with the wavelength growing across dimensions. That is the whole encoding recipe.

pe[:, 0::2] = torch.sin(pos / div)
pe[:, 1::2] = torch.cos(pos / div)

Relative Distance

A neat bonus: with sinusoids, the offset between two positions is easy to express, helping attention reason about relative distance.

Learned Positions

Modern models often skip sinusoids and use a learned embedding table, one trainable vector per position, just like word embeddings.

self.pos_emb = nn.Embedding(max_len, d_model)

Fixed vs Learned

Fixed sinusoids extrapolate to new lengths for free; learned tables fit your data but are capped at the maximum length you trained on.

Rotary Encoding

Newer transformers favor rotary position encoding, which rotates query and key vectors by an angle tied to position, baking order into attention itself.

Where It Goes

Whatever scheme you pick, positional info is injected once at the input, before the first attention layer ever runs.

Quick Check

Let's check why positional encoding exists.

Recap

You learned that attention ignores order, so we add positional encodings, whether sinusoidal, learned, or rotary, to tell tokens where they sit. Well done!

よくある質問

「順序のための位置エンコーディング」レッスンは無料ですか?

はい。「順序のための位置エンコーディング」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Deep Learning Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Deep Learning Academyコースには全4レッスンが含まれています。

「順序のための位置エンコーディング」で何を学びますか?

系列内の位置情報をトークンに組み込みます ブラウザで直接実行するハンズオンコードでDeep Learning Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Deep Learning Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDeep Learning Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「順序のための位置エンコーディング」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDeep Learning Academyレッスンでコードを書いて実行できますか?

はい。すべてのDeep Learning Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Self-Attention:Query、Key、Value
  2. Scaled Dot-ProductとMulti-Head
  3. 順序のための位置エンコーディング
  4. Transformer Encoderブロックを積み重ねる
← Deep Learning Academyに戻る