示例#1
0
def report(docs, t, idx, loss, results):
    print "{0} epoch, {1}th data".format(t, idx)
    print loss.data, np.linalg.norm(cuda.to_cpu_async(model.Wh1.W)), np.linalg.norm(
        cuda.to_cpu_async(model.Wh2.W)
    ), np.linalg.norm(cuda.to_cpu_async(model.Wx1.W))
    print "------------------------------------------"
    print to_text([d[0] for d in docs], vocablary)
    print "=========================================="
    print to_text(results, vocablary)
    print "------------------------------------------"
示例#2
0
def report(docs, t, idx, loss, results):
    print "{0} epoch, {1}th data".format(t, idx)
    print loss.data, np.linalg.norm(cuda.to_cpu_async(
        model.Wh1.W)), np.linalg.norm(cuda.to_cpu_async(
            model.Wh2.W)), np.linalg.norm(cuda.to_cpu_async(model.Wx1.W))
    print "------------------------------------------"
    print to_text([d[0] for d in docs], vocablary)
    print "=========================================="
    print to_text(results, vocablary)
    print "------------------------------------------"
示例#3
0
def forward_one_step(h1, h2, cur_word, next_word, volatile=False):
    word = V(cur_word, volatile=volatile)
    x = F.leaky_relu(model.embed(word))

    tmp_x = model.Wx1(x)
    tmp_h1 = model.Wh1(h1)
    h1 = F.leaky_relu(tmp_x + tmp_h1)

    tmp_x2 = model.Wx2(h1)
    tmp_h2 = model.Wh2(h2)
    h2 = F.leaky_relu(tmp_x2 + tmp_h2)

    y = model.Wy(h2)
    t = V(next_word, volatile=volatile)
    loss = F.softmax_cross_entropy(y, t)
    pred = F.softmax(y)
    return h1, h2, loss, np.argmax(cuda.to_cpu_async(pred.data))
示例#4
0
def forward_one_step(h1, h2, cur_word, next_word, volatile=False):
    word = V(cur_word, volatile=volatile)
    x = F.leaky_relu(model.embed(word))

    tmp_x = model.Wx1(x)
    tmp_h1 = model.Wh1(h1)
    h1 = F.leaky_relu(tmp_x + tmp_h1)

    tmp_x2 = model.Wx2(h1)
    tmp_h2 = model.Wh2(h2)
    h2 = F.leaky_relu(tmp_x2 + tmp_h2)

    y = model.Wy(h2)
    t = V(next_word, volatile=volatile)
    loss = F.softmax_cross_entropy(y, t)
    pred = F.softmax(y)
    return h1, h2, loss, np.argmax(cuda.to_cpu_async(pred.data))
示例#5
0
def serialize_model(namespace, epoch, model, vocab):
    file_path = "data/model_{0}_{1}.pickle".format(namespace, epoch)
    pickle.dump((cuda.to_cpu_async(model), vocab), open(file_path, "wb"), -1)
示例#6
0
def serialize_model(namespace, epoch, model, vocab):
    file_path = "data/model_{0}_{1}.pickle".format(namespace, epoch)
    pickle.dump((cuda.to_cpu_async(model), vocab), open(file_path, 'wb'), -1)