概述
個別損失值通常會合併成一個標量以供最佳化,且所選的目標是一個代理,可能與應用的評估指標不同。
深入探討
A prediction loss compares outputs with training targets according to a specified rule. Those targets can be labels or values constructed for the learning task; they should not automatically be called unquestionable truth. Implementations may produce per-example losses and then sum or average them for an optimization step. Choosing the rule matters. Mean squared error averages squared residuals, giving large residuals more influence than mean absolute error, which averages their absolute values. For residuals one and three, mean squared error is five, while mean absolute error is two. These are illustrative calculations rather than performance results from a dataset. Classification commonly uses cross-entropy. With a one-hot target and a predicted probability p for its class, the loss is minus log p. A lower probability for the target class gives a larger loss, so confident wrong predictions can incur high loss. The logarithm base determines the units: base-two loss is in bits, while a natural logarithm gives nats. For a target probability of one-quarter, minus log-base-two p is two bits. Gradient-based optimization needs usable derivative information, but differentiability requirements should not be generalized to every learning algorithm. Some losses have nondifferentiable points handled by an appropriate subgradient or surrogate. Accuracy is a discrete evaluation metric and is generally not directly useful as a gradient-training objective. A suitable training loss supplies an optimization signal; final task quality needs evaluation using the relevant metrics.
現實世界的實施
使用交叉熵損失來訓練電子郵件垃圾郵件分類器,以懲罰有信心的錯誤分類
選擇房價預測的平均絕對誤差,這樣一些極端的豪宅就不會主導訓練
應用對比損失,以便臉部辨識模型將同一個人的影像組合在一起
設計獎勵模型損失以引導聊天機器人做出更有幫助和誠實的回應
損失函數的未來
目標設計可結合預測項、正則化及其他任務需求。比較時應說明目標定義、公式、減少量、單位與評估指標。目標值可能下降,而應用指標保持不變或惡化,因此應以改進為衡量標準,而非僅從訓練損失推斷。自訂損失需檢視其鼓勵的行為以及數值與優化特性。
付諸實踐
為什麼這很重要
- 更明確的決策. 它可以幫助您將清晰的技術聲明與行銷語言分開。
- 成本與預算. 在花費金錢或時間之前,您可以提出更好的實施問題。
- 團隊與工作流程. 具有共同理解的團隊可以做出更好的產品、政策和學習決策。
留意
- 不同的團隊可能會以不同的方式使用相同術語,因此請儘早定義範圍。
- 基準測試可能看起來很強大,但實際效能卻參差不齊。
- 忽視數據品質和評估計劃通常會產生脆弱的結果。
後續步驟
- 從您需要的結果的簡單語言定義開始。
- 在測試之前選擇一種成功指標和一種失敗條件。
- 使用代表性資料運行小型試點,而不是完善的演示集。
- 記錄損失函數在哪些方面有幫助以及在哪些方面更簡單的方法更好。
不斷探索
常見問題
什麼是損失函數?
損失定義了用於評估預測或其他訓練目標的目標。個別的損失值通常會被合併為一個標量以進行最佳化,且所選的目標是一個代理,可能與應用程式的評估指標不同。
對於預測任務,其選擇的損失是用來量化什麼相對於訓練目標的?
損失定義了訓練目標;它不會自動衡量應用品質的每一個面向。
哪種損失函數最常用於分類任務?
交叉熵將預測機率分佈與真實標籤進行比較,是分類的標準選擇。
與均方誤差相比,為什麼您會選擇平均絕對誤差?
平均絕對誤差按比例處理所有誤差,而不是對它們進行平方,因此一些極端異常值的影響較小。
為什麼基於梯度的訓練需要可使用的損失導數或合適的替代品?
這涉及基於梯度的訓練,而非聲稱每一種可能的學習演算法都需要可微分的損失。
當指派給目標類別的機率變得非常小時,單熱類別交叉熵會如何變化?
當目標類別的機率縮小時,負對數 p 的項會增大。這並不保證每個模型權重都有特定的梯度大小。