In this assignment you will use FairSeq, a neural network sequence-to-sequence learning tool, to build an encoder-decoder LSTM grapheme-to-phoneme engine for Icelandic.
Icelandic is written in a Roman script but the mapping from spelling to pronunciation regular but rather complex.
This repository contains three data files:
-
training data:
ice_train.tsvis a two-column TSV file in which the first column is a Icelandic word in UTF-8, and the second column gives that word's space-delimited IPA transcription in UTF-8. There are 800 training examples in all. For instance, the rowauga ø yː ɣ aindicates that auga 'eye' is pronounced [øyːɣa].
-
development data:
ice_dev.tsvis a two-column, 100-row TSV file in the same format as the previous file. -
test data:
ice_test.tsvis a two-column, 100-row TSV file in the same format as the previous two files.
First, set up your environment.
Install FairSeq:
pip install fairseq==0.10.2
Nothing for this part of the assignment.
If the above command fails with an error message reading:
Sorry, Python >= 3.6 is required for fairseq.
Then you are using an (ancient) system Python instead of Conda. Please just use Conda instead.
FairSeq requires you to "preprocess" the data into binary files that it can read
into memory rapidly during training, development, and testing. Preprocessing is
performed by the
fairseq-preprocess
command-line tool. This tool takes a series of arguments specifying the location
of the data and how it to be "tokenized" into graphemes and phones. Because this
tool makes certain assumptions about the format of your data, you will have to
first convert the aforementioned TSV and text files as follows:
-
Write the first column of
ice_train.tsvto a file calledtrain.ice.g. You must also place a space between each UTF-8 character. Thus, the rowauga ø yː ɣ awould appear in
train.ice.gasa u g a -
Write the second column of
ice_train.tsvto a file calledtrain.ice.p. The data has already been segmented with spaces so do not add additional spaces. Thus the aforementioned row would appear intrain.ice.pasø yː ɣ a -
Write the first column of
ice_dev.tsvto a file calleddev.ice.gusing the same style as you did in step 1. -
Write the second column of
ice_dev.tsvto a file calleddev.ice.pusing the same style as you did in step 2. -
Write the first column of
ice_test.tsvto a file calledtest.ice.gusing the same style as you did in steps 1 and 3. -
Write the second column of
ice_test.tsvto a file calledtest.ice.pusing the same style as you did in steps 2 and 4.
Then, call fairseq-preprocess as follows:
fairseq-preprocess \
--source-lang ice.g \
--target-lang ice.p \
--trainpref train \
--validpref dev \
--testpref test \
--tokenizer space \
--thresholdsrc 2 \
--thresholdtgt 2
- All Python code you used to prepare the data.
- The logging output from
fairseq-preprocess.
- The
\character used at the end of a lines above is a "continuation": it indicates that the current command continues on the next line. You yourself do not need to type it in at the command line. - You need to name the files exactly what I say:
fairseq-preprocessis finicky like that. - Visually inspect all six
.gand.pfiles before attempting to callfairseq-preprocess; confirm there are no blank lines and that there are spaces between grapheme and phone symbols. - Read the the
docs
for
fairseq-preprocess. - If you call
fairseq-preprocessmultiple times it may crash with aFileExistsError. If you see this error, simply remove thedata-bindirectory and try again.
Model training is performed by the
fairseq-train
command-line tool.
Using fairseq-train, train the model. You should use the following parameters:
- random seed: pick some random number
- architecture: LSTM
- bidirectional encoder
- dropout probability .2
- encoder embedding dimensionality: 128
- decoder embedding dimensionality: 128
- decoder output embedding dimensionality: 128
- encoder hidden layer size: 512
- decoder hidden layer size: 512
- criterion: label-smoothed cross-entropy
- label smoothing coefficient: .1
- optimizer: Adam
- learning rate: .001
- norm clipping coefficient: 1
- batch size: 50
- maximum number of updates: 800
- don't store epoch checkpoints
If successful, this will produce two large model files in a checkpoints
directory.
The fairseq-train command you ran.
-
You do not need to write any Python for this step; your goal here is to read the documentation carefully and figure out how to get
fairseq-trainto do what you want. -
The command will begin as follows:
fairseq-train \ data-bin \ --source-lang ice.g \ --target-lang ice.p \ ...but many more flags are required (roughly, one for each bullet point).
-
Read the docs for
fairseq-train.
Grapheme-to-phoneme conversion engines are traditionally evaluated using word
error rate (WER), which is simply the percentage of incorrectly predicted word
pronuniciations in the test set. Unfortunately, FairSeq does not provide any
tool to compute word error rate. Instead, the
fairseq-generate
command-line tool is used for inference/prediction, and this program's output
can then be processed to compute WER.
Run the following command to write the one-best prediction for each test example
to a file called predictions.txt.
fairseq-generate \
data-bin \
--source-lang ice.g \
--target-lang ice.p \
--path checkpoints/checkpoint_best.pt \
--gen-subset test \
--beam 8 \
> predictions.txt
Then, automatically process predictions.txt, a verbose (but human-readable)
text file, to compute test set WER.
- A Python script for computing WER from the
predictions.txtfile. - Your word error rate, rounded to an appropriate number of digits given the number of test examples.
- I obtained a WER of 23, but your mileage may vary somewhat.
- Since there are only 100 examples, multiply WER by 100 and round to the nearest integer. Thus WER should be some number between 0 and 100, the smaller the better.
- In this file, the gold ("target") pronunciation is indicated by line-initial
T-and the predicted ("hypothesis") pronunciation is indicated by line-initialH-. - Don't forget to turn in your WER.
- Read the
docs
for
fairseq-generate.
Please provide a brief (roughly one page) reflection on this assignment.
A brief description of the challenges and problems you ran into during this assignment.
- Run the above experiment on a GPU, such as available in the computational
linguistics lab (7400.13). Using
timeto keep track of "wall clock" time (i.e., human time), report the runtime of the CPU and GPU versions. - Tune at least two of the hyperparameters to minimize word error rate on the development set.
- Perform an error analysis along the lines proposed in section 8 of Ashby et al. 2021.
- Try an alternative sequence-to-sequence model supported by FairSeq, such as the transformer, using hyperparameters such as those proposed by Wu et al. 2021.