cuốn sách gpt4 ai đã làm

python - Tensorflow softmax_cross_entropy_with_logits 与 tf.reduce_mean(-tf.reduce_sum(y*tf.log(yhat), reduction_indices = 1))

In lại Tác giả: Vũ trụ không gian Thời gian cập nhật: 2023-11-04 02:54:42 28 4
mua khóa gpt4 Nike

Tôi đang làm theo ví dụ về perceptron đa lớp ở đây:https://github.com/aymericdamien/TensorFlow-ExamplesTôi quan tâm đến chức năng tf.nn.softmax_cross_entropy_with_logits và mối quan hệ của nó với tf.nn.relugiảm_tổng mối quan hệ đang bối rối. Giả sử tôi khai báo một mạng:

x = tf.placeholder('float',[None,24**2])
y = tf.placeholder('float',[None,10])
w1 = tf.Variable(random_normal([24**2,12])
w2 = tf.Variable(random_normal([12,10])
h = tf.nn.relu(tf.matmul(x,w1))
yhat= tf.matmul(h, w2)

'''
hàm chi phí
'''
chi phí = tf.reduce_mean(tf.nn.softmax_corss_entropy_with_logits(logits=yhat, labels=y))

Không phải những điều trên đều giống nhau sao:

x = tf.placeholder('float',[None,24**2])
y = tf.placeholder('float',[None,10])
w1 = tf.Variable(random_normal([24**2,12])
w2 = tf.Variable(random_normal([12,10])
h = tf.nn.relu(tf.matmul(x,w1))
yhat= tf.nn.softmax(tf.matmul(h, w2))

'''
hàm chi phí
'''
cost = tf.reduce_mean(-tf.reduce_sum(y*tf.log(_hat),reduction_indices=1))

Nhưng khi tôi luyện tập bằng cấu trúc đầu tiên, độ chính xác của tôi là xấp xỉ. 95%, phương pháp thứ hai tạo ra 1% độ chính xác, vậy rõ ràng đó không chỉ là "sự mất ổn định về số" phải không?

有关完整示例,请参阅:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/multilayer_perceptron.py

câu trả lời hay nhất

Đã thực hiện một số nghiên cứu nhanh chóng. tôi ở đây multilayer_peceptron.py Đã thêm dòng 62 ở trên của tệp và in nó ở dòng 87

cost_v2 = tf.reduce_mean(-tf.reduce_sum(y*tf.log(tf.nn.softmax(pred)),1))

Trong đợt đầu tiên, nó bắt đầu bằng nan xuất hiện vì trước Trên thực tế chứa khá nhiều số 0 sau softmax. Tôi đoán entropy chéo bỏ qua các số 0 và chỉ tính tổng dựa trên điều này:https://datascience.stackexchange.com/questions/9302/the-cross-entropy-error-function-in-neural-networks

Về python - Tensorflow softmax_cross_entropy_with_logits so với tf.reduce_mean(-tf.reduce_sum(y*tf.log(yhat),Giảm_indices = 1)), chúng tôi đã tìm thấy một câu hỏi tương tự trên Stack Overflow: https://stackoverflow.com/questions/42799818/

28 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress