How to increase the accuracy and the prediction percentage of Sequential machine learning model of tensorflow

i am creating the AI for document classification using the sequential model of tensorflow library. so i need the guidance regarding increasing the prediction percentage/accuracy of ml model.should i increase or add more data to train the model or what should i do?

Accuracy is tricky. If you have more data, always go for it, more data is always valuable.
To increase accuracy is tricky because it depends on a lot of factors, especially how much noise your data has, what type of data you have, what model you’re using and how sensitive your task is to errors. In most cases, you pick a suitable model, and train and fine-tune it to get some desired accuracy.
Assuming you’ve a model at hand, to increase accuracy you can:

  1. Make the model more powerful by using more layers
  2. Making the model deeper, as in increasing the number of neurons in hidden layers or any other layer.
  3. Try using different loss functions and accuracy measures (depending on type of data).
1 Like

Hi @pranay_huskal ,

welcome to the Forum :tada:. Assuming, you’re using text from the documents, you can further try:

  1. Fine-tune the hyperparameter in the TextVectorization Layer
    tf.keras.layers.TextVectorization  |  TensorFlow v2.16.1
    Basic text classification  |  TensorFlow Core

  2. Increase the Dimensions in the Embedding Layer
    tf.keras.layers.Embedding  |  TensorFlow v2.16.1
    Basic text classification  |  TensorFlow Core

  3. You can visualise the Text Embedding in TF Projector (Gather more insights)
    https://projector.tensorflow.org/

  4. Try different Network Architectures e.g stack more layers:
    layers.Embedding()
    layers.LSTM()++
    layers.Dense()++
    Text classification with an RNN  |  TensorFlow

  5. A good ‘benchmark’ might be to test with a pre-trained text classifier from tfhub
    Text classification with TensorFlow Hub: Movie reviews  |  TensorFlow Core

  6. Compare with one of the BERT family Text classifier how they perform (can save some time)
    Classify text with BERT  |  Text  |  TensorFlow

Feel free to provide more details or share some code of your data and network.

Looking forward,
Dennis

1 Like

Hello @Dennis ,
i am using the json data fetch from document by using the pytesseract’s image_to_data() function, that function detects the all words from document and give data that contains information of each detected words like position of word(from left, top, height, width, line_num, text, etc.). i trained the my sequential model on json data of document with two dense layers,
model = tf.keras.Sequential([
tf.keras.layers.Input(shape=(X_train.shape[1],)),
tf.keras.layers.Dense(64, activation=‘relu’),
tf.keras.layers.Dense(32, activation=‘relu’),
tf.keras.layers.Dense(len(label_encoder.classes_), activation=‘softmax’)
])
now i want to increase the prediction score of input data in my ml model.

Hi @pranay_huskal ,

the text received from the OCR, can be vectorised with tf.keras.layers.TextVectorization()

vectorize_layer = tf.keras.layers.TextVectorization(
    output_mode='int',
    ngrams=5,
    output_sequence_length=100)

vectorize_layer.adapt(X_train)

Including a Embedding Layer, the Model can look like:

voc_count = len(vectorize_layer.get_vocabulary())
emb_dim = 512

model = tf.keras.Sequential([
    vectorize_layer,
    tf.keras.layers.Embedding(voc_count, emb_dim, name='embedding'),
    tf.keras.layers.GlobalAveragePooling1D(),
    tf.keras.layers.Dense(64, activation=‘relu’),
    tf.keras.layers.Dense(32, activation=‘relu’),
    tf.keras.layers.Dense(len(label_encoder.classes_), activation='softmax')
])

Depending on the Data, you can fine-tune the hyperparameters (e.g: dimensions, ngrams, etc.)

Thanks for your response.