How can Tensorflow be used to check how well the model performs on stackoverflow question dataset using Python?

PythonServer Side ProgrammingProgramming

Tensorflow is a machine learning framework that is provided by Google. It is an open-source framework used in conjunction with Python to implement algorithms, deep learning applications, and much more. It is used in research and for production purposes.

The ‘tensorflow’ package can be installed on Windows using the below line of code −

pip install tensorflow

Tensor is a data structure used in TensorFlow. It helps connect edges in a flow diagram. This flow diagram is known as the ‘Data flow graph’. Tensors are nothing but a multidimensional array or a list.

We are using Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code over the browser and requires zero configuration and free access to GPUs (Graphical Processing Units). Collaboratory has been built on top of Jupyter Notebook.

Example

Following is the code snippet −

print("Testing the model with new data")
inputs = [
   "how do I extract keys from a dict into a list?",
   "debug public static void main(string[] args) {...}",
]
print("Predicting the scores ")
predicted_scores = export_model.predict(inputs)
print("Predicting the labels")
predicted_labels = get_string_labels(predicted_scores)
for input, label in zip(inputs, predicted_labels):
   print("Question is: ", input)
   print("The predicted label is : ", label.numpy())

Code credit − https://www.tensorflow.org/tutorials/load_data/text

Output

Testing the model with new data
Predicting the scores
Predicting the labels
Question is: how do I extract keys from a dict into a list?
The predicted label is : b'python'
Question is: debug public static void main(string[] args) {...}
The predicted label is : b'java'

Explanation

  • When the text preprocessing code is present inside the model, it helps export the model for production.

  • This way, the deployment is simplified.

  • When the ‘TextVectorization’ is used outside the model, it helps perform asynchronous CPU processing and buffering.

raja
Published on 19-Jan-2021 07:39:16
Advertisements