sentence_generator.py 文件源码

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

项目:ircbot 作者: pbzweihander 项目源码 文件源码
def generate_sentence(cfdist, word, num=15):
    sentence = []

    # Generate words until we meet a period
    while word!='.':
        sentence.append(word)

        # Generate the next word based on probability
        choices, weights = zip(*cfdist[word].items())
        cumdist = list(itertools.accumulate(weights))
        x = random.random() * cumdist[-1]
        word = choices[bisect.bisect(cumdist, x)]

    return ' '.join(sentence)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号