コード例 #1
0
ファイル: demo.py プロジェクト: granilace/squad
def main():
    path = input('Enter file path of your model:')

    with open(RAW_META_PATH, 'rb') as f:
        meta = msgpack.load(f, encoding='utf8')

    embedding = load_pickle(EMB_PATH)

    model = models.AttentionModel(path)

    w2id = {w: i for i, w in enumerate(meta['vocab'])}
    tag2id = {w: i for i, w in enumerate(meta['vocab_tag'])}
    ent2id = {w: i for i, w in enumerate(meta['vocab_ent'])}

    while True:
        id_ = 0
        try:
            while True:
                context = input('Enter context: ')
                if context.strip():
                    break
            while True:
                question = input('Enter question: ')
                if question.strip():
                    break
        except EOFError:
            break
        id_ += 1
        annotated = annotate(('interact-{}'.format(id_), context, question),
                             meta['wv_cased'])
        model_in_raw = to_id(annotated, w2id, tag2id, ent2id)
        model_in = generate_batch(model_in_raw)
        start_probas, end_probas = model.model.predict(model_in)
        answ_pair = get_preds2(start_probas, end_probas, MAX_ANSW_LEN)
        print('Answer:', end=' ')
        for i in range(answ_pair[0][0], answ_pair[0][1] + 1):
            print(model_in_raw[6][model_in_raw[7][i][0]:model_in_raw[7][i][1] +
                                  1],
                  end='')
        print('\n\n\n-------------|||-------------\n\n\n')
コード例 #2
0
                                img_dim=X.shape[2],
                                n_outputs=10)

        results = {}

        for i in range(10):
            model.fit(X, y, epochs=1, batch_size=50, verbose=0)

            # EVALUATE TRAIN AND TEST CLASSIFICATION
            yhat = np.argmax(model.predict(X), axis=1)
            trainscore = (yhat == y).mean()

            yhat = np.argmax(model.predict(Xtest), axis=1)
            testscore = (yhat == ytest).mean()

            print("%d - Train score = %.3f" % (i, trainscore))
            print("%d - Test score = %.3f\n" % (i, testscore))

        # BASELINE TEST score IS 91%

    elif part == '7':
        X, y = du.load_dataset("boat_images", as_image=False)

        # TRAIN NETWORK
        model = models.AttentionModel(n_channels=3, n_outputs=1)
        model.fit(X, y, batch_size=23, epochs=100)
        show = lambda m, i: iu.show(m.get_heatmap(X)[i], X[i])
        import pdb
        pdb.set_trace()  # breakpoint 387f960a //
        show(model, 1)
コード例 #3
0
def main():
    path = input('Enter file path of your model:')
    att_model = models.AttentionModel(path)
    att_model.quality()
コード例 #4
0
def main():
    epochs = input('Enter amount of epochs')
    att_model = models.AttentionModel()
    att_model.train(n_epochs=epochs)