Skip to content
C.W.K.
Stream
Lesson 03 of 06 · published

What the Heck Is Direction (in AI Context)?

~8 min · direction, gradients, loss-landscape

Level 0Math Novice
0 XP0/59 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

Movement in a Coordinate Space

In AI, direction is not limited to north or east. It describes how a point moves when several coordinates change together. In parameter space it is a combination of changes to many weights; in embedding space it is an axis along which representations vary.

  • Loss landscape: the gradient points in the direction of steepest local increase. The steepest local decrease is its negative, .
  • Embedding space: a difference vector can describe movement from one represented state to another. Famous word-arithmetic examples illustrate relations that appear in some embeddings, not universal exact laws.
  • Attention: query-key dot products produce relevance scores, but a single “direction” is not itself the token being attended to. Scores, softmax, and a weighted combination of values together produce the output.

A Value and a Change Instruction Are Different Information

A scalar loss says how poor the current result is. A gradient vector says how sensitively the loss changes when each parameter moves a little. The update therefore combines the current position, a direction, and a step size .

A gradient does not guarantee a direct path to the global minimum. Learning rate, curvature, noise, and saddle points all affect the trajectory. It is still a far more useful local compass than random search.

The gradient points uphill; the negative gradient points downhill. Dropping the minus sign turns gradient descent into gradient ascent.

Code

Direction = the gradient, negated·python
import numpy as np

# A toy 'loss landscape' — distance from origin squared
def loss(w):
    return np.sum(w ** 2)

# The gradient is the direction of steepest *ascent*
# We negate it to descend
def grad(w):
    return 2 * w

w = np.array([3.0, 4.0])         # start somewhere bad — loss = 25
for step in range(5):
    direction = -grad(w)         # which way to move
    w = w + 0.1 * direction      # take a small step
    print(f"step {step}: w = {w}, loss = {loss(w):.3f}")

External links

Exercise

Run the gradient-descent snippet above with different starting points and learning rates. At what learning rate does it diverge, oscillate, or crawl? The gradient points uphill; the update uses its negative.
Hint
Try learning rate 1.0 (oscillates) and 0.001 (crawls forever). The sweet spot for this loss is around 0.1-0.3.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 6

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.
  1. Elechemist
    Elechemist

    -작은 수일 때는 학습률이 너무 작아 기어감 (0.001 같이) -1일 때는 부호가 바뀌면서 값은 같으니 진동 -1이상일 떄는 발산시작 -0.1은 sweet spot이라고 할만함

    💛 by Pippa💛 by Ttoriwarm
    1. Pippa
      Pippa· warmElechemistElechemist

      학습률 sweet spot 정확히 짚으셨어요. 너무 작아서 기어가는 것발산이 같은 dial의 양 끝 — 두 실패가 같은 자리에서 나옵니다.

      -1에서 진동하는 자리가 특히 깊어요. 함수 모양을 안다고 가정하면 exact step이 가능한 자린데, 모르는 함수에선 부호만 뒤집히면서 왕복합니다. 0.1모른다는 사실에 정직한 자리예요.

      💛 by Ttoriwarm
  2. Happycurio3
    Happycurio3

    Loss landscape 가야 할 길, Embedding 정보의 위치, Attention 정보를 연결하는 끈 direction = -grad(w) # 어느 쪽으로 움직일지 (나침반) w = w + 0.1 * direction # 작은 발걸음 (0.1이 보폭!) 숫자 1.0 캥거루 점프, 튕겨 나갈 리스크 숫자 0.001 거북이 걸음, 기어감 숫자 0.1-0.3 황금보폭 Sweet spot 은 0.1

    💛 by Pippawarm💛 by Ttoriwarm
    1. Pippa
      Pippa· warmHappycurio3Happycurio3

      동물 보폭으로 외우면 다음 lesson 가셔도 한 번 더 보일 거예요 — 캥거루/거북이/황금보폭, 정리 잘 짚으셨어요.

      그리고 Loss landscape · Embedding · Attention 세 자리에서 direction이 다 등장한다는 거 짚으신 게 진짜 핵심이에요. 어느 쪽인가 라는 같은 질문이 모양만 바꿔서 quest 전체를 관통하거든요.

      💛 by Ttoriwarm
  3. payitforwardforever
    payitforwardforever

    신기하네요 Mean Squared Error (MSE) 를 쓰는 이유도 이 챕터 덕분에 배울수 있었습니다- to heavily punishes big mistakes, stops error from canceling out, for calculus reason.

    💛 by Ttoriwarm
    1. Pippa
      Pippa· warmpayitforwardforeverpayitforwardforever

      왜 제곱인가 까지 끌고 가셨네요. 이 lesson 토이 코드의 w ** 2 도 같은 정신이에요 — 큰 실수에 더 무거운 책임, 부호 상쇄 차단, 미분이 깔끔. 그래서 다음 chapter 의 loss 들도 거의 다 제곱 베이스로 오실 거예요.

      💛 by Ttoriwarm