Exemple #1
0
def diagnosis_example(num_graphs=200,
                      num_processing_steps_tr=5,
                      num_processing_steps_ge=5,
                      num_training_iterations=1000,
                      keyspace=KEYSPACE,
                      uri=URI):
    """
    Run the diagnosis example from start to finish, including traceably ingesting predictions back into Grakn

    Args:
        num_graphs: Number of graphs to use for training and testing combined
        num_processing_steps_tr: The number of message-passing steps for training
        num_processing_steps_ge: The number of message-passing steps for testing
        num_training_iterations: The number of training epochs
        keyspace: The name of the keyspace to retrieve example subgraphs from
        uri: The uri of the running Grakn instance

    Returns:
        Final accuracies for training and for testing
    """

    tr_ge_split = int(num_graphs * 0.5)

    generate_example_graphs(num_graphs, keyspace=keyspace, uri=uri)

    client = GraknClient(uri=uri)
    session = client.session(keyspace=keyspace)

    graphs = create_concept_graphs(list(range(num_graphs)), session)

    with session.transaction().read() as tx:
        # Change the terminology here onwards from thing -> node and role -> edge
        node_types = get_thing_types(tx)
        [node_types.remove(el) for el in TYPES_TO_IGNORE]

        edge_types = get_role_types(tx)
        [edge_types.remove(el) for el in ROLES_TO_IGNORE]
        print(f'Found node types: {node_types}')
        print(f'Found edge types: {edge_types}')

    ge_graphs, solveds_tr, solveds_ge = pipeline(
        graphs,
        tr_ge_split,
        node_types,
        edge_types,
        num_processing_steps_tr=num_processing_steps_tr,
        num_processing_steps_ge=num_processing_steps_ge,
        num_training_iterations=num_training_iterations,
        continuous_attributes=CONTINUOUS_ATTRIBUTES,
        categorical_attributes=CATEGORICAL_ATTRIBUTES,
        output_dir=f"./events/{time.time()}/")

    with session.transaction().write() as tx:
        write_predictions_to_grakn(ge_graphs, tx)

    session.close()
    client.close()

    return solveds_tr, solveds_ge
Exemple #2
0
def diagnosis_example(num_graphs=200,
                      num_processing_steps_tr=10,
                      num_processing_steps_ge=10,
                      num_training_iterations=1000,
                      keyspace="diagnosis",
                      uri="localhost:48555"):

    tr_ge_split = int(num_graphs * 0.5)

    generate_example_graphs(num_graphs, keyspace=keyspace, uri=uri)

    client = GraknClient(uri=uri)
    session = client.session(keyspace=keyspace)

    graphs = create_concept_graphs(list(range(num_graphs)), session)

    with session.transaction().read() as tx:
        # Change the terminology here onwards from thing -> node and role -> edge
        node_types = get_thing_types(tx)
        edge_types = get_role_types(tx)
        print(f'Found node types: {node_types}')
        print(f'Found edge types: {edge_types}')

    ge_graphs, solveds_tr, solveds_ge = pipeline(
        graphs,
        tr_ge_split,
        node_types,
        edge_types,
        num_processing_steps_tr=num_processing_steps_tr,
        num_processing_steps_ge=num_processing_steps_ge,
        num_training_iterations=num_training_iterations,
        continuous_attributes=CONTINUOUS_ATTRIBUTES,
        categorical_attributes=CATEGORICAL_ATTRIBUTES,
        output_dir=f"./events/{time.time()}/")

    with session.transaction().write() as tx:
        write_predictions_to_grakn(ge_graphs, tx)

    session.close()
    client.close()

    return solveds_tr, solveds_ge