SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2105.14556 · ACL · 2021

Diversifying Dialog Generation via Adaptive Label Smoothing

Minlie Huang, Yong Jiang, Yida Wang, Yinhe Zheng

arXiv · PDF · Open in the Atlas

Code that ran

4 of 5 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 2 failures of our instrument; 1 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2105.14556.json · badge: /api/ran/2105.14556.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
lemon234071/AdaLabel marked official in Papers with Code
Papers with Code archive
4 ran · 1 no recorded run
FunctionStatusWhere it lives
AdaLabLoss Ran
ran on a synthesized input · constructed an object; no result was computed
lemon234071/AdaLabel/onmt/utils/loss.py
code served (permissive licence) · get_code("3389446ed90d80b6")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, AdaLabLoss: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Define the AdaLabLoss class
class AdaLabLoss(nn.Module):
    """
    With adaptive label smoothing,
    KL-divergence between q_{smoothed ground truth prob.}(w)
    and p_{prob. computed by model}(w) is minimized.
    """

    def __init__(self, tgt_vocab_size, batch_size, ignore_index=-100, device='cpu', reduction='sum', temperature=1, eos_index=3):
        self.ignore_index = ignore_index
        self.eos_index = eos_index
        self.tgt_vocab_size = tgt_vocab_size
        super(AdaLabLoss, self).__init__()
        self.device = device
        self.batch_size = batch_size
        self.reduction = reduction
        self.step = 0
        self.temperature = temperature
        self.top_head = 2
        self.top_tail = 500
        self.margin = 0.2
        self.alpha_param = 2
        self.topk = 5

    def forward(self, output, target, tgt_batch=None, label_scores=None):
        """
        output (FloatTensor): batch_size x n_classes
        target (LongTensor): batch_size
        """
        v = self._get_v(label_scores, target)
        epsilon = self._get_epsilon(output, target, v)
        confidence = 1 - epsilon
        smoothing_penalty = epsilon.unsqueeze(-1) * v
        model_prob = torch.zeros_like(output, device=output.device, dtype=torch.float)
        model_prob.scatter_(1, target.unsqueeze(1), confidence.unsqueeze(1))
        model_prob = model_prob + smoothing_penalty
        model_prob.masked_fill_((target == self.ignore_index).unsqueeze(1), 0)
        return torch.nn.functional.kl_div(output, model_prob, reduction=self.reduction)

    def _bottle(self, _v):
        return _v.view(-1, _v.size(2))

    def _unbottle(self, _v, batch_size):
        return _v.view(-1, batch_size, _v.size(1))

    def _get_epsilon(self, output, target, v):
        probs = output.detach().clone().exp()
        prob_max = probs.max(dim=1)[0]
        prob_gtruth = probs.gather(dim=1, index=target.unsqueeze(1)).squeeze()
        epsilon = 1 - prob_max
        maxv = v.max(dim=-1)[0]
        up_bond = 1 / (1 + maxv) - self.margin
        mask = epsilon.gt(up_bond)
        epsilon[mask] = up_bond[mask]
        alpha = (prob_gtruth / prob_max).pow(self.alpha_param)
        epsilon = alpha * epsilon
        return epsilon

    def _get_v(self, label_scores, target):
        v = label_scores.detach().clone()
        v = v / self.temperature
        v.scatter_(1, target.unsqueeze(1), -float('inf'))
        v[:, self.ignore_index] = -float('inf')
        upper_values, upper_indices = torch.topk(v, self.top_tail, dim=1)
        kth_upper = upper_values[:, -1].view([-1, 1])
        kth_upper = kth_upper.repeat([1, v.shape[1]]).float()
        upper_ignore = torch.lt(v, kth_upper)
        v = v.masked_fill(upper_ignore, -10000)
        lower_values, lower_indices = torch.topk(v, self.top_head, dim=1)
        kth_lower = lower_values[:, -1].view([-1, 1])
        kth_lower = kth_lower.repeat([1, v.shape[1]]).float()
        lower_ignore = torch.gt(v, kth_lower)
        v = v.masked_fill(lower_ignore, -10000)
        v = v.softmax(dim=-1)
        return v

    def _compute_entropy(self, output):
        entropy = -torch.sum(output.exp() * output, -1)
        return entropy


# Create small tensors for testing
batch_size = 2
tgt_vocab_size = 1024
n_classes = 1024

# output: log probabilities from model, shape (batch_size, n_classes)
output = torch.randn(batch_size, n_classes, requires_grad=True)

# target: ground truth class indices, shape (batch_size,)
target = torch.randint(0, tgt_vocab_size, (batch_size,))

# label_scores: scores for all vocabulary items, shape (batch_size, n_classes)
label_scores = torch.randn(batch_size, n_classes)

# tgt_batch: optional batch information
tgt_batch = None

ARGS = {
    'tgt_vocab_size': tgt_vocab_size,
    'batch_size': batch_size,
    'ignore_index': -100,
    'device': 'cpu',
    'reduction': 'sum',
    'temperature': 1.0,
    'eos_index': 3,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type AdaLabLoss — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a AdaLabLoss output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
LossComputeBase Ran
ran on a synthesized input · constructed an object; no result was computed
lemon234071/AdaLabel/onmt/utils/loss.py
code served (permissive licence) · get_code("c4741c2232030fcb")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, LossComputeBase: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create a simple generator module that maps hidden states to vocabulary logits
class SimpleGenerator(nn.Module):
    def __init__(self, hidden_dim, vocab_size):
        super(SimpleGenerator, self).__init__()
        self.linear = nn.Linear(hidden_dim, vocab_size)
    
    def forward(self, x):
        return self.linear(x)

# Create a simple criterion (loss function)
criterion = nn.NLLLoss(ignore_index=0)

# Create a generator
generator = SimpleGenerator(hidden_dim=4, vocab_size=5)

# Create batch object with minimal required attributes
class SimpleBatch:
    def __init__(self):
        self.batch_size = 2
        self.src = torch.randint(1, 5, (3, 2))  # [src_len x batch]
        self.tgt = torch.randint(1, 5, (2, 2))  # [tgt_len x batch]

batch = SimpleBatch()

# Create output tensor [tgt_len x batch x hidden_dim]
output = torch.randn(2, 2, 4, requires_grad=True)

# Create attns dictionary
attns = {
    'std': torch.randn(2, 2, 3)  # [tgt_len x batch x src_len]
}

ARGS = {
    'criterion': criterion,
    'generator': generator
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type LossComputeBase — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a LossComputeBase output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
filter_shard_state Ran
ran; our contract draft was wrong, not the code
lemon234071/AdaLabel/onmt/utils/loss.py
code served (permissive licence) · get_code("e6f9b7a73fec596e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned generator. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create a sample state dict with various types of values
state = {
    "tensor_param": torch.randn(8, 4, requires_grad=True),
    "scalar_param": 0.001,
    "none_param": None,
    "list_param": [1, 2, 3],
}

# shard_size parameter
shard_size = 3

ARGS = {
    "state": state,
    "shard_size": shard_size,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type generator — a generator output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a generator output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
shards Ran
ran; our contract draft was wrong, not the code
lemon234071/AdaLabel/onmt/utils/loss.py
code served (permissive licence) · get_code("38cecda28cf3e292")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned generator. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create a sample state dictionary with tensors
# The state dict maps keys to Tensor-like objects or None
state = {
    'loss': torch.tensor([1.5, 2.0], requires_grad=True),
    'hidden': torch.randn(4, 3, requires_grad=True),
    'optional_field': None,
    'weights': torch.randn(2, 4, requires_grad=True),
}

shard_size = 2
eval_only = False

ARGS = {
    'state': state,
    'shard_size': shard_size,
    'eval_only': eval_only,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type generator — a generator output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a generator output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
AdaLabLossCompute Not yet run
unverified (harvested, no recorded run)
lemon234071/AdaLabel/onmt/utils/loss.py
code served (permissive licence) · get_code("0c1ba651d677a958")
How it ran

no invocation recorded.

Also present in other papers' code

Of 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 5 distinct functions with an identity, 2 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 0 the same month, 0 later) and 3 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
filter_shard_state
brick of this paper's assembly: helper
1 other paper
1 dated earlier · 1 only as an assembly brick
2010.03034 (2020-10)
Why Skip If You Can Combine: A Simple Knowledge Distillation Technique for Intermediate Layers
shards
brick of this paper's assembly: helper
1 other paper
1 dated earlier · 1 only as an assembly brick
2010.03034 (2020-10)
Why Skip If You Can Combine: A Simple Knowledge Distillation Technique for Intermediate Layers

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Neural dialogue generation models trained with the one-hot target distribution suffer from the over-confidence issue, which leads to poor generation diversity as widely reported in the literature. Although existing approaches such as label smoothing can alleviate this issue, they fail to adapt to diverse dialog contexts. In this paper, we propose an Adaptive Label Smoothing (AdaLabel) approach that can adaptively estimate a target label distribution at each time step for different contexts. The maximum probability in the predicted distribution is used to modify the soft target distribution produced by a novel light-weight bi-directional decoder module. The resulting target distribution is aware of both previous and future contexts and is adjusted to avoid over-training the dialogue model. Our model can be trained in an endto-end manner. Extensive experiments on two benchmark datasets show that our approach outperforms various competitive baselines in producing diverse responses.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2105.14556")
get_code_for_paper("2105.14556")
have("2105.14556")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2105.14556.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2105.14556.svg)](https://syntology.ai/paper/2105.14556)

Connect an agent — have() is free.