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

Beyond North and South

"Direction" outside of geometry is slippery. In AI, direction stops being about points on a compass and starts being about which way to move in some space to make a thing better or worse. That space might be:

  • Loss landscape — direction = which combination of weight changes makes the error drop fastest. The gradient is the steepest-descent direction.
  • Embedding space — direction = the conceptual axis along which meaning varies. king - man + woman ≈ queen uses the gender axis as a direction.
  • Attention space — direction = which previous token a new token is "looking at" most strongly.

None of these are physical. All of them obey the same vector rules. That's the bargain: once you can think in vectors, the bargain pays off in every weird AI space you ever meet.

Why Magnitude Alone Loses

If a model only knew "the loss is high," it could only say "things are bad." What it actually knows — via gradients — is "things are bad, AND if you wiggle w_42 a tiny bit upward and w_8 downward, things get less bad fastest." That's a direction. Without it, training would be random search. With it, training is steepest descent.

Direction is the compass that turns "we're lost" into "let's go this way." Every learning algorithm in AI exists to give you that compass.

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. Try different starting points and learning rates (the 0.1). At what learning rate does it diverge? At what learning rate does it crawl? The direction stays the gradient — only the *step size* changes.
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