Пример #1
0
if __name__ == "__main__":
    args = docopt(__doc__)

    # load test data
    with open("data/snli/test.pkl", "rb") as fin:
        test = pickle.load(fin)
    input_embeddings = np.load("data/snli/input_embeddings.npy")

    model = dy.Model()

    parsed = False
    if args["cyk"]:
        net = networks.CYK(
            model,
            input_embeddings,
            update_embeddings=False,
            hidden_dim=100,
        )
        if args["--inv-temp"] is not None:
            net.inv_temp = float(args["--inv-temp"])
            print("Inverse temperature set to " + str(net.inv_temp))
    elif args["ltr-cyk"]:
        net = networks.CYK(
            model,
            input_embeddings,
            update_embeddings=False,
            hidden_dim=100,
            order=1,
        )
    elif args["rtl-cyk"]:
        net = networks.CYK(
Пример #2
0
    return np.median(ranks), accuracy10, accuracy100

if __name__ == "__main__":
    args = docopt(__doc__)

    model = dy.Model()

    update_embeddings = bool(args["--update-embeddings"])
    input_embeddings = np.load("data/dicteval/input_embeddings.reduced.npy")
    hidden_dim = 256
    parsed = False

    if args["cyk"]:
        net = networks.CYK(
            model,
            input_embeddings,
            update_embeddings = update_embeddings,
            hidden_dim = hidden_dim,
        )
    elif args["ltr-cyk"]:
        net = networks.CYK(
            model,
            input_embeddings,
            update_embeddings = update_embeddings,
            hidden_dim = hidden_dim,
            order = 1,
        )
    elif args["rtl-cyk"]:
        net = networks.CYK(
            model,
            input_embeddings,
            update_embeddings = update_embeddings,
Пример #3
0
args = docopt(__doc__)

# load the embeddings and vocab
embeddings = np.load("data/snli2/input_embeddings.npy")
vocab = []
with open("data/snli2/input_vocab.txt") as fin:
    for line in fin:
        vocab.append(line.strip().split("\t")[0])
bacov = {n: i for i, n in enumerate(vocab)}
dim = embeddings.shape[1]

# initialise and restore the model
model = dy.Model()
net = networks.CYK(
    model,
    embeddings,
    update_embeddings = False,
    hidden_dim = 100,
)
model.load(args["<model-file>"])
net.inv_temp = float(args["--inv-temp"])

while True:
    try:
        words = list(map(lambda x: cleanup(x), input("Sentence: ").split(" ")))
        indices = [bacov[w] for w in words if w in bacov]
        n = len(indices)
        _, weights = net(np.reshape(indices, (n, 1)), )
        tree = build_subtree(weights, words)
        tree.render("/home/jm864/public_html/graphviz.gv", view = False)
    except (EOFError, ValueError):
        break