評價此頁

torch.nn.functional.log_softmax#

torch.nn.functional.log_softmax(input, dim=None, _stacklevel=3, dtype=None)[source]#

應用 softmax 然後取對數。

雖然在數學上等同於 log(softmax(x)),但分別執行這兩個操作速度較慢且數值不穩定。此函式使用一種替代的公式來正確計算輸出和梯度。

有關更多詳細資訊,請參閱 LogSoftmax

引數
  • input (張量) – 輸入

  • dim (int) – 計算 log_softmax 的維度。

  • dtype (torch.dtype, optional) – 返回張量的目標資料型別。如果指定,將在執行操作之前將輸入張量轉換為 dtype。這對於防止資料型別溢位很有用。預設為 None。

返回型別

張量