Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Artificial Vision and Language Processing for Robotics

You're reading from   Artificial Vision and Language Processing for Robotics Create end-to-end systems that can power robots with artificial vision and deep learning techniques

Arrow left icon
Product type Paperback
Published in Apr 2019
Publisher Packt
ISBN-13 9781838552268
Length 356 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (3):
Arrow left icon
Gonzalo Molina Gallego Gonzalo Molina Gallego
Author Profile Icon Gonzalo Molina Gallego
Gonzalo Molina Gallego
Unai Garay Maestre Unai Garay Maestre
Author Profile Icon Unai Garay Maestre
Unai Garay Maestre
Álvaro Morena Alberola Álvaro Morena Alberola
Author Profile Icon Álvaro Morena Alberola
Álvaro Morena Alberola
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Artificial Vision and Language Processing for Robotics
Preface
1. Fundamentals of Robotics FREE CHAPTER 2. Introduction to Computer Vision 3. Fundamentals of Natural Language Processing 4. Neural Networks with NLP 5. Convolutional Neural Networks for Computer Vision 6. Robot Operating System (ROS) 7. Build a Text-Based Dialogue System (Chatbot) 8. Object Recognition to Guide a Robot Using CNNs 9. Computer Vision for Robotics Appendix

Chapter 7: Build a Text-Based Dialogue System (Chatbot)


Activity 7: Create a Conversational Agent to Control a Robot

Solution

  1. Open up your Google Colab interface.

  2. Create a folder for the book and download the utils, responses, and training folder from Github and upload it in the folder.

  3. Import drive and mount it as follows:

    from google.colab import drive
    drive.mount('/content/drive')

    Note

    Every time you use a new collaborator, mount the drive to the desired folder.

  4. Once you have mounted your drive for the first time, you will need to enter the authorization code mentioned by clicking on the URL mentioned by Google and press the Enter key on your keyboard:

    Figure 7.28: Image displaying the Google Colab authorization step

  5. Now that you have mounted the drive, you need to set the path of the directory.

    cd /content/drive/My Drive/C13550/Lesson07/Activity01

    Note

    The path mentioned in step 5 may change as per your folder setup on Google Drive. The path will always begin with cd /content/drive/My Drive/

  6. Import the chatbot_intro file:

    from chatbot_intro import *
  7. Define the GloVe model:

    filename = '../utils/glove.6B.50d.txt.word2vec'
    model = KeyedVectors.load_word2vec_format(filename, binary=False)
  8. List the responses and training sentences files:

    intent_route = 'training/'
    response_route = 'responses/'
    intents = listdir(intent_route)
    responses = listdir(response_route)
    
    print("Documents: ", intents)

    Figure 7.29: A list of intent documents

  9. Create document vectors:

    doc_vectors = np.empty((0,50), dtype='f')
    for i in intents:
        with open(intent_route + i) as f:
            sentences = f.readlines()
        sentences = [x.strip() for x in sentences]
        sentences = pre_processing(sentences)
    doc_vectors= np.append(doc_vectors,doc_vector(sentences,model),axis=0)
    
    print("Shape of doc_vectors:",doc_vectors.shape)
    print(" Vector representation of backward.txt:\n",doc_vectors)

    7.30: Shape of doc_vectors

  10. Predict the intent:

    user_sentence = "Look to the right"
    
    user_sentence = pre_processing([user_sentence])
    user_vector = doc_vector(user_sentence,model).reshape(100,)
    intent = intents[select_intent(user_vector, doc_vectors)]
    intent

    7.31: Predicted intent

Congratulations! You finished the activity. You can add more intents if you want to and train the GloVe model to achieve better results. By creating a function with all the code, you programmed and developing a movement node in ROS, you can order your robot to make movements and turn around.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image