- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can Tensorflow be used to work with tf.data API and tokenizer?
The ‘tf.data’ API can be used to tokenize the strings. Tokenization is the method of breaking down a string into tokens. These tokens can be words, numbers, or punctuation.
Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?
We will use the Keras Sequential API, which is helpful in building a sequential model that is used to work with a plain stack of layers, where every layer has exactly one input tensor and one output tensor.
A neural network that contains at least one layer is known as a convolutional layer. We can use the Convolutional Neural Network to build learning model.
TensorFlow Text contains collection of text related classes and ops that can be used with TensorFlow 2.0. The TensorFlow Text can be used to preprocess sequence modelling.
We are using the 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). Colaboratory has been built on top of Jupyter Notebook.
The important interfaces include Tokenizer and TokenizerWithOffsets each of which have a single method tokenize and tokenize_with_offsets respectively. There are multiple tokenizers, each of which implement TokenizerWithOffsets (which extends the Tokenizer class). This includes an option to get byte offsets into the original string. This helps know the bytes in the original string the token was created from.
print("Tokenizer with tf.data API") docs = tf.data.Dataset.from_tensor_slices([['Never tell me about the odds.'], ["It's not trye!"]]) print("Whitespace tokenizer is being called") tokenizer = text.WhitespaceTokenizer() tokenized_docs = docs.map(lambda x: tokenizer.tokenize(x)) iterator = iter(tokenized_docs) print(next(iterator).to_list()) print(next(iterator).to_list())
Code credit −https://www.tensorflow.org/tutorials/tensorflow_text/intro
Tokenizer with tf.data API Whitespace tokenizer is being called [[b'Never', b'tell', b'me', b'about', b'the', b'odds.']] [[b"It's", b'not', b'trye!']]
- The tf.data API is used with tokenizer.
- Once this is done, the whitespace tokenizer is called on the input.
- The tokens are iterated over, and then stored in a list.
- Related Articles
- How can Tensorflow text be used with whitespace tokenizer in Python?
- How can Tensorflow be used with tf.data for finer control using Python?
- How can Tensorflow be used to work with character substring in Python?
- How can Tensorflow be used to load the flower dataset and work with it?
- How can functional API be used to work with residual connections in Python?
- How can Tensorflow be used to download the flower dataset using keras sequential API?
- How can Tensorflow be used to explore the flower dataset using keras sequential API?
- How can Tensorflow and Tensorflow text be used to tokenize string data?
- How can Tensorflow be used with Estimators to perform data transformation?
- How can Tensorflow be used with Estimators to optimize the model?
- How can Tensorflow be used with boosted trees in Python?
- How can Tensorflow be used with Estimators to create feature columns and input functions?
- How can Tensorflow text be used with UnicodeScriptTokenizer to encode the data?
- How can Tensorflow be used with Estimators to split the iris dataset?
- How can Tensorflow be used with Estimators to explore the titanic data?