Fine tuning is a technique employed to a base fully trained model (foundation) and to retraining/ repurposing it to meet some different objective(s). The key aspect of fine tuning being that it is not a complete/ full retraining of the base model. It's done on a much smaller training budget keeping the weights of the original model intact, and bringing in a much smaller additional set of trainable weights known as adapters.
These adapter weights are typically of Low Rank matrices thus the name LoRA (Low Rank Adapters). With every round of training only these LoRA weights get updated which the weights from the base model stay frozen. Since final weights are additive so the corresponding fine trained LoRA model equation:
output = f(W_base*x + b_base + B*A*x), where for any given input x
W_base, b_base: Base model weights & bias which remain fixed
B, A: Low Rank Adapter weights of a small rank (r), which are trained during fine tuning
f: Activation Function
In the example TextClassificationFineTuningLora.py the working of the LoRA adapter for fine tuning a Text Classification model is demonstrated.
Fine Tuning Objective
- The base model is a Sentiment Classifier on the Imdb database which labels data as either 1 (Positive) or 0 (Negative).
- The base model is repurposed as a Exaggeration detector that labels the data as either 1 (Has-Exaggerations) or 0 (No Exaggerations).
- Exaggerations are any reviews containing the exaggerations defined in: TextClassificationTorchUtilities.exaggerations. Also see: TextClassificationTorchUtilities.buildExaggerationDataset().
Fine Tuning Details
- The base model had 2.67 Mn total parameters of which 8.86 Lakh paramters were trainable. For fine tuning these 8.86 Lakh parameters are all frozen.
- The LoRA model is employed to every trainable layer of the base model. Each trainable layer of the base model is set to enable_lora(rank=4). This results in total trainable parameters of just ~30.6K.
- After fine tuning the model is able to identify Exaggerations with an accuracy in the high 90's.
No comments:
Post a Comment