That’s all: by calling predict with our input functions we’re able to generate predictions on our trained Estimator model! We take the index of the highest value from this vector, and then get the text label that corresponds with this index. Predictions is now a vector with the softmax probabilities for each possible Stack Overflow tag in our dataset. Print("Predicted label: " + predicted_label + "\n") # Print out the true and expected labelfor i in range(len(examples)): Predictions = list(estimator_model.predict(input_function(examples))) # We'll make predictions for the first five examples ![]() The labels argument defaults to None since we won’t pass labels to the function when we generate a prediction using. With these parameters in mind, we can now build our input function with the following code. There are a few optional parameters, including whether or not we should shuffle the data as we feed it to our model.y: the labels for our model, in this case the correct tag for each post encoded as a one-hot vector the size of all possible tags in our model.Since we named our column “posts” above, we can reference it in our input function by the name posts_input. x is an object: the key is the name of this feature column. x: the input features to our model, in our example this is the Stack Overflow posts as a vector the size of our vocabulary.The training input function takes a few parameters: ![]() We’ll use the numpy_input_fn provided by the Estimators API in this example. Feature columns define the types of data we’re feeding into the model, and in this example we have one feature column - the bag of words vector for each post. In TensorFlow, input functions prepare data for the model by mapping raw input data to feature columns. Instead of passing our features and labels to the model directly when we run training, we need to pass it an input function. ![]() Since our model is now an Estimator, we’ll train and evaluate it a bit differently than we did in Keras. pile(loss='categorical_crossentropy',Īwesome, now we can call model_to_estimator() and we’ll be working with a TF Estimator object. Model.add((num_classes, activation='softmax', name='labels'))
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |