Running Deep QA on Google Colaboratory
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.