repl.py 文件源码

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

项目:baseline 作者: dpressel 项目源码 文件源码
def classifier_repl(classifier, **kwargs):

    mxlen = int(kwargs.get('mxlen', 100))
    k = int(kwargs.get('k', 1))
    thresh = float(kwargs.get('thresh', 0.0))
    zeropad = int(kwargs.get('zeropad', 0))
    prompt_name = kwargs.get('prompt', 'class> ')
    history_file = kwargs.get('history_file', '.history')
    history = FileHistory(history_file)

    while True:
        text = prompt(prompt_name, history=history)
        text = text.strip()
        if text == 'quit':
            break
        try:
            tokens = text.split(' ')
            outcomes = classifier.classify_text(tokens, mxlen=mxlen, zeropad=zeropad)
            k = min(k, len(outcomes))
            probs = outcomes[:k]
            for prob_i in probs:
                if prob_i[1] > thresh:
                    print('Guess [%s]: %.3f' % prob_i)

        except Exception as e:
            logging.exception('Error')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号