매일 쓸 factory 함수들
TF의 생성자 세트는 작지만 완전해. 어떤 걸 언제 꺼낼지 알면 코드도 줄고 버그도 줄어.
tf.constant는 Python 값/list/NumPy array에서 immutable tensor 만들어. tf.zeros, tf.ones, tf.fill은 초기화용 고정값 tensor. tf.eye는 단위행렬, tf.range는 Python range처럼 시퀀스. *_like 변형들 — tf.zeros_like, tf.ones_like — 은 다른 tensor의 shape/dtype을 따라가서 한 카테고리의 버그를 통째로 막아줘.
weight 초기화엔 거의 항상 tf.random.normal보다 tf.random.truncated_normal이 답이야. truncated 버전은 평균에서 2σ 넘어가는 outlier를 잘라내서 초반 gradient 불안정을 막으면서 평균은 안 흔들어.
재현성: 결정론적이어야 하는 스크립트는 맨 위에
tf.random.set_seed(42). graph mode (@tf.function)에서 재현성 필요하면 tf.random.stateless_normal에 명시적 seed=[a, b] — 글로벌 state는 컴파일된 graph 안에선 불안정해.