Keras로 배우는 언어 모델링을 위한 순환 신경망(RNN)
David Cecchini
Data Scientist
텍스트 분류의 활용:
이진에서 다중 클래스로 바뀌는 점:
y의 형태출력 변수 y의 형태:
# Example: num_classes = 3
y[0] = [0, 1, 0]
y.shape = (N, num_classes)
출력층 유닛 수:
# Output layer
model.add(Dense(num_classes))

출력층의 활성화 함수:
softmax는 각 클래스의 확률을 반환합니다# Output layer
model.add(Dense(num_classes, activation="softmax"))
손실 함수:
# Compile the model
model.compile(loss='categorical_crossentropy')
y = ["sports", "economy", "data_science", "sports", "finance"] # Transform to pandas series object y_series = pd.Series(y, dtype="category")# Print the category codes print(y_series.cat.codes)
0 3
1 1
2 0
3 3
4 2
from tensorflow.keras.utils import to_categoricaly = np.array([0, 1, 2]) # Change to categorical y_prep = to_categorical(y) print(y_prep)
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
Keras로 배우는 언어 모델링을 위한 순환 신경망(RNN)