Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Running Deep QA on Google Colaboratory

Tech May 8 4

Deep QA Overview

The project aims to replicate the architecture described in A Neural Conversational Model (the Google chatbot). It implements a sequence-to-sequence Recurrent Neural Network (RNN) for generating conversational responses. The implementation utilizes Python and TensorFlow.

Setting Up Google Colaboratory

Refer to: Using Google Colaboratory

Note: Accessing Colaboratory from China may require specific methods.

To begin, log into Google Drive and select "New" followed by "More" and then "Connect more apps" (already connected in this case).

Search for "Colaboratory" in the app list and connect it.

After successful connection, launch Colaboratory from Drive. Click "Edit" -> "Notebook settings", choose "GPU", and save the setting.

Click the triangle icon next to "Connect" to establish a runtime connection.

Uploading Folders to Google Drive

Use "New" -> "Upload folder" to transfer files.

Connecting to Google Drive

Execute the following commands in a notebook cell:

!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}

Click the generated link to authenticate and authorize access. Then mount the drive:

!mkdir -p drive
!google-drive-ocamlfuse drive

List contnets of the mounted drive with:

!ls drive/

Running the Code

By default, Colaboratroy runs TensorFlow 2.x, which causes compatibility issues with older scripts. Switch to version 1.x:

%tensorflow_version 1.10.0

The script expects data files in the root directory. To adjust for Colaboratory, modify chatbot/chatbot.py at line 152:

self.args.rootDir = os.getcwd() + '/drive/DeepQA-master'  #for colab run
#self.args.rootDir = os.getcwd()

Download required NLTK data:

import nltk
nltk.download('punkt')

Train the model (approx. 2 hours):

!python3 drive/DeepQA-master/main.py

Test the model:

!python3 drive/DeepQA-master/main.py --test

Results will appear in save/model/samples_predictions.txt.

For interactive testing:

!python3 drive/DeepQA-master/main.py --test interactive

Troubleshooting

E: Package 'python-software-properties' has no installation candidate

If you encounter this error during drive mounting, execute:

sudo apt-get install python-software-properties

Colaboratory Disconnection

While not severely disruptive, occasional disconnections can occur. Regular interaction keeps the session alive. Some users have found solutions to maintain persistent connections.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.