tf.random.categorical( logits, num_samples, dtype=None, seed=None, name=None )
순환신경망에서 다음 예측값에 어느정도 확률을 기반으로한 랜덤성을 부여할 때 사용할 수 있다.
Params :
logits : 2D Tensor [ batch_size, num_classes ], [ i , : ] slice represents unnormalized log-probailities of all classes
num_samples : 0-D Number of independent samples of draw for each row slice
dtype : Integer type of output, default int64
seed : Integer, random seed distribution
name : name
Returns :
Tensor, the drawn samples of shape [ batch_size, num_samples ]
설명 :
샘플당 각 클레스의 로그 확률과 batch_size 개의 샘플을 지닌 2D 텐서를 인자로 전달하면, 전달된 확률을 기반으로 랜덤하게 클래스 하나를 반환한다. 예를들어 하나의 샘플을 예측해 클래스 별 확률지닌 [ 1 , 100 ] 의 텐서를 전달하면, 확률들을 기반으로 num_samples 만큼 클래스를 무작위로 선택한다.
probabilities = [[np.log(0.5), np.log(0.4), np.log(0.1)]] # [ 1, 3 ]
tf.random.categorical(probabilities, num_samples=10)
#<tf.Tensor: shape=(1, 10), dtype=int64, numpy=array([[1, 0, 2, 0, 0, 0, 0, 0, 0, 1]])>
'오늘 > 오늘의 함수' 카테고리의 다른 글
[Tensorflow] tf.math.equal, tf.math.not_equal, tf.reduce_all, tf.cond (0) | 2021.12.31 |
---|---|
[tensorflow] tf.math.add_n, tf.math.reduce_mean, tf.cinsum (0) | 2021.12.09 |
[numpy] np.ufunc.accumulate (0) | 2021.12.08 |
[numpy] np.flip (0) | 2021.12.08 |
[Python] functools.partial (0) | 2021.12.04 |