## Appendix A Appendix A
### Training a Fine-Tuned BERT  
There are several libraries and methods to fine-tune a pretrained BERT model. We use functions from the Hugging Face transformers library to demonstrate the process of training a fine-tuned BERT model. Just as we loaded the _bert-base-uncased_ model for fine-tuning, a user can load the fine-tuned model for further pretraining for classification tasks. The fine-tuned BERT model, when saved, has the following files in a single folder, which we named \"fine-tuned-BERT\":  
* _config.json_ has the BERT-base-uncased architecture and configuration of the model, saved in JavaScript Object Notation (JSON). * _pytorch_model.bin_ is the model in a binary file format. * _special_tokens_map.json_ has the [CLS], [SEP], and more special tokens stored as JSON. * _tokenizer.json_ consists of the tokenizer information, as well as the indices of the tokens in the vocabulary. * _tokenizer_config.json_ has the tokenizer configuration of the fine-tuned BERT model. * _training_args.bin_ is a binary file of the training arguments used while training the model. * _vocab.txt_ consists of all the words in the BERT-base vocabulary in a text file. Below, we describe the process of loading the model for further training/fine-tuning on new data. The programs were written in Python, and the models are stored as PyTorch models that accept PyTorch tensors:  
1. Data Preprocessing The first step is to prepare the data. Based on the task, a user may choose to preprocess their data, as we describe in Section 3.4. For further fine tuning of BERT, a user may have fewer or more classes than what the model was previously trained to predict. The utterances need to be in text (not tokens) and stored in the first column of a CSV file with the header \"text\". The labels should be encoded to be represented as unique integers. For example, if your labels are 'positive', 'negative' or 'neutral', you can encode the labels as 'positive': 0, 'negative': 1, 'neutral': 2. The encoded label for each corresponding utterance should be in the second column of the CSV file with the header 'label'. The training and testing data are to be separated into a _training.csv_ file and a _testing.csv_ file, and the columns in both files should have the same headers \"text\" and \"label\" (see Figure 11). Note that the training data can be further split into a training and validation set for evaluation of models during training, which is especially useful for early stopping. In the program, the CSV files are loaded using the _load_dataset()_ function of the Python _datasets_ library. _train_data = load_dataset('csv', 'train': 'training.csv')_  
For tokenization and feature extraction, we use the _BERTFastTokenizer_ from the _transformers_ library, which has a _from_pretrained()_ function that loads the saved tokenizer in fine-tuned BERT. The function takes the model name as an argument or the nameof the folder where the fine-tuned BERT model files are stored, i.e., fine-tuned-BERT. The second parameter is _do_lower_case = True_, which internally converts the text to lowercase if it is not already. Below is the line of code to load the tokenizer. _tokenizer = BERTFastTokenizer,frompretrained('fine-tuned-BERT',do_lower_case = True)_ Once loaded, the dataset is tokenized one sample at a time, where the tokenizer accepts a few arguments: _padding_ = [True, False], _truncation = [True, False], _max_length =_ integer value. For example, to make all samples a fixed length, we can set _padding_ to True; if the sentences are very long (greater than 512 tokens), we can set _truncation_ to True; or if we want each sequence to be of a specific length, e.g., 32 tokens, then we can set _max_length_ to that value. The preprocess function passed each sample in the _train_data_ and returns the tokenized data. _predrocess_(samples): return _tokenizer(samples['text'], padding = True) _tokenized_train_data = train_data.map(preprocess)_ Once the training and testing sets have been tokenized, we move on to the model. 2.