random-graphs / README.md
vstenby's picture
Upload README.md with huggingface_hub
e089f7b verified
metadata
language: en
license: mit
size_categories:
  - 10K<n<100K
task_categories:
  - graph-ml
tags:
  - graphs
  - synthetic
  - erdos-renyi
  - barabasi-albert
  - watts-strogatz
  - stochastic-block-model
  - complete-graph
  - graph-qa

Graph Dataset with Task Labels

A synthetic graph dataset containing graphs generated using five different algorithms, with pre-computed answers for 9 graph reasoning tasks.

Dataset Description

This dataset contains synthetic graphs represented as edge lists, along with ground-truth answers for various graph reasoning tasks. The graphs are generated using five classical random graph models:

  • Erdős–Rényi: Random graphs where each edge is included independently with probability p
  • Barabási–Albert: Scale-free networks generated using preferential attachment
  • Watts–Strogatz: Small-world networks with high clustering and short path lengths
  • Stochastic Block Model: Community-structured graphs with 2-4 communities, higher edge probability within communities than between
  • Complete Graph: Fully connected graphs where every pair of nodes is connected

Dataset Structure

Data Fields

Field Type Description
algorithm string Graph generation algorithm: erdos_renyi, barabasi_albert, watts_strogatz, stochastic_block_model, or complete
edge_list string Edge list in format [(u, v), (x, y), ...]

Task Columns

Task Fields Description
node_count node_count (int) Number of nodes in the graph
edge_count edge_count (int) Number of edges in the graph
node_degree node_degree_node (int), node_degree (int) Sampled node and its degree
edge_existence edge_existence_src (int), edge_existence_dst (int), edge_existence (bool) Two sampled nodes and whether an edge exists between them
cycle_check cycle_check (bool) Whether the graph contains a cycle
triangle_counting triangle_count (int) Number of triangles in the graph
connected_nodes connected_nodes_node (int), connected_nodes (string) Sampled node and comma-separated list of its neighbors
reachability reachability_src (int), reachability_dst (int), reachability (bool) Two sampled nodes and whether a path exists between them
shortest_path shortest_path_src (int), shortest_path_dst (int), shortest_path (int) Two sampled nodes and shortest path length (-1 if no path exists)

Data Splits

Split Number of Examples
train 10000
validation 1000
test 1000

Graph Statistics

  • Node range: [5, 25]
  • Algorithms: Balanced across all five types (cycled)

Usage

from datasets import load_dataset

dataset = load_dataset("vstenby/random-graphs")

# Access a sample
sample = dataset["train"][0]
print(f"Algorithm: {sample['algorithm']}")
print(f"Node count: {sample['node_count']}")
print(f"Edge count: {sample['edge_count']}")
print(f"Has cycle: {sample['cycle_check']}")
print(f"Triangle count: {sample['triangle_count']}")

# Node-specific tasks
print(f"Node {sample['node_degree_node']} has degree {sample['node_degree']}")
print(f"Node {sample['connected_nodes_node']} is connected to: {sample['connected_nodes']}")

# Edge/path tasks
print(f"Edge between {sample['edge_existence_src']} and {sample['edge_existence_dst']}: {sample['edge_existence']}")
print(f"Path from {sample['reachability_src']} to {sample['reachability_dst']}: {sample['reachability']}")
print(f"Shortest path from {sample['shortest_path_src']} to {sample['shortest_path_dst']}: {sample['shortest_path']}")

Converting to NetworkX

import networkx as nx
import ast

def parse_edge_list(edge_list_str):
    """Parse edge list string to list of tuples."""
    if not edge_list_str or edge_list_str == "[]":
        return []
    return ast.literal_eval(edge_list_str)

sample = dataset["train"][0]
edges = parse_edge_list(sample["edge_list"])
G = nx.Graph()
G.add_nodes_from(range(sample["node_count"]))
G.add_edges_from(edges)

Generation Details

  • Random seed: 42 (train), 43 (validation), 44 (test)
  • Generation method: Each graph has a random number of nodes uniformly sampled from [5, 25]
  • Task sampling: For tasks requiring node/edge sampling (node_degree, edge_existence, connected_nodes, reachability, shortest_path), nodes are sampled uniformly at random

License

MIT License

MIT License