test_data.py 文件源码

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

项目:focus_of_attention-RNN 作者: luochuwei 项目源码 文件源码
def word_sequence(f_path, batch_size = 1, i2w, w2i):
    test_seqs = []
    lines = []
    tf = {}
    f = open(curr_path + "/" + f_path, "r")
    for line in f:
        line = line.strip('\n').lower()
        words = ['<soss>']+line_x.split()+["<eoss>"]
        lines.append(words)
    f.close()

    for i in range(0, len(lines)):
        words = lines[i]
        x = np.zeros((len(words), len(w2i)), dtype = theano.config.floatX)
        for j in range(0, len(words)):
            if words[j] in w2i:
                x[j, w2i[words[j]]] = 1
        test_seqs.append(np.asmatrix(x))

    test_data_x = batch_sequences(test_seqs, i2w, w2i, batch_size)

    return test_seqs, i2w, w2i, test_data_x
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号