Giter Club home page Giter Club logo

tensorflow-machine-learning-cookbook's Introduction

TensorFlow Machine Learning Cookbook

This is the code repository for TensorFlow Machine Learning Cookbook, published by Packt. It contains all the supporting project files necessary to work through the book from start to finish.

About the book

TensorFlow is an open source software library for Machine Intelligence. The independent recipes in this book will teach you how to use TensorFlow for complex data computations and will let you dig deeper and gain more insights into your data than ever before. You’ll work through recipes on training models, model evaluation, sentiment analysis, regression analysis, clustering analysis, artificial neural networks, and deep learning – each using Google’s machine learning library TensorFlow.

This guide starts with the fundamentals of the TensorFlow library which includes variables, matrices, and various data sources. Moving ahead, you will get hands-on experience with Linear Regression techniques with TensorFlow. The next chapters cover important high-level concepts such as neural networks, CNN, RNN, and NLP.

Once you are familiar and comfortable with the TensorFlow ecosystem, the last chapter will show you how to take it to production.

Instructions and Navigations

All of the code is organized into folders. Each folder starts with a number followed by the application name. For example, Chapter 03.

The code will look like the following:

     import matplotlib.pyplot as plt
     import numpy as np
     import tensorflow as tf
     from sklearn import datasets
     from tensorflow.python.framework import ops
     ops.reset_default_graph()

Software requirements:

Python 3, with the following installed Python libraries: TensorFlow, Numpy, Scikit-Learn, Requests, and Jupyter. It is compatible in all three major operating systems, Mac, Windows, and Linux. It requires no special hardware to run the scripts.

Related Products:

Suggestions and Feedback

Click here if you have any feedback or suggestions.

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781786462169

tensorflow-machine-learning-cookbook's People

Contributors

jim8y avatar murtazatinwala avatar packt-itservice avatar packtutkarshr avatar techsachinkumar avatar vishalmewadapackt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tensorflow-machine-learning-cookbook's Issues

Error at the chapter 7 - word2vec_cbow.py

Hello?

I have been reading this book and there is some error I do not know how to solve in the chapter 7.
In word2vec_cbow.py and text_helpers.py,

I made some corrections first.

from:
loss = tf.reduce_mean(tf.nn.nce_loss(nce_weights, nce_biases, embed, y_target,
num_sampled, vocabulary_size))
to:
loss = tf.reduce_mean(tf.nn.nce_loss(weights=nce_weights, biases=nce_biases, labels=y_target,
inputs=embed, num_sampled=num_sampled, num_classes=vocabulary_size))

from:
with open(pos_file, 'r') as temp_pos_file:
for row in temp_pos_file:
pos_data.append(row)
neg_data = []
with open(neg_file, 'r') as temp_neg_file:
for row in temp_neg_file:
neg_data.append(row)

to:
with open(pos_file, 'r', encoding='ISO-8859-1', errors='ignore') as temp_pos_file:
for row in temp_pos_file:
pos_data.append(row)
neg_data = []
with open(neg_file, 'r', encoding='ISO-8859-1', errors='ignore') as temp_neg_file:
for row in temp_neg_file:
neg_data.append(row)

And this error is popping out and I don't know how to solve this:

Traceback (most recent call last):
File "word2vec_cbow.py", line 123, in
batch_inputs, batch_labels = text_helpers.generate_batch_data(text_data, batch_size, window_size, method='cbow')
File "/home/tester/libs/cookbook/Chapter 7/text_helpers.py", line 97, in generate_batch_data
batch, labels = [list(x) for x in zip(*batch_and_labels)]
ValueError: not enough values to unpack (expected 2, got 0)

Doc2Vec example does not work in TensorFlow r1.10

After fixing the text_helpers.py file to download the dataset in python3, the next error is...

Traceback (most recent call last): File "doc2vec.py", line 112, in <module> final_embed = tf.concat(1, [embed, tf.squeeze(doc_embed)]) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/array_ops.py", line 1111, in concat dtype=dtypes.int32).get_shape().assert_is_compatible_with( File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 1027, in convert_to_tensor as_ref=False) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 1123, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py", line 217, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py", line 196, in constant value, dtype=dtype, shape=shape, verify_shape=verify_shape)) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/tensor_util.py", line 442, in make_tensor_proto _AssertCompatible(values, dtype) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/tensor_util.py", line 353, in _AssertCompatible (dtype.name, repr(mismatch), type(mismatch).__name__)) TypeError: Expected int32, got list containing Tensors of type '_Message' instead.

Which I managed to fix by updating the parameters in concat from line 112 as specified for tensorflow 1.10, however, the next error I get is...

`Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py", line 510, in _apply_op_helper
preferred_dtype=default_dtype)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 1123, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 960, in _TensorTensorConversionFunction
(dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("nce_loss/Slice_1:0", shape=(250, 300), dtype=float32)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "doc2vec.py", line 116, in
num_sampled, vocabulary_size))
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/nn_impl.py", line 1246, in nce_loss
name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/nn_impl.py", line 1074, in _compute_sampled_logits
sampled_logits = math_ops.matmul(inputs, sampled_w, transpose_b=True)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/math_ops.py", line 2019, in matmul
a, b, transpose_a=transpose_a, transpose_b=transpose_b, name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_math_ops.py", line 4499, in mat_mul
name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py", line 546, in _apply_op_helper
inferred_from[input_arg.type_attr]))
TypeError: Input 'b' of 'MatMul' Op has type float32 that does not match type int32 of argument 'a'.`

Which can be "fixed" by swapping "final_embed" and "y_target" parameter places in line 115 nce_loss function, however this seems like a really non-functional hack, as the similar words shown by the algorithm are nowhere near correct.

Therefore, I would be glad to get some help here, as a doc2vec implementation on GPU is really needed. Thanks in advance!

Some question about TensorFlow-Machine-Learning-Cookbook/Chapter 05/nearest_neighbor.py

line73:distance = tf.reduce_sum(tf.abs(tf.sub(x_data_train, tf.expand_dims(x_data_test,1))), reduction_indices=2)
I dont understand this line. i think L1 norm is :
distance = tf.reduce_sum(tf.abs(tf.sub(x_data_train, x_data_test))), reduction_indices=2
your code is tf.expand_dims(x_data_test,1)instead of x_data_test,can you explain the ops that subtract
2D-tensor from 3D-tensor.thanks you very much

Question about SVM with kernels.

Hi,

I have a question about this line from the notebook named "04_svm_kernels":
sq_dists = tf.add(tf.subtract(dist, tf.multiply(2., tf.matmul(x_data, tf.transpose(x_data)))), tf.transpose(dist))

It looks too complicated than the distance required by the Gaussian Kernel.

An other question is about the prediction tensor: it accepts a batch of data as a training samples. Is not the SVM supposed to identify the Support Vector and thereby learn the relevant data points in order to make a prediction? These data points aren't they to be kept by the model from the training data set?

Thank you in advance.

tf.concat not working

On these lines, I have to send the axis parameter later, the order is different now on tensorflow=1.12.0
I think it would be better to use keyword arguments than positional arguments in these cases

final_embed = tf.concat(1, [embed, tf.squeeze(doc_embed)])

log_final_embed = tf.concat(1, [log_embed, tf.squeeze(log_doc_embed)])

Chapter2 combining_everything_together.py

Py3.6
OSX 10.13.5
tensorflow==1.8.0

Chapter2 combining_everything_together.py

Traceback (most recent call last):
  File "/Users/wyx/project/learn-sktf/tf/classifi.py", line 31, in <module>
    loss = tf.nn.sigmoid_cross_entropy_with_logits(my_output, labels=y_target)
  File "/Users/wyx/project/learn-sktf/.env/lib/python3.6/site-packages/tensorflow/python/ops/nn_impl.py", line 156, in sigmoid_cross_entropy_with_logits
    labels, logits)
  File "/Users/wyx/project/learn-sktf/.env/lib/python3.6/site-packages/tensorflow/python/ops/nn_ops.py", line 1775, in _ensure_xent_args
    "named arguments (labels=..., logits=..., ...)" % name)
ValueError: Only call `sigmoid_cross_entropy_with_logits` with named arguments (labels=..., logits=..., ...)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.