如何用Python下载和探索Iliad数据集
Tensorflow是一个免费的开源机器学习和人工智能库,广泛流行于训练和部署神经网络。它是由谷歌大脑团队开发的,支持广泛的平台。在本教程中,我们将学习下载、加载和探索著名的Iliad数据集。
在《伊利亚特》数据集中,有各种不同的荷马《伊利亚特》文本的英文翻译作品。Tensorflow对这些文件进行了修改,以关注其作品的例子。该数据集可在以下网址获得。
https://storage.googleapis.com/download.tensorflow.org/data/illiad/
例子 。在下面的例子中,我们将以三位译者的作品命名。William Cowper, Edward, Earl of Derb, and Samuel Butler。然后在TensorFlow的帮助下,我们将加载他们,并将他们的作品与他们的翻译进行分类。
安装TensorFlow文本包:
下载并加载Iliad数据集
我们需要对每个数据集进行单独标注,因此我们使用Dataset.map函数。这将返回例子-标签对。
输出:
[
,
,
]
对数据集进行串联和洗牌。使用Dataset.concatenate函数对其进行连接。shuffle函数用来洗数据。然后我们打印出一些例子。
输出:
Sentence: b”Of brass, and color’d with a ring of gold.”
Label: 0
Sentence: b’drove the horses in among the others.’
Label: 2
Sentence: b’Into the boundless ether. Reaching soon’
Label: 0
Sentence: b”Drive to the ships, for pain weigh’d down his soul.”
Label: 1
Sentence: b”Not one is station’d to protect the camp.”
Label: 1