SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · aaai_6453 · AAAI · 2020

Improving Knowledge-Aware Dialogue Generation via Knowledge Base Question Answering

Jian Wang, Xiaojiang Liu, Wei Bi, Min Yang, Ruifeng Xu, Junhao Liu, Kejing He

Open in the Atlas

Code that ran

5 of 9 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 1 failure of our instrument; 4 no recorded run), measured 2026-11-22; 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/aaai_6453.json · badge: /api/ran/aaai_6453.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
siat-nlp/TransDG canonical (classifier label)
classifier basis: census
5 ran · 4 no recorded run
FunctionStatusWhere it lives
compute_bleu Ran
ran; our contract draft was wrong, not the code
siat-nlp/TransDG/src/utils/bleu.py
code served (permissive licence) · get_code("c2167c0487876139")
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 tuple. 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 collections
import math

def _get_ngrams(segment, max_order):
    """Extracts all n-grams upto a given maximum order from an input segment.
      Args:
        segment: text segment from which n-grams will be extracted.
        max_order: maximum length in tokens of the n-grams returned by this
            methods.
      Returns:
        The Counter containing all n-grams upto max_order in segment
        with a count of how many times each n-gram occurred.
      """
    ngram_counts = collections.Counter()
    for order in range(1, max_order + 1):
        for i in range(0, len(segment) - order + 1):
            ngram = tuple(segment[i:i + order])
            ngram_counts[ngram] += 1
    return ngram_counts

def compute_bleu(reference_corpus, translation_corpus, max_order=4, smooth=False):
    """Computes BLEU score of translated segments against one or more references.
      Args:
        reference_corpus: list of lists of references for each translation. Each
            reference should be tokenized into a list of tokens.
        translation_corpus: list of translations to score. Each translation
            should be tokenized into a list of tokens.
        max_order: Maximum n-gram order to use when computing BLEU score.
        smooth: Whether or not to apply Lin et al. 2004 smoothing.
      Returns:
        3-Tuple with the BLEU score, n-gram precisions, geometric mean of n-gram
        precisions and brevity penalty.
      """
    matches_by_order = [0] * max_order
    possible_matches_by_order = [0] * max_order
    reference_length = 0
    translation_length = 0
    for references, translation in zip(reference_corpus, translation_corpus):
        reference_length += min((len(r) for r in references))
        translation_length += len(translation)
        merged_ref_ngram_counts = collections.Counter()
        for reference in references:
            merged_ref_ngram_counts |= _get_ngrams(reference, max_order)
        translation_ngram_counts = _get_ngrams(translation, max_order)
        overlap = translation_ngram_counts & merged_ref_ngram_counts
        for ngram in overlap:
            matches_by_order[len(ngram) - 1] += overlap[ngram]
        for order in range(1, max_order + 1):
            possible_matches = len(translation) - order + 1
            if possible_matches > 0:
                possible_matches_by_order[order - 1] += possible_matches
    precisions = [0] * max_order
    for i in range(0, max_order):
        if smooth:
            precisions[i] = (matches_by_order[i] + 1.0) / (possible_matches_by_order[i] + 1.0)
        elif possible_matches_by_order[i] > 0:
            precisions[i] = float(matches_by_order[i]) / possible_matches_by_order[i]
        else:
            precisions[i] = 0.0
    if min(precisions) > 0:
        p_log_sum = sum((1.0 / max_order * math.log(p) for p in precisions))
        geo_mean = math.exp(p_log_sum)
    else:
        geo_mean = 0
    ratio = float(translation_length) / reference_length
    if ratio > 1.0:
        bp = 1.0
    else:
        bp = math.exp(1 - 1.0 / ratio)
    bleu = geo_mean * bp
    return (bleu, precisions, bp, ratio, translation_length, reference_length)


# Create reference corpus: list of lists of references
# Each reference is a tokenized list
reference_corpus = [
    [["the", "cat", "sat", "on", "the", "mat"], ["a", "cat", "is", "sitting", "on", "the", "mat"]],
    [["hello", "world"], ["hi", "world"]]
]

# Create translation corpus: list of translations
# Each translation is a tokenized list
translation_corpus = [
    ["the", "cat", "sat", "on", "the", "mat"],
    ["hello", "world"]
]

ARGS = {
    "reference_corpus": reference_corpus,
    "translation_corpus": translation_corpus,
    "max_order": 4,
    "smooth": False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
load_data Ran
ran on a synthesized input
siat-nlp/TransDG/src/utils/data_loader.py
code served (permissive licence) · get_code("d8bc198319587bd0")
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 tuple, ndim 2, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 tempfile
import json
import os

# Create a temporary directory with the required data files
temp_dir = tempfile.mkdtemp()

# Create train.txt with some sample JSON lines
train_data = [
    {"text": "sample train 1", "label": 0},
    {"text": "sample train 2", "label": 1},
]
with open(os.path.join(temp_dir, 'train.txt'), 'w') as f:
    for item in train_data:
        f.write(json.dumps(item) + '\n')

# Create valid.txt with some sample JSON lines
valid_data = [
    {"text": "sample valid 1", "label": 0},
    {"text": "sample valid 2", "label": 1},
]
with open(os.path.join(temp_dir, 'valid.txt'), 'w') as f:
    for item in valid_data:
        f.write(json.dumps(item) + '\n')

# Create test.txt with some sample JSON lines
test_data = [
    {"text": "sample test 1", "label": 0},
    {"text": "sample test 2", "label": 1},
]
with open(os.path.join(temp_dir, 'test.txt'), 'w') as f:
    for item in test_data:
        f.write(json.dumps(item) + '\n')

ARGS = {
    'data_dir': temp_dir,
    'is_train': True,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 2, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
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
load_trans_data Ran
ran on a synthesized input
siat-nlp/TransDG/src/utils/data_loader.py
code served (permissive licence) · get_code("fdc308e688aedfaf")
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 dict. 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 os
import tempfile
import pickle
import numpy as np

# Create a temporary directory for test data
temp_dir = tempfile.mkdtemp()

# Create mock pickle files for training data
for idx in range(34):
    sent_repr = np.random.randn(5, 8).astype(np.float32)  # 5 samples, 8-dim representations
    rm_final_feats = np.random.randn(5, 12).astype(np.float32)  # 5 samples, 12-dim features
    
    trans_bucket = {
        'sent_repr': sent_repr,
        'rm_final_feats': rm_final_feats
    }
    
    filepath = os.path.join(temp_dir, f'data_trans_train_{idx}.picke')
    with open(filepath, 'wb') as fw:
        pickle.dump(trans_bucket, fw)

# Create mock pickle file for validation data
data_trans_valid = {
    'sent_repr': np.random.randn(3, 8).astype(np.float32),
    'rm_final_feats': np.random.randn(3, 12).astype(np.float32)
}
valid_filepath = os.path.join(temp_dir, 'data_trans_valid.picke')
with open(valid_filepath, 'wb') as fw:
    pickle.dump(data_trans_valid, fw)

# Create mock pickle file for test data
data_trans_test = {
    'sent_repr': np.random.randn(2, 8).astype(np.float32),
    'rm_final_feats': np.random.randn(2, 12).astype(np.float32)
}
test_filepath = os.path.join(temp_dir, 'data_trans_test.picke')
with open(test_filepath, 'wb') as fw:
    pickle.dump(data_trans_test, fw)

ARGS = {
    'dir': temp_dir,
    'is_train': False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
load_vocab Ran
ran on a synthesized input
siat-nlp/TransDG/src/utils/data_loader.py
code served (permissive licence) · get_code("b2a79364e5c3e474")
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 tuple. 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 numpy as np
import json
import tempfile
import os

# Create a temporary directory with the required files
tmpdir = tempfile.mkdtemp()

# Create vocab file
vocab_data = {
    "hello": 100,
    "world": 95,
    "test": 80,
    "data": 75,
    "python": 70
}
with open(os.path.join(tmpdir, 'vocab'), 'w') as f:
    json.dump(vocab_data, f)

# Create csk_entity.txt file
with open(os.path.join(tmpdir, 'csk_entity.txt'), 'w') as f:
    f.write("entity1\n")
    f.write("entity2\n")
    f.write("entity3\n")

# Create glove.840B.300d.txt file with word vectors
with open(os.path.join(tmpdir, 'glove.840B.300d.txt'), 'w') as f:
    # Add some sample word vectors (300 dimensions as per filename)
    f.write("hello " + " ".join([str(0.1 * i) for i in range(300)]) + "\n")
    f.write("world " + " ".join([str(0.2 * i) for i in range(300)]) + "\n")
    f.write("test " + " ".join([str(0.3 * i) for i in range(300)]) + "\n")

ARGS = {
    "dir": tmpdir,
    "vocab_size": 1000,
    "embed_units": 300
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
sequence_loss Ran
ran on a synthesized input
siat-nlp/TransDG/src/model/seq_helper.py
code served (permissive licence) · get_code("de208a5655a13b94")
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 SymbolicTensor. 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 tensorflow as tf
import numpy as np

# Set seeds for reproducibility
tf.random.set_seed(0)
np.random.seed(0)

# Define parameters
num_symbols = 5  # vocabulary size
batch_size = 2
sequence_length = 3

# Create output_logits: shape [batch_size, sequence_length, num_symbols]
output_logits = tf.random.normal([batch_size, sequence_length, num_symbols])

# Create targets: shape [batch_size, sequence_length]
# Each target is a class index in range [0, num_symbols)
targets = tf.constant([[1, 2, 0], [3, 1, 4]], dtype=tf.int64)

# Create masks: shape [batch_size, sequence_length]
# Masks are floats (0.0 or 1.0) to indicate which positions are valid
masks = tf.constant([[1.0, 1.0, 0.0], [1.0, 1.0, 1.0]], dtype=tf.float32)

ARGS = {
    "num_symbols": num_symbols,
    "output_logits": output_logits,
    "targets": targets,
    "masks": masks,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type SymbolicTensor — a SymbolicTensor output has no array shape of its own; none is 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
bahdanau_attention Not yet run
unverified (harvested, no recorded run)
siat-nlp/TransDG/src/model/attention.py
code served (permissive licence) · get_code("70c07cf6f2977983")
How it ran

no invocation recorded.

dynamic_rnn_decoder Not yet run
unverified (harvested, no recorded run)
siat-nlp/TransDG/src/model/dynamic_decoder.py
code served (permissive licence) · get_code("e826d18bb3d1c124")
How it ran

no invocation recorded.

luong_attention Not yet run
unverified (harvested, no recorded run)
siat-nlp/TransDG/src/model/attention.py
code served (permissive licence) · get_code("edfbe3619d278b60")
How it ran

no invocation recorded.

ppx_loss Not yet run
unverified (harvested, no recorded run)
siat-nlp/TransDG/src/model/seq_helper.py
code served (permissive licence) · get_code("dbdc0b6a58715eb7")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 1 later) and 8 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
compute_bleu 10 other papers
1 dated earlier, 9 later
1909.09436 (2019-09)
CodeSearchNet Challenge: Evaluating the State of Semantic Code Search
2206.05239 (2022-06)
StructCoder: Structure-Aware Transformer for Code Generation
2206.08474 (2022-06)
XLCoST: A Benchmark Dataset for Cross-lingual Code Intelligence
and 7 more not named here

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-22.

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 network models usually suffer from the challenge of incorporating commonsense knowledge into the opendomain dialogue systems. In this paper, we propose a novel knowledge-aware dialogue generation model (called TransDG), which transfers question representation and knowledge matching abilities from knowledge base question answering (KBQA) task to facilitate the utterance understanding and factual knowledge selection for dialogue generation. In addition, we propose a response guiding attention and a multi-step decoding strategy to steer our model to focus on relevant features for response generation. Experiments on two benchmark datasets demonstrate that our model has robust superiority over compared methods in generating informative and fluent dialogues. Our code is available at https://github.com/siat-nlp/TransDG.

For agents

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

get_harvested_code_for_paper("aaai_6453")
get_code_for_paper("aaai_6453")
have("aaai_6453")

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

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

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

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

Connect an agent — have() is free.