# Get the first row in the dataset >>> dataset[0] {'label': 1, 'text': 'the rock is destined to be the 21st century\'s new " conan " and that he\'s going to make a splash even greater than arnold schwarzenegger , jean-claud van damme or steven segal .'}
使用-运算符从数据集的末尾开始:
1 2 3 4
# Get the last row in the dataset >>> dataset[-1] {'label': 0, 'text': 'things really get weird , though not particularly scary : the movie is all portent and no content .'}
按列名索引会返回列中所有值的列表:
1 2 3 4 5 6
>>> dataset["text"] ['the rock is destined to be the 21st century\'s new " conan " and that he\'s going to make a splash even greater than arnold schwarzenegger , jean-claud van damme or steven segal .', 'the gorgeously elaborate continuation of " the lord of the rings " trilogy is so huge that a column of words cannot adequately describe co-writer/director peter jackson\'s expanded vision of j . r . r . tolkien\'s middle-earth .', 'effective but too-tepid biopic', ..., 'things really get weird , though not particularly scary : the movie is all portent and no content .']
您可以组合行名和列名索引以在某个位置返回特定值:
1 2
>>> dataset[0]["text"] 'the rock is destined to be the 21st century\'s new " conan " and that he\'s going to make a splash even greater than arnold schwarzenegger , jean-claud van damme or steven segal .'
# Get the first three rows >>> dataset[:3] {'label': [1, 1, 1], 'text': ['the rock is destined to be the 21st century\'s new " conan " and that he\'s going to make a splash even greater than arnold schwarzenegger , jean-claud van damme or steven segal .', 'the gorgeously elaborate continuation of " the lord of the rings " trilogy is so huge that a column of words cannot adequately describe co-writer/director peter jackson\'s expanded vision of j . r . r . tolkien\'s middle-earth .', 'effective but too-tepid biopic']}
# Get rows between three and six >>> dataset[3:6] {'label': [1, 1, 1], 'text': ['if you sometimes like to go to the movies to have fun , wasabi is a good place to start .', "emerges as something rare , an issue movie that's so honest and keenly observed that it doesn't feel like one .", 'the film provides some great insight into the neurotic mindset of all comics -- even those who have reached the absolute top of the game .']}
>>> for example in iterable_dataset: ... print(example) ... break {'image': <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=384x512 at 0x7F7479DE82B0>, 'label': 6}
您可以使用IterableDataset.take()返回数据集的子集,其中包含特定数量的示例:
1 2 3 4 5 6 7 8
# Get first three examples >>> list(iterable_dataset.take(3)) [{'image': <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=384x512 at 0x7F7479DEE9D0>, 'label': 6}, {'image': <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=512x512 at 0x7F7479DE8190>, 'label': 6}, {'image': <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=512x383 at 0x7F7479DE8310>, 'label': 6}]