# label_smooth¶

paddle.fluid.layers.nn. label_smooth ( label, prior_dist=None, epsilon=0.1, dtype='float32', name=None ) [source]
Alias_main

Label smoothing is a mechanism to regularize the classifier layer and is called label-smoothing regularization (LSR).

Label smoothing is proposed to encourage the model to be less confident, since optimizing the log-likelihood of the correct label directly may cause overfitting and reduce the ability of the model to adapt. Label smoothing replaces the ground-truth label $$y$$ with the weighted sum of itself and some fixed distribution $$\mu$$. For class $$k$$, i.e.

$\begin{split}\\tilde{y_k} = (1 - \epsilon) * y_k + \epsilon * \mu_k,\end{split}$

where $$1 - \epsilon$$ and $$\epsilon$$ are the weights respectively, and $$\\tilde{y}_k$$ is the smoothed label. Usually uniform distribution is used for $$\mu$$.

See more details about label smoothing in https://arxiv.org/abs/1512.00567.

Parameters
• label (Variable) – The input variable containing the label data. The label data should use one-hot representation. It’s a multidimensional tensor with a shape of $$[N_1, ..., Depth]$$, where Depth is class number. The dtype can be “float32” and “float64”.

• prior_dist (Variable, optional) – The prior distribution to be used to smooth labels. If not provided, an uniform distribution is used. It’s a multidimensional tensor with a shape of $$[1, class\_num]$$ . The default value is None.

• epsilon (float, optional) – The weight used to mix up the original ground-truth distribution and the fixed distribution. The default value is 0.1.

• dtype (np.dtype|core.VarDesc.VarType|str, optional) – The data type can be set as ‘float32’, ‘float64’. The default value is ‘float32’.

• name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

The tensor variable containing the smoothed labels.

Return type

Variable

Examples

import paddle.fluid as fluid
{"ft_lang_label":"__label__en","ft_lang_prob":0.70071864,"math_prob":0.98385894,"size":2401,"snap":"2021-43-2021-49","text_gpt3_token_len":587,"char_repetition_ratio":0.13308302,"word_repetition_ratio":0.03164557,"special_character_ratio":0.26114118,"punctuation_ratio":0.196868,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9940876,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-20T01:21:23Z\",\"WARC-Record-ID\":\"<urn:uuid:b69960df-5bb0-4f41-88c5-af62c7bf0025>\",\"Content-Length\":\"217684\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:c3332b55-ca4f-4b5f-b717-48f2e95a1d44>\",\"WARC-Concurrent-To\":\"<urn:uuid:309fb365-e403-45e2-b64b-5d44373de090>\",\"WARC-IP-Address\":\"106.12.155.111\",\"WARC-Target-URI\":\"https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/fluid/layers/nn/label_smooth_en.html\",\"WARC-Payload-Digest\":\"sha1:Z6PCPAP3EDK6VXUSHVFWBLKGLRP6UJES\",\"WARC-Block-Digest\":\"sha1:XIGYNDBKIIV3UABTK72JBVQUC2G6UGUE\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585290.83_warc_CC-MAIN-20211019233130-20211020023130-00291.warc.gz\"}"}