中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

谷歌開源機器學習數(shù)據(jù)集,可在TensorFlow直接調用

2019-03-01    來源:raincent

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

 

吳恩達說過,公共數(shù)據(jù)集為機器學習研究這枚火箭提供了動力,但將這些數(shù)據(jù)集放入機器學習管道就已經(jīng)夠難的了。編寫供下載的一次性腳本,準備他們要用的源格式和復雜性不一的數(shù)據(jù)集,相信這種痛苦每個程序員都有過切身體會。

但現(xiàn)在,你再也不會被這種痛苦困擾了。谷歌今天開源了一個機器學習數(shù)據(jù)集,可在 TensorFlow 直接調用,這為開發(fā)人員省去了不少麻煩。

照例先放數(shù)據(jù)集:

GitHub:https://github.com/tensorflow/datasets

今天,我們很高興地推出 TensorFlow 數(shù)據(jù)集,它將作為tf.data.Datasets和 NumPy 數(shù)組向公眾開放。它可以完成從獲取源數(shù)據(jù),到準備磁盤上的通用格式的所有瑣碎工作,并使用tf.data API構建高性能輸入管道,這些管道支持 TensorFlow 2.0,并可與 tf.keras 模型一起使用。我們推出了 29 個流行的研究數(shù)據(jù)集,如 MNIST、Street View House Numbers、包含 10 億數(shù)據(jù)的語言模型基準和大型電影評論數(shù)據(jù)集,并將在未來幾個月推出更多數(shù)據(jù)集;我們也希望你可以加入并貢獻數(shù)據(jù)集。

tl;dr

# Install: pip install tensorflow-datasets
import tensorflow_datasets as tfds
mnist_data = tfds.load("mnist")
mnist_train, mnist_test = mnist_data["train"], mnist_data["test"]
assert isinstance(mnist_train, tf.data.Dataset)

在 Colab notebook 上試試 tfds。

tfds.load和DatasetBuilder

每個數(shù)據(jù)集都作為 DatasetBuilder 公開,它會告訴你:

從哪里下載數(shù)據(jù)以及如何提取數(shù)據(jù)并將其寫入標準格式(DatasetBuilder.download_and_prepare)。

如何從磁盤加載它(DatasetBuilder.as_dataset)。

以及有關數(shù)據(jù)集的所有信息,例如所有要素的名稱、類型和形狀,每個拆分中的記錄數(shù)、源 URL、數(shù)據(jù)集或相關論文的引用等(DatasetBuilder.info)。

你可以直接對所有 DatasetBuilders 進行實例化或使用 tfds.builder 字符串獲。

import tensorflow_datasets as tfds

# Fetch the dataset directly
mnist = tfds.image.MNIST()
# or by string name
mnist = tfds.builder('mnist')

# Describe the dataset with DatasetInfo
assert mnist.info.features['image'].shape == (28, 28, 1)
assert mnist.info.features['label'].num_classes == 10
assert mnist.info.splits['train'].num_examples == 60000

# Download the data, prepare it, and write it to disk
mnist.download_and_prepare()

# Load data from disk as tf.data.Datasets
datasets = mnist.as_dataset()
train_dataset, test_dataset = datasets['train'], datasets['test']
assert isinstance(train_dataset, tf.data.Dataset)

# And convert the Dataset to NumPy arrays if you'd like
for example in tfds.as_numpy(train_dataset):
image, label = example['image'], example['label']
assert isinstance(image, np.array)

as_dataset()接受一個 batch_size 參數(shù),它將提供批量示例,而不是一次一個示例。對于適合內存的小型數(shù)據(jù)集,你可以用 batch_size = -1 立即獲取整個數(shù)據(jù)集作為 tf.Tensor。使用tfds.as_numpy()可以輕松地將所有 tf.data.Datasets 轉換為 NumPy 數(shù)組的參數(shù)。

為方便起見,你可以使用tfds.load執(zhí)行以上所有操作,tfds.load 按名稱獲取 DatasetBuilder,調用 download_and_prepare()以及 as_dataset()。

import tensorflow_datasets as tfds

datasets = tfds.load("mnist")
train_dataset, test_dataset = datasets["train"], datasets["test"]
assert isinstance(train_dataset, tf.data.Dataset)

你也可以通過傳遞 with_info = True 輕松地從 tfds.load 獲取DatasetInfo 對象。有關所有選項,請參閱API 文檔。

數(shù)據(jù)集版本管理

每個數(shù)據(jù)集都是版本化的(builder.info.version),你大可放心,數(shù)據(jù)不會隨意發(fā)生變化,且結果是可重現(xiàn)的。目前,我們保證如果數(shù)據(jù)發(fā)生變化,將增加版本。

請注意,盡管目前我們保證給定同一版本下的數(shù)據(jù)值和拆分是相同的,但不保證對同一版本的記錄進行排序。

數(shù)據(jù)集配置

具有不同變體的數(shù)據(jù)集使用命名的 BuilderConfigs 進行配置。例如,大型電影評論數(shù)據(jù)集 (tfds.text.IMDBReviews ) 不同的輸入可能有不同的編碼(例如,純文本、字符編碼或子詞編碼)。內置配置與數(shù)據(jù)集文檔一起列出,可以通過字符串進行尋址,也可以傳入你自己的配置。

# See the built-in configs
configs = tfds.text.IMDBReviews.builder_configs
assert "bytes" in configs

# Address a built-in config with tfds.builder
imdb = tfds.builder("imdb_reviews/bytes")
# or when constructing the builder directly
imdb = tfds.text.IMDBReviews(config="bytes")
# or use your own custom configuration
my_encoder = tfds.features.text.ByteTextEncoder(additional_tokens=['hello'])
my_config = tfds.text.IMDBReviewsConfig(
name="my_config",
version="1.0.0",
text_encoder_config=tfds.features.text.TextEncoderConfig(encoder=my_encoder),
)
imdb = tfds.text.IMDBReviews(config=my_config)

請參閱有關添加數(shù)據(jù)集的文檔中有關數(shù)據(jù)集配置的部分。

文本數(shù)據(jù)集和詞匯表

由于編碼和詞匯文件不同,文本數(shù)據(jù)集通常很難處理。tensorflow-datasets 讓這一過程變得更簡單。它包含許多文本任務,包括三種 TextEncoders,且都支持 Unicode:

ByteTextEncoder 用于字節(jié) / 字符級編碼

TokenTextEncoder 用于基于詞匯表文件的單詞級編碼

SubwordTextEncoder 用于子詞級編碼(以及針對特定文本語料庫創(chuàng)建子詞詞匯的能力),可以字節(jié)級回退,因此它是完全可逆的。例如,“hello world”可以拆分為 [“he”,“llo”,“”,“wor”,“ld”],然后進行整數(shù)編碼。子詞是詞級和字節(jié)級編碼之間的媒介,在一些自然語言研究項目中很受歡迎。

可以通過 DatasetInfo 訪問編碼器及其詞匯表大。

imdb = tfds.builder("imdb_reviews/subwords8k")

# Get the TextEncoder from DatasetInfo
encoder = imdb.info.features["text"].encoder
assert isinstance(encoder, tfds.features.text.SubwordTextEncoder)

# Encode, decode
ids = encoder.encode("Hello world")
assert encoder.decode(ids) == "Hello world"

# Get the vocabulary size
vocab_size = encoder.vocab_size

TensorFlow 和 TensorFlow 數(shù)據(jù)集都將在未來進一步改進文本支持。

入門

我們的文檔站點是開始使用 tensorflow 數(shù)據(jù)集的最佳位置。以下是一些入門指南:

數(shù)據(jù)集頁面

API 文檔

Colab 教程

如何添加數(shù)據(jù)集

GitHub

我們將在未來幾個月內添加更多數(shù)據(jù)集,并希望社區(qū)能夠加入。如果你需要什么數(shù)據(jù)集,請在 GitHub 創(chuàng)建話題,我們將對下一步應添加的數(shù)據(jù)集進行投票,討論實施細節(jié)或尋求幫助。非常歡迎 Pull Requests!人人獻出一點數(shù)據(jù)集,讓社區(qū)變得更美好,把你的數(shù)據(jù)集貢獻給 TFDS 聲名大噪吧!

當獲取數(shù)據(jù)變得簡單,我們就能快樂地建模!

原文鏈接:

https://medium.com/tensorflow/introducing-tensorflow-datasets-c7f01f7e19f3

標簽: 谷歌 腳本

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:大數(shù)據(jù)分析陷阱與Simpson’s Paradox(辛普森悖論)

下一篇:大數(shù)據(jù)正在遭遇成長的煩惱