bst_dataset.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:CopyNet 作者: MultiPath 项目源码 文件源码
def generate():
    import random, sys
    random.seed(19920206)

    Lmin   = 2 ** 2 - 1
    Lmax   = 2 ** 4 - 1
    Xnum   = 1000000
    voc    = 26

    wfile  = open('/home/thoma/Work/Dial-DRL/dataset/BST_1M.txt', 'w')
    for id in xrange(Xnum):
        tree   = BST()
        items  = (random.randrange(voc) for i in
                 xrange(random.randint(Lmin, Lmax)))
        source = []
        for item in items:
            item = chr(item + 65)
            tree.insert(item)
            source += [str(item)]
        source = ' '.join(source)
        target = str(tree)
        line   = '{0} -> {1}'.format(source, target)
        wfile.write(line + '\n')
        if id % 10000 == 0:
            print id
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号