
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check Model Performance on StackOverflow Dataset Using TensorFlow in Python
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.