Tensorflow Text Classification - Python Deep Learning - Source Dexter

Join the Sourcedexter Community

https://t.me/source_dexter  Community to talk about AI, machine learning, blockchain and more!

40 Comments

  1. akshay pai
    October 13, 2017 @ 12:28 pm

    A guide to building a contextual Chatbot with tensorflow: https://chatbotsmagazine.com/contextual-chat-bots-with-tensorflow-4391749d0077

    Reply

    • Rachit
      June 22, 2018 @ 11:00 am

      same task for text classification i am trying using R can u please suggest me the code for the same…Thanks in advance

      Reply

      • akshay pai
        June 27, 2018 @ 10:17 pm

        Sorry, Rachit, I have no idea about R, so I won’t be able to help you.

        Reply

    • Rachit
      June 22, 2018 @ 11:02 am

      Even I tried the same with python but showing number of errors , i am not that much comfortable with python , can u please suggest me for R

      Reply

  2. Kai Wendt
    February 19, 2018 @ 2:09 pm

    Hey, great tutorial but is there any possibility that you append the code with the accuracy of the model.

    Reply

    • akshay pai
      May 16, 2018 @ 11:40 am

      Hey, that is a possibility, I will try to add that sometime. If you have done that already, then please do raise a PR on github.

      Reply

  3. Anders Fåk
    April 5, 2018 @ 4:57 pm

    Thanks for an excellent example.
    This got me started with text classification on my text data.

    In your sample the training and predict section is in the same python script…. How would you define and load that model for predictions in a separate standalone script?

    Reply

    • akshay pai
      May 16, 2018 @ 11:41 am

      You can save the model, using tflearn and then load it in another file. Once loaded, you can use the same methods as in this script to predict

      Reply

  4. Sean O'Keefe
    April 9, 2018 @ 6:12 am

    Love this post! I’ve been trying to figure out how to do with with TF for some time.

    Reply

  5. Senso
    April 10, 2018 @ 5:56 pm

    Most examples for NLP in TensorFlow involve labels which are already given by the developer who creates and trains the TensorFlow model. I am beginner in this field and this seems to fall under the category of supervised learning. Is this correct?

    Now I would like to have a training model with TensorFlow where I don’t give it any labels. It should classify sentences itself. There is a huge amount of data where labels are not clear. The hope is that TensorFlow finds clusters in the data which can be used for the labeling and classifying the sentences.

    Reply

    • akshay pai
      May 16, 2018 @ 11:43 am

      Yes, this most certainly falls into the supervised learning category. I haven’t worked on unsupervised learning with tensorflow yet. But i will surely update my blog when I do so.

      Reply

  6. Ramprassad
    April 18, 2018 @ 1:07 pm

    thatns for useful article. Can you try to port the same to golang?

    Reply

    • akshay pai
      May 16, 2018 @ 11:37 am

      Sorry, I am not that good at golang, If you have done it, then please do raise a pull request.

      Reply

  7. Ramprassad
    April 19, 2018 @ 7:49 pm

    i can test this as it is.

    But i can’t load saved model using tensorflow not tflearn.

    i understand that model is trained using tflearn and hence can be loaded in tflearn only.

    Please try to port this completely to tensorflow.

    Reply

  8. Prateek
    June 7, 2018 @ 8:51 pm

    Nice article. I am using this in a personal fun project. I noticed the following.

    1. There are issues while restoring model in new code , avoiding to prepare data is cumbersome task.
    2. tflearn github is almost unsupported for issues.
    3. Even though model is restored with lot of modifications, its taking 3-4 seconds to run the program which is too slow.
    4. predictions are different every time for same input (I loaded same saved model in each run without changing trained data) Is this because I added parameter restore=False on net = tflearn.fully_connected(net, 8, restore=False) to avoid shape mismatch exceptions on reloading the model?

    Reply

    • Akshay Pai
      June 7, 2018 @ 8:54 pm

      These issues that you are facing is due to the version mismatch of tensorflow or some errors with the tensors that is being formed. I am using this extensively in many places and I can assure you that the results are stable and the performance is super fast. it in milli-seconds that I get results in.

      Reply

      • Prateek
        June 7, 2018 @ 9:29 pm

        I just cloned github code of this and retested. I dont see any issue with version issue in log?

        Regarding this is slow : I have large model , with 224 labels and 1600 total sentences. tflearn restoring model with code in different program is not so easy. Even with few lines of code , we still need to have reference to `words`

        I guess one can use different stemmer , I see stemmed words look weird. How about `nltk.stem.wordnetWordNetLemmatizer`

        I just want to fix this issue of different predictions each time. I couldnt get same issue being mentioned anywhere in any blog either .

        And tflearn does not have method to update the model with new data, we have call model.fit with updated data and them model.save again which will retrain the whole model and takes a lot of time.

        Reply

        • Akshay Pai
          June 7, 2018 @ 9:33 pm

          You can certainly try the nltk.stem.wordnetWordNetLemmatizer . Even with that large dataset, I don’t think it should be an issue for the program to either run slowly or not to be stable. I will try to look at this when I shave some time.

          Reply

    • Prateek
      June 7, 2018 @ 9:19 pm

      “Output predictions vary every time with the mentioned code as well without any changes. I think this is weird.

      Reply

  9. rachit
    June 22, 2018 @ 12:16 pm

    Error importing tensorflow. Unless you are using bazel,
    you should not try to import tensorflow from its source directory;
    please exit the tensorflow source tree, and relaunch your python interpreter
    from there.

    Reply

  10. Desmond
    June 26, 2018 @ 8:33 am

    Hi, that’s a great tutorial. However, do you mind to provide more strings in the data.json? I realized that when I add more string to perform the machine learning, the accuracy went downhills.

    Reply

    • akshay pai
      June 27, 2018 @ 10:21 pm

      Could you send me the json that you are using? I feel it’s not due to more number of strings that the accuracy has gone down. I feel it might be due to the way in which you have categorized the data. Sometimes, categorization does not allow the neural network to correctly classify the input data.

      Reply

  11. John
    June 28, 2018 @ 8:45 pm

    Hello,

    I downloaded source code from your Github repo. But When I running “classify_text.py” and then it gives below error message. How can I fix it ?

    TypeError: category() argument 1 must be unicode, not str

    Reply

  12. Kornel
    July 8, 2018 @ 7:24 pm

    Hello,

    thanks for the great tutorial. I combined it with your chatbot tutorial and everything works but the prediction takes very long (20-30 seconds). I have trained the model with 3 categories with about 5000 words each category). The pickle file has 104MB. Is there a way to make the prediction faster?

    Reply

  13. Simon
    July 13, 2018 @ 10:35 pm

    Thank you for posting

    Reply

  14. Dipti Pawar
    August 1, 2018 @ 3:18 pm

    Thanks.. Nice Tutorial.

    Reply

  15. T. Hossain
    August 6, 2018 @ 12:05 am

    Hi, is it possible to share full code with library imports and stuff? Having bunch of errors trying to achieve result. much appreciated.

    Reply

    • akshay pai
      August 7, 2018 @ 10:29 pm

      Hi, at the end of the article, I have shared the link to the GitHub project from which you will get all the code. Have you checked that? Let me know if you tried it and it didn’t work.

      Reply

  16. akshay pai
    August 7, 2018 @ 10:31 pm

    Thank you very much.

    Reply

  17. Nuha
    September 3, 2018 @ 12:25 pm

    Thank You very very much you’ve helped me a lot. I faced some errors regarding missing modules but I fixed them and now it works well. I really appreciate people helping others.
    I have a question, how can I know the supported languages in the preprocessing methods? (specially Arabic Language) and thanks again

    Reply

    • akshay pai
      September 3, 2018 @ 10:45 pm

      Hello Nuha,
      I’m glad to know that this has helped you. With regards to supported languages, I haven’t tried running it with languages other than English. But if you observe, the processing uses the Unicode notations which means it can support any given language that we know (Arabic included)

      I hope that you can get it up and running for Arabic 🙂

      Reply

  18. samira
    September 18, 2018 @ 12:53 pm

    Thank you for your good scripts
    I run this script with excel file as input data and it works finely
    I want to load my model after i save it.
    how can i do it?
    thank you for your reply

    Reply

  19. Amit Gupta
    December 6, 2018 @ 10:36 am

    Hi akshay, can we use word embedding using word2vec instead of bag of words? Because if there is large corpus than there will be huge number of zeros for a sentence.

    Reply

    • akshay pai
      December 6, 2018 @ 10:42 am

      Hi Amit,

      WordToVec is designed to convert a word to a vector or a phrase to a vector. When using TF bag of words model, the same is happening internally.
      Though I haven’t used word-to-vec, I know that the existing approach is quote scalable.

      Reply

Leave a Reply

%d bloggers like this: