当前位置:   article > 正文

【PyTorch】关于函数 datasets.IMDB.splits()_imdb(root="data", split="train")

imdb(root="data", split="train")
  • I M D B \rm IMDB IMDB 是关于电影评论的数据集,其中有 50000 50000 50000 条情感倾向明显的评论信息,其中 25000 25000 25000 条作为训练集, 25000 25000 25000 条作为测试集。并且数据的总体分布是均衡的,即正面评价和负面评价各 25000 25000 25000 条。
  • 下面的代码可以将 t o r c h t e x t . d a t a s e t s \rm torchtext.datasets torchtext.datasets 中的 I M D B \rm IMDB IMDB 数据集分割成文本 T E X T \rm TEXT TEXT 和标签 L A B E L \rm LABEL LABEL 两部分。
train,test = datasets.IMDB.splits(TEXT,LABEL)
  • 1
  • s p l i t s ( ) \rm splits() splits() 方法的定义如下:
@classmethod
def splits(cls, text_field, label_field, root='.data',
			train='train', test='test', **kwargs):
	"""Create dataset objects for splits of the IMDB dataset.

	 Arguments:
		text_field: The field that will be used for the sentence.
		label_field: The field that will be used for label data.
		root: Root dataset storage directory. Default is '.data'.
		train: The directory that contains the training examples
		test: The directory that contains the test examples
		Remaining keyword arguments: Passed to the splits method of Dataset.
        """
        return super(IMDB, cls).splits(
            root=root, text_field=text_field, label_field=label_field,
            train=train, validation=None, test=test, **kwargs)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 对比定义和调用方式,可以看出 T E X T , L A B E L \rm TEXT,LABEL TEXT,LABEL 是两个 F i e l d \rm Field Field 类型的对象。下载到本地的 I M D B \rm IMDB IMDB 数据集组织如下所示:
    在这里插入图片描述
  • 下图是 P y T o r c h \rm PyTorch PyTorch 官网给出的 I M D B \rm IMDB IMDB 信息:
    在这里插入图片描述

  • G i t H u b \rm GitHub GitHub 上有这样一个问题:
    在这里插入图片描述
  • 我们希望训练集与测试集不是对半分的,而是以某个比值 r r r,例如这里的 0.8. 0.8. 0.8. 需要明确,通过 d a t a s e t s . I M D B \rm datasets.IMDB datasets.IMDB 这种方式获取到的数据集,是服务器上组织后的数据集,其 t r a i n , t e s t \rm train,test train,test 均已确定,即官网给出的 25000   v s   25000 \rm 25000~vs~25000 25000 vs 25000,如果需要改变这个划分方式,需要在本地对数据集进行修改并读取。

  • 在下载后的 I M D B \rm IMDB IMDB 压缩文件中,发现 t r a i n / u n s u p \rm train/unsup train/unsup 文件夹,官方数据集对其描述如下:
We also include an additional 50,000 unlabeled documents for unsupervised learning. 
  • 1

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/353344?site
推荐阅读
相关标签
  

闽ICP备14008679号