# Emotion Analysis AI Model for Sensing Architecture Using EEG
## 3 Emotion Analysis AI Model Using EEG
### Fine-Tuned Model Development and Training
#### 3.3.2 Fine-Tuned Model Training  
In the fine-tuning process, which integrates the brainwave data into the GPT model, it is important to have clear prompt naming for the training data. In this process, the structuring stage, which converts the brainwave data to a vector format, plays an important role. The converted data are inputted into the GPT model, and fine-tuning is performed so that the model can effectively classify and recognise specific emotional states. To this end, clear labels based on system messages and roles are assigned to each brainwave data point and set up so that the model can accurately classify and respond to emotional states. In this process, each of the brainwave data's channel values were used to classify the emotional states as '0 sad', '1 neutral', or '2 happy'. For example, the user-provided brainwave data sample {'FP1 -12.189149856567383, FP2 -16.15285873413086, C3 -15.556812286376953, C4 -9.626150131225586, CPZ 14.394521713256836, PZ 10.222196578979492, O1 4.649162292480469, O2 8.314847946166992'\({}^{\prime}\)) was processed and classified as '0 sad'.  
To apply fine-tuning to the GPT API, token values were calculated for text that includes the brainwave channel data and AI commands. In this process, the number of tokens was reduced by using as much English text as possible rather than Korean text to minimise the system load and reduce cost. By doing so, it was possible to effectively manage the number of tokens and perform fine-tuning at an optimised cost. The process is shown in Figure 4.  
Figure 4 illustrates how a single prompt was organised into a module such that 163 tokens constituted one fine-tuning training set, resulting in a total of 4,173,237 tokens being used in the fine-tuning process. Through this model training, the fine-tuned GPT model became capable of effectively classifying and predicting emotional states from EEG data within architectural environments. All textual data for the fine-tuning process was stored in JSONL format.  
Additionally, the attached image was not manually created by the author but was automatically generated by OpenAI's Tokenizer system to structure readable data for AI model training. This system organises text data into a structured JSON format and utilises colour coding to differentiate various elements, such as key values, data values, and emotion classification labels. This process helps the AI model efficiently analyse and process the input data.  
Figure 4: Tokenizer settings for fine tuning.  
During the model training for fine-tuning, numerous trial-and-error steps were encountered. Notably, close attention must be paid to the data format: unlike the conventional JSON format, JSON Lines (JSONL) strictly follows a line-based structure. Hence, when preparing the fine-tuning training data in JSONL format, each of the eight EEG channels must be written as an individual JSON object on a separate line, with no blank lines in between, as illustrated in Figure 4.  
Once the fine-tuning process was completed, the loss values converged nearly to zero, and, as shown in Figure 5, there was a marked increase in the accuracy of emotion predictions based on EEG data. Specifically, the final training loss was 0.1163, and the validation loss was 0.2752 (with a full validation loss of 0.2373). Although one cannot precisely determine accuracy solely from these loss values, the inverse relationship generally observed between cross-entropy loss and accuracy suggests that a validation accuracy of approximately 85-90% might be expected at this level of loss. Of course, this figure remains merely an estimate; to obtain the actual accuracy as well as metrics such as F1 score or Cohen's Kappa, one must compare the model's predictions on the validation set directly against the ground-truth labels. These points will be discussed more extensively in the following section.  
Figure 5: Fine-tuning model training results.