Shortcuts

Source code for torchtext.datasets.imdb

from torchtext.utils import download_from_url, extract_archive
from torchtext.data.datasets_utils import _RawTextIterableDataset
from torchtext.data.datasets_utils import _wrap_split_argument
from torchtext.data.datasets_utils import _add_docstring_header
import io

URL = 'http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz'

MD5 = '7c2ac02c03563afcf9b574c7e56c153a'

NUM_LINES = {
    'train': 25000,
    'test': 25000,
}

_PATH = 'aclImdb_v1.tar.gz'


[docs]@_add_docstring_header(num_lines=NUM_LINES, num_classes=2) @_wrap_split_argument(('train', 'test')) def IMDB(root, split): def generate_imdb_data(key, extracted_files): for fname in extracted_files: if 'urls' in fname: continue elif key in fname and ('pos' in fname or 'neg' in fname): with io.open(fname, encoding="utf8") as f: label = 'pos' if 'pos' in fname else 'neg' yield label, f.read() dataset_tar = download_from_url(URL, root=root, hash_value=MD5, hash_type='md5') extracted_files = extract_archive(dataset_tar) iterator = generate_imdb_data(split, extracted_files) return _RawTextIterableDataset("IMDB", NUM_LINES[split], iterator)

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources