분류 손실함수 중 하나로 이진 분류 모델에 사용
tf.keras.losses.BinaryCrossentropy(
from_logits=False,
label_smoothing=0.0,
axis=-1,
reduction=losses_utils.ReductionV2.AUTO,
name='binary_crossentropy'
)
from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers import Dense, Embedding, LSTM, Bidirectional
# this function builds, trains and evaluates a keras LSTM model
def build_and_evaluate_model(x_train, y_train, x_develop, y_develop):
x_train = sequence.pad_sequences(x_train, maxlen = 100)
x_dev = sequence.pad_sequences(x_develop, maxlen = 100)
model = Sequential()
model.add(Embedding(input_dim = 10000, output_dim = 50)) #input_dim or the size of the data set, e.g vocabulary
model.add(Bidirectional(LSTM(units = 25)))
model.add(Dense(1,activation='sigmoid'))
model.predict(x_develop)
model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics=['accuracy'])
model.fit(x = x_train, y = y_train, batch_size = 32, epochs = 10, validation_data = (x_develop, y_develop))
score, acc = model.evaluate(x_develop, y_develop)
return score, acc, model
https://www.tensorflow.org/api_docs/python/tf/keras/losses/BinaryCrossentropy
https://bskyvision.com/822
https://gooopy.tistory.com/52
https://kh-kim.gitbook.io/natural-language-processing-with-pytorch/00-cover-7/06-multi_classification
https://towardsdatascience.com/understanding-pytorch-loss-functions-the-maths-and-algorithms-part-1-6e439b27117e
https://siegel.work/blog/LossFunctions/