Differences with torchtext.datasets.IMDB

View Source On Gitee

torchtext.datasets.IMDB

class torchtext.datasets.IMDB(
    root: str = '.data',
    split: Union[List[str], str] = ('train', 'test'))

For more information, see torchtext.datasets.IMDB.

mindspore.dataset.IMDBDataset

class mindspore.dataset.IMDBDataset(
    dataset_dir,
    usage=None,
    num_samples=None,
    num_parallel_workers=None,
    shuffle=None,
    sampler=None,
    num_shards=None,
    shard_id=None,
    cache=None)

For more information, see mindspore.dataset.IMDBDataset.

Differences

PyTorch: Read the IMDB dataset.

MindSpore: Read the IMDB dataset. Download dataset from web is not supported.

Categories

Subcategories

PyTorch

MindSpore

Difference

Parameter

Parameter1

root

dataset_dir

-

Parameter2

split

usage

-

Parameter3

-

num_samples

The number of images to be included in the dataset

Parameter4

-

num_parallel_workers

Number of worker threads to read the data

Parameter5

-

shuffle

Whether to perform shuffle on the dataset

Parameter6

-

sampler

Object used to choose samples from the dataset

Parameter7

-

num_shards

Number of shards that the dataset will be divided into

Parameter8

-

shard_id

The shard ID within num_shards

Parameter9

-

cache

Use tensor caching service to speed up dataset processing

Code Example

# PyTorch
import torchtext.datasets as datasets
from torch.utils.data import DataLoader

root = "/path/to/dataset_directory/"
dataset = datasets.IMDB(root, split=('train', 'test'))
dataloader = DataLoader(dataset)

# MindSpore
import mindspore.dataset as ds

# Download IMDB dataset files, unzip into the following structure
# .
# └── /path/to/dataset_directory/
#      ├── train
#      │    ├── pos
#      │    │    ├── 0_9.txt
#      │    │    ├── 1_7.txt
#      │    │    ├── ...
#      │    ├── neg
#      │    │    ├── 0_3.txt
#      │    │    ├── 1_1.txt
#      │    │    ├── ...
#      ├── test
#      │    ├── pos
#      │    │    ├── 0_10.txt
#      │    │    ├── 1_10.txt
#      │    │    ├── ...
#      │    ├── neg
#      │    │    ├── 0_2.txt
#      │    │    ├── 1_3.txt
#      │    │    ├── ...
root = "/path/to/dataset_directory/"
ms_dataloader = ds.IMDBDataset(root, usage='all')