text-graph-generalization

Code for our paper Compositional Generalization with Grounded Language Models
git clone https://esimon.eu/repos/text-graph-generalization.git
Log | Files | Refs | README | LICENSE

commit f6f89de01867e03e24d2a9828af9c3e4d3068518
parent c196be5171521e5c214fd029210e83eba57f5735
Author: Sondre Wold <sondrewold1@gmail.com>
Date:   Thu, 30 May 2024 15:18:26 +0200

Add stats files

Diffstat:
Acalculate_graph_statistics.py | 28++++++++++++++++++++++++++++
1 file changed, 28 insertions(+), 0 deletions(-)

diff --git a/calculate_graph_statistics.py b/calculate_graph_statistics.py @@ -0,0 +1,28 @@ +from graph_sampler import preprocess_graph +import json +from rdflib.extras.external_graph_libs import rdflib_to_networkx_multidigraph +from tqdm import tqdm +import networkx as nx +import numpy as np +import pathlib +import rdflib + + +if __name__ == '__main__': + raw_graphs = pathlib.Path("./raw_graphs/") + n_nodes = [] + n_edges = [] + + for input_file in tqdm(raw_graphs.iterdir()): + rdf_graph = rdflib.Graph() + rdf_graph.parse(input_file) + original_graph: nx.MultiDiGraph = rdflib_to_networkx_multidigraph(rdf_graph) + filtered_graph, possible_relations = preprocess_graph(original_graph) + n_nodes.append(len(filtered_graph.nodes())) + n_edges.append(len(filtered_graph.edges())) + print(f"Mean nodes: {np.mean(n_nodes)}, std: {np.std(n_nodes)}") + print(f"Mean edges: {np.mean(n_edges)}, std: {np.std(n_edges)}") + + stats = {"nodes":[np.mean(n_nodes), np.std(n_nodes)], "edges": [np.mean(n_edges), np.std(n_edges)]} + with open("./graph_stats.json", "w") as f: + json.dump(stats, f)