RecBole-GNN

repository·main·Indexed 41 days ago

https://github.com/rucaibox/recbole-gnn

A specialized library for developing and reproducing Graph Neural Network (GNN) based recommendation algorithms. Extending the RecBole framework, it supports General, Sequential, and Social recommendation tasks with efficient graph processing. It implements various models including LightGCN, NGCF, SR-GNN, and DiffNet, and is compatible with PyG, PyTorch, and recbole==1.1.1.

Tokens
3.7K
Snippets
10
Records
16
Agent score
53%

What's inside RecBole-GNN

  1. What is RecBole-GNN?

    main
    RecBole-GNN is a library built on PyTorch and RecBole designed for reproducing and developing recommendation algorithms based on Graph Neural Networks (GNNs). It provides a unified API and input format compatible with RecBole, covering General, Sequential, and Social recommendation tasks. It incorporates GNNs from libraries like PyG and provides efficient graph processing layers and datasets.
  2. Install RecBole-GNN requirements

    main

    To use RecBole-GNN, ensure your environment meets the following version requirements:

    • recbole==1.1.1
    • pyg>=2.0.4
    • pytorch>=1.7.0
    • python>=3.7.0

    Note: If you are using recbole==1.0.1, you must use the recbole1.0.1 branch of this repository.

    recbole==1.1.1
    pyg>=2.0.4
    pytorch>=1.7.0
    python>=3.7.0
  3. Configure dataset and training settings for MovieLens-1M

    main

    When working with the MovieLens-1M dataset in RecBole-GNN, use the following configuration parameters to ensure correct data loading, filtering, and training behavior.

    Data Loading & Filtering:

    • Use field_separator: "\t" and seq_separator: " " for parsing.
    • Define USER_ID_FIELD, ITEM_ID_FIELD, and RATING_FIELD to map dataset columns.
    • To filter interactions (e.g., removing ratings less than 3), use the val_interval key with a range string like "[3,inf)".
    • Specify columns to load via load_col and columns to ignore via unused_col.

    Training & Evaluation:

    • Set epochs for the total number of training iterations.
    • Adjust train_batch_size and eval_batch_size to manage memory usage.
    • Use valid_metric to specify which metric (e.g., MRR@10) should be used for validation.
    # dataset config
    field_separator: "\t"
    seq_separator: " "
    USER_ID_FIELD: user_id
    ITEM_ID_FIELD: item_id
    RATING_FIELD: rating
    NEG_PREFIX: neg_
    LABEL_FIELD: label
    load_col:
        inter: [user_id, item_id, rating]
    val_interval:
        rating: "[3,inf)"
    unused_col: 
        inter: [rating]
    
    # training and evaluation
    epochs: 500
    train_batch_size: 4096
    valid_metric: MRR@10
    eval_batch_size: 4096000
  4. Configure training and evaluation parameters

    main

    Use these settings to control the training lifecycle and evaluation process for the LastFM experiment:

    • epochs: Total number of training epochs (e.g., 5000).
    • train_batch_size: Batch size for training (e.g., 4096).
    • eval_batch_size: Batch size for evaluation (e.g., 409600000).
    • valid_metric: The metric used to determine the best model during validation (e.g., NDCG@10).
    • stopping_step: Number of steps to wait before stopping early (e.g., 50).
    • embedding_size: The dimension for users' and items' embeddings (e.g., 64). Note: You may need to adjust the argument name to match specific model requirements.
    # training and evaluation
    epochs: 5000
    train_batch_size: 4096
    eval_batch_size: 409600000
    valid_metric: NDCG@10
    stopping_step: 50
    
    # embedding dimension
    embedding_size: 64
  5. Configure dataset and social network settings for LastFM

    main

    When working with the LastFM dataset in RecBole-GNN, use the following configuration properties to define field mappings, separators, and social network behavior.

    Dataset Configuration:

    • field_separator: Character used to separate fields (e.g., \t).
    • seq_separator: Character used to separate sequences (e.g., ).
    • USER_ID_FIELD: The name of the user ID field.
    • ITEM_ID_FIELD: The name of the item ID field.
    • NET_SOURCE_ID_FIELD: The name of the source node ID in the social network.
    • NET_TARGET_ID_FIELD: The name of the target node ID in the social network.
    • LABEL_FIELD: The name of the label field.
    • NEG_PREFIX: Prefix for negative samples.
    • load_col: Mapping for loading columns, specifying inter (interaction) and net (network) fields.

    Social Network Configuration:

    • filter_net_by_inter: Boolean to determine if the network should be filtered by interactions.
    • undirected_net: Boolean to treat the social network as undirected.
    # dataset config
    field_separator: "\t"
    seq_separator: " "
    USER_ID_FIELD: user_id
    ITEM_ID_FIELD: artist_id
    NET_SOURCE_ID_FIELD: source_id
    NET_TARGET_ID_FIELD: target_id
    LABEL_FIELD: label
    NEG_PREFIX: neg_
    load_col:
      inter: [user_id, artist_id]
      net: [source_id, target_id]
    
    # social network config
    filter_net_by_inter: True
    undirected_net: True
  6. Configure the Diginetica dataset for sequential recommendation

    main

    To use the diginetica-not-merged dataset in RecBole-GNN, configure the following YAML settings. Note that users and items with fewer than 5 interactions are filtered out. The evaluation uses a leave-one-out strategy with full sort mode.

    Dataset Configuration

    • field_separator: \t
    • seq_separator: (space)
    • USER_ID_FIELD: session_id
    • ITEM_ID_FIELD: item_id
    • TIME_FIELD: timestamp
    • NEG_PREFIX: neg_
    • ITEM_LIST_LENGTH_FIELD: item_length
    • LIST_SUFFIX: _list
    • MAX_ITEM_LIST_LENGTH: 20
    • POSITION_FIELD: position_id
    • load_col.inter: [session_id, item_id, timestamp]
    • user_inter_num_interval: "[5,inf)"
    • item_inter_num_interval: "[5,inf)"

    Training and Evaluation Configuration

    • epochs: 500
    • train_batch_size: 4096
    • eval_batch_size: 2000
    • valid_metric: MRR@10
    • eval_args:
      • split: {'LS':"valid_and_test"}
      • mode: full
      • order: TO (Time Order)

    Global Constraints

    To ensure fairness across models, restrict the embedding dimension:

    • embedding_size: 64 (Note: You may need to adjust the specific argument name depending on the model being used).
    # dataset config
    field_separator: "\t"
    seq_separator: " "
    USER_ID_FIELD: session_id
    ITEM_ID_FIELD: item_id
    TIME_FIELD: timestamp
    NEG_PREFIX: neg_
    ITEM_LIST_LENGTH_FIELD: item_length
    LIST_SUFFIX: _list
    MAX_ITEM_LIST_LENGTH: 20
    POSITION_FIELD: position_id
    load_col:
      inter: [session_id, item_id, timestamp]
    user_inter_num_interval: "[5,inf)"
    item_inter_num_interval: "[5,inf)"
    
    # training and evaluation
    epochs: 500
    train_batch_size: 4096
    eval_batch_size: 2000
    valid_metric: MRR@10
    eval_args:
      split: {'LS':"valid_and_test"}
      mode: full
      order: TO
    train_neg_sample_args: ~
    
    # fairness constraint
    embedding_size: 64
  7. Run RecBole-GNN with specific models and datasets

    main

    To customize your experiment, use the -m flag to specify a model and the -d flag to specify a dataset when running the run_recbole_gnn.py script.

    python run_recbole_gnn.py -m [model] -d [dataset]
  8. Overview of implemented GNN models

    main

    RecBole-GNN implements various Graph Neural Network models categorized by recommendation type:

    General Recommendation

    (User-item interaction graphs)

    • NGCF
    • LightGCN (supports sparse tensor acceleration)
    • SSL4Rec
    • SGL
    • HMLET
    • NCL
    • DirectAU
    • SimGCL
    • XSimGCL
    • LightGCL

    Sequential Recommendation

    (Session/sequence graphs)

    • SR-GNN
    • GC-SAN
    • NISER+
    • LESSR
    • TAGNN
    • GCE-GNN
    • SGNN-HN

    Social Recommendation

    (Social networks)

    • DiffNet
    • MHCN
    • SEPT

    Note: Social recommendation datasets can be obtained from the Social-Datasets repository.