Movielens

class paddle.text. Movielens ( data_file=None, mode='train', test_ratio=0.1, rand_seed=0, download=True ) [源代码]

该类是对 Movielens 1-M 测试数据集的实现。

参数

  • data_file (str) - 保存压缩数据的路径,如果参数 :attr:`download`设置为 True,可设置为 None。默认为 None。

  • mode (str) - 'train' 或 'test' 模式。默认为'train'。

  • test_ratio (float) - 为测试集划分的比例。默认为 0.1。

  • rand_seed (int) - 随机数种子。默认为 0。

  • download (bool) - 如果 :attr:`data_file`未设置,是否自动下载数据集。默认为 True。

返回值

Dataset,Movielens 1-M 数据集实例。

代码示例

>>> import paddle
>>> from paddle.text.datasets import Movielens

>>> class SimpleNet(paddle.nn.Layer):
...     def __init__(self):
...         super().__init__()
...
...     def forward(self, category, title, rating):
...         return paddle.sum(category), paddle.sum(title), paddle.sum(rating)


>>> movielens = Movielens(mode='train')

>>> for i in range(10):
...     category, title, rating = movielens[i][-3:]
...     category = paddle.to_tensor(category)
...     title = paddle.to_tensor(title)
...     rating = paddle.to_tensor(rating)
...
...     model = SimpleNet()
...     category, title, rating = model(category, title, rating)
...     print(category.shape, title.shape, rating.shape)
[] [] []
[] [] []
[] [] []
[] [] []
[] [] []
[] [] []
[] [] []
[] [] []
[] [] []
[] [] []