【PyTorch】关于函数 datasets.IMDB.splits()

  • 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)
  • 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)
  • 对比定义和调用方式,可以看出 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. 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值