Federated Matrix Factorization Module References

federatedscope.mf.dataset

class federatedscope.mf.dataset.HFLMovieLens10M(root, num_client, train_portion=0.9, download=True)[source]

MovieLens10M dataset in HFL setting

class federatedscope.mf.dataset.HFLMovieLens1M(root, num_client, train_portion=0.9, download=True)[source]

MovieLens1M dataset in HFL setting

class federatedscope.mf.dataset.HMFDataset[source]

Dataset of matrix factorization task in horizontal federated learning.

class federatedscope.mf.dataset.MovieLens10M(root, num_client, train_portion=0.9, download=True)[source]

MoviesLens 10M Dataset (https://grouplens.org/datasets/movielens)

Format:

UserID::MovieID::Rating::Timestamp

Parameters
  • root (str) – Root directory of dataset where directory MoviesLen1M exists or will be saved to if download is set to True.

  • config (callable) – Parameters related to matrix factorization.

  • train_size (float, optional) – The proportion of training data.

  • test_size (float, optional) – The proportion of test data.

  • download (bool, optional) – If true, downloads the dataset from the

  • and (internet) – puts it in root directory. If dataset is already downloaded, it is not downloaded again.

class federatedscope.mf.dataset.MovieLens1M(root, num_client, train_portion=0.9, download=True)[source]

MoviesLens 1M Dataset (https://grouplens.org/datasets/movielens)

Format:

UserID::MovieID::Rating::Timestamp

Parameters
  • root (str) – Root directory of dataset where directory MoviesLen1M exists or will be saved to if download is set to True.

  • config (callable) – Parameters related to matrix factorization.

  • train_size (float, optional) – The proportion of training data.

  • test_size (float, optional) – The proportion of test data.

  • download (bool, optional) – If true, downloads the dataset from the

  • already (internet and puts it in root directory. If dataset is) –

  • downloaded

  • again. (it is not downloaded) –

class federatedscope.mf.dataset.MovieLensData(root, num_client, train_portion=0.9, download=True)[source]

Download and split MF datasets

Parameters
  • root (string) – the path of data

  • num_client (int) – the number of clients

  • train_portion (float) – the portion of training data

  • download (bool) – indicator to download dataset

class federatedscope.mf.dataset.VFLMovieLens10M(root, num_client, train_portion=0.9, download=True)[source]

MovieLens10M dataset in VFL setting

class federatedscope.mf.dataset.VFLMovieLens1M(root, num_client, train_portion=0.9, download=True)[source]

MovieLens1M dataset in VFL setting

class federatedscope.mf.dataset.VMFDataset[source]

Dataset of matrix factorization task in vertical federated learning.

federatedscope.mf.model

class federatedscope.mf.model.BasicMFNet(num_user, num_item, num_hidden)[source]

Basic model for MF task

Parameters
  • num_user (int) – the number of users

  • num_item (int) – the number of items

  • num_hidden (int) – the dimension of embedding vector

forward(indices, ratings)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

load_state_dict(state_dict, strict: bool = True)[source]

Copies parameters and buffers from state_dict into this module and its descendants. If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Parameters
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

Returns

  • missing_keys is a list of str containing the missing keys

  • unexpected_keys is a list of str containing the unexpected keys

Return type

NamedTuple with missing_keys and unexpected_keys fields

state_dict(destination=None, prefix='', keep_vars=False)[source]

Returns a dictionary containing a whole state of the module.

Both parameters and persistent buffers (e.g. running averages) are included. Keys are corresponding parameter and buffer names.

Returns

a dictionary containing a whole state of the module

Return type

dict

Example:

>>> module.state_dict().keys()
['bias', 'weight']
class federatedscope.mf.model.HMFNet(num_user, num_item, num_hidden)[source]

MF model for horizontal federated learning

class federatedscope.mf.model.VMFNet(num_user, num_item, num_hidden)[source]

MF model for vertical federated learning

federatedscope.mf.model.get_mfnet(model_config, data_shape)[source]

Return the MF model according to model configs

Parameters
  • model_config – the model related parameters

  • data_shape (int) – the input shape of the model

federatedscope.mf.dataloader

class federatedscope.mf.dataloader.MFDataLoader(data: scipy.sparse.csc.csc_matrix, batch_size: int, shuffle=True, drop_last=False, theta=None)[source]

DataLoader for MF dataset

Parameters
  • data (csc_matrix) – sparse MF dataset

  • batch_size (int) – the size of batch data

  • shuffle (bool) – shuffle the dataset

  • drop_last (bool) – drop the last batch if True

  • theta (int) – the maximal number of ratings for each user

federatedscope.mf.dataloader.load_mf_dataset(config=None)[source]

Return the dataset of matrix factorization

Format:
{
‘client_id’: {

‘train’: DataLoader(), ‘test’: DataLoader(), ‘val’: DataLoader()

}

}

federatedscope.mf.trainer