Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Natural Language Processing with Attention Models/Week 3 - Question Answering/C4_W3_Assignment_Ungraded_T5.ipynb
Views: 13373
Assignment 3 Ungraded Sections - Part 2: T5 SQuAD Model
Welcome to the part 2 of testing the models for this week's assignment. This time we will perform decoding using the T5 SQuAD model. In this notebook we'll perform Question Answering by providing a "Question", its "Context" and see how well we get the "Target" answer.
Colab
Since this ungraded lab takes a lot of time to run on coursera, as an alternative we have a colab prepared for you.
If you run into a page that looks similar to the one below, with the option
Open with
, this would mean you need to download theColaboratory
app. You can do so byOpen with -> Connect more apps -> in the search bar write "Colaboratory" -> install
After installation it should look like this. Click on
Open with Google Colaboratory
Part 2: Fine-tuning on SQuAD
Now let's try to fine tune on SQuAD and see what becomes of the model.For this, we need to write a function that will create and process the SQuAD tf.data.Dataset
. Below is how T5 pre-processes SQuAD dataset as a text2text example. Before we jump in, we will have to first load in the data.
2.1 Loading in the data and preprocessing
You first start by loading in the dataset. The text2text example for a SQuAD example looks like:
The squad pre-processing function takes in the dataset and processes it using the sentencePiece vocabulary you have seen above. It generates the features from the vocab and encodes the string features. It takes on question, context, and answer, and returns "question: Q context: C" as input and "A" as target.
Run the cell below to decode.
Note: This will take some time to run
You should also be aware that the quality of the decoding is not very good because max_length was downsized from 10 to 5 so that this runs faster within this environment. The colab version uses the original max_length so check that one for the actual decoding.