1 Star 0 Fork 1

WhiteCloudTemple / PythonProgramming

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
004.md 3.84 KB
一键复制 编辑 原始数据 按行查看 历史
WhiteCloudTemple 提交于 2020-03-31 11:15 . Update tensorflow 004.md

TensorFlow 练习题 004

Hands-on Machine Learning with Scikit-Learn, Keras & TensorFlow 2nd Edition 第十三章课后练习题
中文翻译请参考本书第一版

chapter 4 Exercises

  1. Why would you want to use the Data API?

  2. What are the benefits of splitting a large dataset into multiple files?

  3. During training, how can you tell that your input pipeline is the bottleneck? What can you do to fix it?

  4. Can you save any binary data to a TFRecord file, or only serialized protocol buffers?

  5. Why would you go through the hassle of converting all your data to the Example protobuf format? Why not use your own protobuf definition?

  6. When using TFRecords, when would you want to activate compression? Why not do it systematically?

  7. Data can be preprocessed directly when writing the data files, or within the tf.data pipeline, or in preprocessing layers within your model, or using TF Transform. Can you list a few pros and cons of each option?

  8. Name a few common techniques you can use to encode categorical features. What about text?

  9. Load the Fashion MNIST dataset (introduced in Chapter 10); split it into a training set, a validation set, and a test set; shuffle the training set; and save each dataset to multiple TFRecord files. Each record should be a serialized Example protobuf with two features: the serialized image (use tf.io.serialize_tensor() to serialize each image), and the label. Then use tf.data to create an efficient dataset for each set. Finally, use a Keras model to train these datasets, including a preprocessing layer to standardize each input feature. Try to make the input pipeline as efficient as possible, using TensorBoard to visualize profiling data.

  10. In this exercise you will download a dataset, split it, create a tf.data.Dataset to load it and preprocess it efficiently, then build and train a binary classification model containing an Embedding layer:

    • Download the Large Movie Review Dataset, which contains 50,000 movies reviews from the Internet Movie Database. The data is organized in two directories, train and test, each containing a pos subdirectory with 12,500 positive reviews and a neg subdirectory with 12,500 negative reviews. Each review is stored in a separate text file. There are other files and folders (including preprocessed bag-of-words), but we will ignore them in this exercise.
    • Split the test set into a validation set (15,000) and a test set (10,000).
    • Use tf.data to create an efficient dataset for each set.
    • Create a binary classification model, using a TextVectorization layer to preprocess each review. If the TextVectorization layer is not yet available (or if you like a challenge), try to create your own custom preprocessing layer: you can use the functions in the tf.strings package, for example lower() to make everything lowercase, regex_replace() to replace punctuation with spaces, and split() to split words on spaces. You should use a lookup table to output word indices, which must be prepared in the adapt() method.
    • Add an Embedding layer and compute the mean embedding for each review, multiplied by the square root of the number of words (see Chapter 16). This rescaled mean embedding can then be passed to the rest of your model.
    • Train the model and see what accuracy you get. Try to optimize your pipelines to make training as fast as possible.
    • Use TFDS to load the same dataset more easily: tfds.load("imdb_reviews").

打卡模版

ID:

链接:
Python
1
https://gitee.com/white-cloud-temple/pp.git
git@gitee.com:white-cloud-temple/pp.git
white-cloud-temple
pp
PythonProgramming
master

搜索帮助