single-jc.php

JACIII Vol.30 No.5 pp. 1404-1416
(2026)

Research Paper:

LLM Prompt Optimization: From Zero-Shot to Automatic Role-Playing Generation Using Ontology

Asyafa Ditra Al Hauna* ORCID Icon, Siti Khomsah** ORCID Icon, Andi Prademon Yunus*,† ORCID Icon, and Masanori Fukui*** ORCID Icon

*Informatics Engineering Study Program, Telkom University
Jl. DI Panjaitan No.128, Karangreja, Purwokerto Kidul, Kecamatan, Purwokerto Selatan, Kabupaten Banyumas, Jawa Tengah 53147, Indonesia

Corresponding author

**Data Science Study Program, Telkom University
Jl. DI Panjaitan No.128, Karangreja, Purwokerto Kidul, Kecamatan, Purwokerto Selatan, Kabupaten Banyumas, Jawa Tengah 53147, Indonesia

***Department of Information Engineering, Mie University
1577 Kurimamachiya-cho, Tsu, Mie 514-8507, Japan

Received:
October 7, 2025
Accepted:
March 31, 2026
Published:
September 20, 2026
Keywords:
large language models optimization, ontology, role-play prompting, recurrent neural network, graph convolutional network
Abstract

The performance of an LLM application is highly dependent on how the user commands the application through prompts. Previous researchers invented role-play prompting techniques to overcome these problems. Including roles relevant to the task can improve the accuracy of the responses generated by LLMs. Nevertheless, the assignment of roles in this study remained a human-driven process. This study addresses the research gap in previous studies by developing deep learning models to effectively predict relevant roles based on tasks. In addition, the impact of the ontology data as an enrichment of the training data on the model performance in two scenarios (with and without ontology) was examined. In the with-ontology setup, enrichment data are extracted from an occupational ontology that includes roles, skills, and abilities along with their corresponding definitions. Data that were restricted to four predefined occupations were incorporated into the benchmark datasets. The benchmark datasets consisted of questions used to assess the LLM performance aligned with predetermined occupations. In without-ontology settings, the models were trained using only the benchmark datasets. An experiment on three variants of recurrent-based and a graph-based model in both scenarios showed that these models exhibited stable convergence and performed best on ontology-enriched data. Notably, the recurrent neural network (RNN) exhibited significant performance gains, achieving improvements of 34% and 1.86% in the F1 score and receiver operating characteristic-area under the curve (ROC–AUC), respectively. Despite its great performance—92% F1 score and 97% ROC–AUC, the gated recurrent unit is computationally the most expensive model compared to long short-term memory, RNN, and graph convolutional network. Further research is required to explore alternative model architectures and expand the scope of their predictable roles.

Automatic role-play prompt generation with ontology

Automatic role-play prompt generation with ontology

Cite this article as:
A. Hauna, S. Khomsah, A. Yunus, and M. Fukui, “LLM Prompt Optimization: From Zero-Shot to Automatic Role-Playing Generation Using Ontology,” J. Adv. Comput. Intell. Intell. Inform., Vol.30 No.5, pp. 1404-1416, 2026.
Data files:

1. Introduction

In natural language processing, large language models (LLMs) represent a major breakthrough that enables a wide range of artificial intelligence applications. These models are trained on extensive datasets, facilitating human-machine interaction through natural language. This capability is supported by the underlying architecture of the LLM builder, which effectively generalizes and interprets human commands across various tasks through prompts 1. Some LLMs are designed to support human tasks by training them on diverse datasets and customizing them to exhibit balanced reasoning across various knowledge domains 2, Llama 3, Bard 4, and ChatGPT 5, which are notable examples of advanced LLMs that assist humans in problem solving. Not bound to universal capabilities, LLMs can be customized to answer problems in a specific domain by fine-tuning to enhance specialized knowledge. Some applications of these methods have resulted in the specialized focus of Bloomberg GPT in the financial field and Med-PaLM in the medical field 6,7. The increased capabilities of LLMs are accompanied by the growing trust of their users. However, users often fail to effectively convey their instructions to LLMs, resulting in inappropriate responses 8. Since LLMs are fundamentally based on mathematical modelling, the cognitive ability of LLM must be guided to increase the probability of obtaining high-accuracy responses. This iterative process of guiding the LLM reasoning involves users going back and forth, refining prompts to obtain the desired response 1. In response to this issue, numerous studies have been conducted to address it. One promising area of research focuses on the use of role-play prompts. This prompt-writing approach incorporates roles relevant to the task. Research 9 has demonstrated that this method can enhance the LLM reasoning ability across multiple aspects based on benchmark evaluations. On the AQuA benchmark, the performance increased from 53.5% to 63.5%, and on the Last Letter task, it improved from 23.8% to 84.2%. However, the role assignment in this study remains manual, highlighting the potential for automated role prediction. In this study, we propose deep learning models that predict roles based on tasks. The developed models enabled the prediction of four classes: mathematicians, education teachers, recorders, and nurses. The models were trained using a combination of training data from the benchmark and ontology datasets. The impact of training data enriched with ontology data was also examined. Occupation ontology (OccO), as a source of ontology, was selected for its relevant role information, its standardization under the international standard classification of occupations, and its organized conceptual structure 10. The results of this study represent the initial steps towards the application of an automated role-play prompting technique.

2. Literature Review

LLM discovery encompasses all tasks that can potentially be addressed by LLMs and is currently being explored. Nevertheless, LLM recalibration for personalized capability requires high computational cost owing to fine-tuning, a process in which pre-trained LLMs with universal capabilities in various domains are recalibrated to possess improved knowledge and aptitude for downstream tasks. However, this approach is constrained by available resources, as LLMs require multiple GPU memory resources during training compared to inference 11. This challenge opens up opportunities for alternative LLM optimization methods, where model recalibration is avoided and prompt optimization is performed 8. In 12, a prompt optimization method called black-box prompt optimization (BPO) was proposed. This method focuses on aligning user-provided prompts with inputs that can be effectively interpreted by LLMs. The application of BPO improved ChatGPT’s response performance by 22% compared with the original prompt. Inspired by the iterative process of prompt adjustment performed by users to obtain desired responses, Ref. 2 proposed an automatic prompt engineer (APE), a method to generate and select the best prompt that leads to a high-accuracy response by combining LLM and Monte Carlo search (MCS). APE experiments demonstrate that prompts generated by APE yield high-quality results comparable to handcrafted prompts. In 8, PromptAgent was introduced as a method that aims to outperform APE. PromptAgent leverages the Monte Carlo tree search (MCTS) method to surpass APE. MCTS is utilized to guide prompt exploration through a strategic planning approach while integrating domain knowledge. Performance comparisons show that PromptAgent exceeds APE on benchmark tasks such as BigBench Hard and general natural language understanding. While BPO, APE, and PromptAgent focus on prompt optimization and prompt exploration, the study 9 highlights the potential of role-play prompting techniques. The study proved that this technique enables LLMs, such as Llama 2, Vicuna, and ChatGPT, to enhance their standard abilities. LLM optimization involving role-play was further investigated in 13. This research established RoIE prompting guided multi-domain adaptation (REGA) to address the decline in predefined LLM capabilities following fine-tuning on domain-specific downstream tasks. REGA consists of three strategies—self-distillation, role prompting, and role integration—to preserve predefined LLM capabilities while integrating new knowledge from fine-tuning. These strategies are designed to address catastrophic forgetting and inter-domain confusion while enabling automatic generation of role-based prompts during fine-tuning. To tackle the same challenge as REGA, Ref. 14 proposed OntoTune, a fine-tuning framework supported by ontology. OntoTune was developed for the medical domain using SNOMED CT\(^{®}\) as a standardized and continuously maintained ontology data source. OntoTune allows LLMs to patch knowledge deficiencies in certain domains while retaining the designated functionality. The transformer architecture, as the fundamental building block of LLM, enables the learning of knowledge rooted in various domains, while addressing long-term dependency issues owing to the fixed memory and sequential processing of recurrent neural network (RNN)-based models. Similarly, the training process accelerates the self-attention mechanism, which allows the entire token to be processed in parallel 15. In addition, each learned token has access to the entire sequence, thereby effectively capturing the global context. Despite their superior performance over RNN-based models, transformers require significantly more resources because of their self-attention behavior, whose time complexity scales quadratically with sequence length 16. To overcome this limitation, Ref. 17 proposed receptance weighted key value (RWKV). The RWKV model integrates characteristics of RNNs and transformers. RWKV can be trained in parallel-like transformers and performs RNN-like inference with linear time complexity. Experiments on the RWKV architecture showed that the performance of RWKV models with 14 billion parameters achieve performance comparable to that of transformer models of the same size. The introduction of the RWKV architecture revealed the potential for developing RNN-based LLMs capable of operating with linear time complexity. In 18, two models, Eagle and Finch, were introduced as extensions of the foundational RWKV model. These models were trained on a multilingual dataset comprising 1.12 trillion tokens. In the specific benchmark evaluations, the performances of both models exceeded that of transformer-based LLM models.

4. Preliminaries

We designed a research flow for this study based on Fig. 4 to inspect how ontology affects predetermined models and to discover the performance of predefined models. Ontology data extraction and benchmark dataset investigation are the first steps in this study. Models are trained and tested using data prepared during the data preprocessing, feature extraction, and separate exclusive data handling for distinct models, such as graph data creation for GCN and padding sequences for recurrent-based models. Details of the stages are explained in the following subsection.

figure

Fig. 4. Research workflow.

4.1. Dataset

In line with the model development in this study, the model predicts four roles based on various benchmark datasets: MultiArith 25, AQuA 26, AddSub 27, BigBench Date Understanding (BDU) 28, StrategyQA 29, CommonsenseQA (CsQA) 30, Big-Bench Tracking-Shuffled-Objects (BTSO) 28, and MedQA 31. In addition, the ontology data from OccO were extracted using SPARQL queries, as OccO is represented in the web ontology language format. The extracted datasets comprised definitions of roles, skills, and abilities. These components were consolidated into a unified dataset yielding 13 data points (role definition, six skills, and six abilities) for each role derived from the ontology. Table 1 presents a detailed breakdown of the dataset quantities, while Table 2 illustrates the augmentation of the extracted data. The skills and abilities were unified by concatenating their names with their definitions using a space character. For instance, a skill named “active learning” is followed by a space and a skill definition. This approach was implemented to streamline the subsequent data pre-processing stage.

4.2. Data Preprocessing

Based on the results of the data exploration at this stage, several elements in the data samples were eliminated and data transformation was performed. The elimination process targeted data containing numbers, dates, names, punctuation, and stopwords. This approach ensured that the model focuses on the learning patterns of important words representing relevant roles. Text data transformations, such as case folding and lemmatization, were applied to obtain words with lowercase characters and their root forms, eliminating prefixes and suffixes. The final step of this stage involved data annotation for the four predefined roles in both ontology and non-ontology scenarios. All ontology data were associated with the corresponding labels. Consequently, there were 13 labeled ontology data points per role.

Table 1. Dataset quantities.
Data Number of samples Usage
MultiArith 370 train
AQuA 370 train
BDU 369 train
StrategyQA 370 train
BTSO (3-objects) 740 train
MedQA 740 train
OccO 52 train
BDU 100 test
AddSub 100 test
CsQA 100 test
BTSO (7-objects) 100 test
MedQA 100 test
Table 2. OccO-based mathematician ontology data.
Features Information
Conduct research in fundamental mathematics or in application of mathematical methods to science, management, and other fields. Solve problems in various domains using mathematical methods. Role definition
Active learning involving the understanding of the implications of new information for current and future problem-solving and decision-making. A skill name
+
definition
Complex problem solving involving the identification of complex problems and the evaluation of related information to develop and implement solutions. An ability name
+
definition

4.3. RNN-Based Models Feature Extraction

At this stage, words in the sample data were transformed into vectors using pre-trained GloVe word embeddings containing 400k vocabulary 32. The specific GloVe model used has a dimensionality of 100. Since the three models developed are RNN-based, an embedding matrix containing the features of each word is required. This embedding matrix enables the model to learn from text data through an embedding layer.

The initial step involved calculating word occurrences in the dataset. Let \(D = \{d_1, d_2,\dots, d_n\}\) be a set of documents, where each document \(d_i\) is a sequence of words \(d_i = \{w_1, w_2,\dots, w_m\}\). The word frequency function \(f(w)\) defined in Eq. (14) computes the number of occurrences of word \((w)\) across the entire dataset. Here, \(d_{i,j}\) denotes the \(i\)-th word in the \(j\)-th document, and the Kronecker delta function used in Eq. (14) is defined in Eq. (15).

\begin{align} \label{eq:eq14} f(w) &= \displaystyle\sum\limits_{i=1}^{n} \displaystyle\sum\limits_{j=1}^{m} \delta\left(w, d_{i,j}\right), \tag{14} \end{align}
\begin{align} \label{eq:eq15} \delta\left(w, d_{i,j}\right) &= \begin{cases} 1 & \text{if } w = d_{i,j}, \\ 0 & \text{otherwise}. \end{cases} \tag{15} \end{align}

The second step involved mapping of words to integer indices, denoted by \(\varphi\): \(W \to N\), where \(W\) is the set of all unique words and \(N\) is the set of integers. The function \(\varphi(w)\) assigns a unique index to each word based on its frequency, starting with the <PAD> token initialized to 0, followed by the vocabulary in the data. The <PAD> token is used to handle documents that have fewer words than the longest document in the dataset.

\begin{equation} \label{eq:eq16} E[\varphi(w)] = \begin{cases} \textit{glove}(w) & \text{if } w \in \textit{glove}, \\ 0_{d} & \text{if } w \notin \textit{glove}. \end{cases} \tag{16} \end{equation}

The third step was the construction of an embedding matrix using word features extracted from GloVe. Let \(E\) denote the embedding matrix with dimensions \(V \times d\), where \(V\) is the vocabulary size, and \(d\) is the embedding dimension. Each row of this matrix corresponds to the feature vector of a word in the vocabulary and is represented in \(\mathbb{R}^d\), denoted as \(e_w\) for word \(w\). Words not represented by a vector in GloVe are assigned a zero vector of dimension \(d\). The embedding for each word \(w\) in the embedding matrix \(E\) is defined as shown in Eq. (16).

The final step was to prepare the data to fit the RNN-based model input, which requires sequential data. Sequential data were obtained by converting the text into a list of indices. The function \(\varphi(w)\) resolved the issue by assigning the same unique index, allowing the resulting indices to match the word embeddings contained in \(E\). The documents were labeled according to their origins, as summarized in Table 1. Consequently, there were four distinct labels across the documents.

4.4. Graph Data Creation

This phase is exclusive to the GCN and GraphConv models, which require input data in the form of graphs. The cleaned text data are converted into graphs through three substages: data feasibility checking, text-to-graph transformation, and embedding assignment, as well as labeling.

Data feasibility checking: Each document in the corpus was checked to determine whether it was one word in length. The purpose of this process is to avoid the existence of a trivial graph, that is, a graph that possesses only one node. A trivial graph cannot represent co-occurrence relationships between words. Thus, we identified a potential issue when removing documents that contained only a single word.

Text-to-graph transformation: We employed this transformation using the text2graphapi state-of-the-art Python API, which streamlines text into a graph transformation. The primary operations involved were the co-occurrence matrix, window technique, and adjacency matrix. These operations were applied to each document to establish the local context relationships of the words within the graph-structured data. The co-occurrence matrix \(M \in \mathbb{R}^{|V|\times|V|}\) for each document in the corpus \(D = \{d_1, d_2,\dots, d_n\}\) contains \(M_{i,j}\) entries, each representing the number of context words \(v_j\) appearing within a window of the target word \(v_i\). Vocabulary denoted as \(D = \{v_1, v_2,\dots, v_m\}\) is a set of unique words in a document. If each document \(d_i = \{w_1, w_2,\dots, w_T\}\) contains a given word \(w_t\) where \(w_t \in V\), the entry \(M_{i,j}\) is defined by Eq. (17). The expression calculates the co-occurrence of context words \(v_j\) occurring within the context window \(C(w_t)\) of a target word \(w_t\). As shown in Eq. (18), it defines the context words within a window of radius \(c\) around a target word to include a set of words up to \(c\) positions to the right and left of \(w_t\), where \(w_t\) in \(1 \leq t \leq T_{j}\). We selected \(c\) as 2 to preserve the local context and bonds.

\begin{align} M_{i,j} &= \displaystyle\sum\limits_{t=1}^{T} \mathbf{1}\left(w_t = v_i\right) \left( \displaystyle\sum\limits_{u \in C\left(w_t\right)} \mathbf{1}\left(u = v_j\right) \right), \label{eq:eq17} \tag{17} \end{align}
\begin{align} C\left(w_t\right) &= \{w_{t-j} \mid 1 \leq j \leq c \} \cup\{w_{t+j} \mid 1 \leq j \leq c \}. \label{eq:eq18} \tag{18} \end{align}

Once the co-occurrence matrix was obtained, each entry was mapped to \(M\) by \(A_{i,j}\) forming an adjacency matrix \(A\). The ultimate goal is to derive an adjacency matrix to represent graph data in an undirected and unweighted manner. Consequently, the maximum number of occurrences of the context word surrounding the target word was one. An undirected, unweighted graph was selected to ensure that the model focused on learning the local context of the target word bidirectionally, without interference from word-context weighting. The resulting adjacency matrix represents word linkages, with binary values zero or one indicating the presence or absence of a word-to-word relationship.

\begin{align} \label{eq:eq19} A_{i,j} &= \mathbf{1}\left(M_{i,j} + M_{j,i} > 0\right), \tag{19} \end{align}
\begin{align} \label{eq:eq20} e\left(w_t\right) &= \begin{cases} \mathrm{GloVe}\left(w_t\right) \in \mathbb{R}^d & \text{if } w_t \in \mathrm{GloVe}, \\ 0_d & \text{if } w_t \notin \mathrm{GloVe}. \end{cases} \tag{20} \end{align}

Word-embedding assignments and labeling: At this stage, the embedding of each word is traced using GloVe. If the embedding of a word is found, a 100-dimensional vector is assigned. Otherwise, zero vector \(z\in\mathbb{R}^{100}\) is assigned. The word-embedding trace is defined in Eq. (20). Suppose \(e\) is the embedding of a word \(w_t\) in a document \(d_i\). The data labeling for the document is similar to that described in the previous section, based on document origin, as shown in Table 1.

4.5. Padding Sequences

RNN-based models require fixed-length inputs. However, the documents in our dataset vary significantly in length. We addressed this discrepancy using sequence padding, a preprocessing step that standardizes all sequences to a uniform length for efficient batch processing. This involves truncating longer sequences or padding shorter sequences with zeros until they match a predetermined size. This value is set according to the maximum document length. Sequences shorter than this threshold were extended by zero-padding, whereas those exceeding it were truncated to the specified length.

4.6. Evaluation

Our study used a multiclass confusion matrix to evaluate the model’s performance in predicting each label, and the receiver operating characteristic-area under the curve (ROC–AUC) was used as an additional metric to assess the model performance across all classification thresholds.

\begin{align} \text{Precision} &= \dfrac{\mathrm{TP}}{\mathrm{TP} + \mathrm{FP}}, \label{eq:eq21} \tag{21} \end{align}
\begin{align} \text{Recall} &= \dfrac{\mathrm{TP}}{\mathrm{TP} + \mathrm{FN}}, \label{eq:eq22} \tag{22} \end{align}
\begin{align} \text{F1 measure} &= 2 \times \dfrac{\text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}}, \label{eq:eq23} \tag{23} \end{align}
\begin{align} \text{Accuracy} &= \dfrac{\mathrm{TP} + \mathrm{TN}}{\mathrm{TP} + \mathrm{FP} + \mathrm{TN} + \mathrm{FN}}. \label{eq:eq24} \tag{24} \end{align}

Because our dataset is approximately balanced, we selected macro-averaged precision (Eq. (21)), recall (Eq. (22)), and F1 measure (Eq. (23)). We calculated the classifier’s overall correctness in Eq. (24) to measure accuracy. A true positive (TP) is the number of correctly predicted positive classes. A false positive (FP) occurs when an instance that does not belong to a class is incorrectly predicted as belonging to that class. False negatives (FN) are positive instances incorrectly predicted as other classes, and true negatives (TN) refer to correctly predicted instances of the negative class.

4.7. Experimental Setup

Table 3. Optuna search configuration.
Models Hidden Layers Dropout Learning
layers probability rate
GCN \([64, 256]\) \(1\) \([0.2, 0.5]\) \([1\mathrm{e}^{-5},1\mathrm{e}^{-3}]\)
RNN \([64, 512]\) \(1\) \([0.1, 0.5]\) \([1\mathrm{e}^{-5},1\mathrm{e}^{-2}]\)
LSTM \([16, 256]\) \([1,3]\) \([0.1, 0.5]\) \([1\mathrm{e}^{-4},1\mathrm{e}^{-2}]\)
GRU \([16, 256]\) \([1,3]\) \([0.1, 0.5]\) \([1\mathrm{e}^{-4},1\mathrm{e}^{-2}]\)

We performed hyperparameter tuning using Optuna. This is a framework for optimizing hyperparameter search. The primary targets are listed in Table 3. They were combined within a specified range during training and evaluated on models trained using a combination of data from benchmark and ontology datasets. Once the best hyperparameter was found, it was used to assess the impact of ontology on the model’s learning process. We designed experiments in which the models were trained using ontology-enriched and ontology-absent data. The learning rate was explored on a logarithmic scale. To automatically stop unpromising trials early during the hyperparameter optimization, we employed a MedianPruner, conducting 100 trials with a maximum of 150 epochs per trial.

\begin{equation} \label{eq:eq25} \mathrm{CE} = -\dfrac{1}{K} \displaystyle\sum\limits_{j=1}^{K} y_j \log \left( \hat{f}_j(x) \right), \tag{25} \end{equation}

We assessed the impact of ontology involvement in the model development by comparing the two scenarios, as shown in Table 4. In the training phase, we set the number of model epochs to 300 based on the results of hyperparameter search results recorded in the log. The categorical cross-entropy (CE) loss function is shown in Eq. (25), where \(K\) represents the total number of classes, \(y_j\) is the true label for \(j\)-th class, and \(\hat{f}_j\left(x\right)\) is the predicted probability for the \(j\)-th class given input \(x\). The Adam optimizer was used to optimize the model weights in the learning process. In addition, the embedding layer of each model was frozen to prevent overfitting.

Table 4. Best hyperparameter configurations.
Models Hidden Layers Dropout Learning
layers probability rate
GCN \(250\) \(1\) \(2.01\times{10}^{-1}\) \(8.691\times{10}^{-4}\)
RNN \(329\) \(1\) \(3.43\times{10}^{-1}\) \(3.248\times{10}^{-5}\)
LSTM \(186\) \(1\) \(4.14\times{10}^{-1}\) \(5.306\times{10}^{-3}\)
GRU \(181\) \(2\) \(1.41\times{10}^{-1}\) \(4.606\times{10}^{-3}\)

5. Results

5.1. Feature Extraction for RNN-Based Model

Following the research workflow, we determined that the maximum sequence length of the dataset from training and testing was 151. Accordingly, the documents shorter than 151 words were padded with zeros in the padding sequences according to the difference in length. We identified 7,526 unique words in both the training and test sets. We used GloVe with a 100-dimensional vector to convert the words into vectors based on their unique global representations. In the GloVe corpus, which contains a vocabulary of 400k words, 6,507 of the 7,526 words are embedded as vectors, while the remaining 1,019 were out-of-vocabulary (OOV). In this case, OOV words were embedded as zero vectors; thus, their vector representations were considered void. Consequently, the embedding matrix has dimensions \(\textrm{7,526} \times 100\), corresponding to 7,526 words, with each word represented by a 100-dimensional vector.

5.2. Graph Data Creation

figure

Fig. 5. Distribution of nodes across documents.

We analyzed the constructed graph data to gain insights into the distribution of nodes as building blocks of the documents. Furthermore, imbalances in the data distribution may contribute to poor model performance. Based on 3,411 graphs, from the training and test sets, the distribution of nodes with respect to document count, as shown in Fig. 5, is right-skewed. This was typically caused by the relationship mean \(>\) median \(>\) mode, with the scores \(22.57\), 14, and \(0.97\), respectively. The number of nodes within the range of 0 to 151 exhibited a high relative distribution, indicated by a standard deviation score close to the mean, which was \(21.8\). Despite the presence of outliers in Fig. 5, we retained them as they did not significantly impact knowledge acquisition during training. The OOV aspects and the number of available word embeddings were consistent with those described in the previous section.

5.3. Best Configuration

Regarding the hyperparameters tuned using Optuna, the best-performing hyperparameter logs are listed in Table 4 for each documented model. The recorded hyperparameters were tested under two scenarios, resulting in the model performance described in the following subsection.

5.4. Model Convergence and Performance

As shown in Fig. 6, the RNN demonstrated the most rapid convergence among the recurrence-based models, attaining stability at 110 epochs, whereas the LSTM and GRU required 220 and 200 epochs, respectively. The presence of the ontology affected the convergence of the models, as the loss record during training in the ontology-involved training setting fluctuated more than that in the ontology-excluding setting. GRU was the most impervious among the recurrence-based models. However, as in the GNN-based models, the GCN converges at smaller epochs, suggesting a more robust capability because the plots across the training settings are congruent. The performances of the models listed in Table 5 support these phenomena by comparing the performances of the GCN and recurrence-based models. Recurrence-based models, particularly RNN, experienced a significant decrease in performance when the ontology was excluded.

figure

Fig. 6. Model training and convergences.

Table 5. Performance of models.
Models With ontology Without ontology
Precision Recall Accuracy F1 measure Precision Recall Accuracy F1 measure
GCN 0.88 0.88 0.88 0.87 0.88 0.87 0.87 0.87
RNN 0.79 0.77 0.77 0.77 0.39 0.49 0.49 0.43
LSTM 0.92 0.92 0.92 0.91 0.84 0.84 0.84 0.84
GRU 0.92 0.92 0.92 0.92 0.86 0.86 0.86 0.86

The baseline RNN model achieved an accuracy of \(0.77\) and an AUC of \(0.89\) once the ontology was injected, representing a significant increase from the previous values of \(0.49\) and \(0.87\). Conversely, the LSTM and GRU models demonstrated superior performance, attaining an accuracy of \(0.92\) with respective AUC values of \(0.96\) and \(0.97\). This represents an accuracy increase of 8% and 6% for the LSTM and GRU models, respectively, and an AUC increase of 1% and 2%, respectively. The GCN achieved a lower performance than the GRU in the ontology training setting. Regarding the convergence plot, the GCN attained a stable performance across the training settings by yielding a performance gap of only \(0.01\).

This case also occurred with the false positive rate value against the true positive rate value of the model, as shown in Fig. 7, where the RNN scored the lowest AUC compared to the other models in any setting. From a holistic perspective, ontology-void training yielded models with lower AUC. However, the difference in the AUC based on the training settings was not significant. At a fine-grained level, the classifier’s performance across the four classes is illustrated in Fig. 8. The RNN trained without ontology information was unable to classify samples belonging to the recorder class. The LSTM and GRU perfectly classified the samples belonging to the recorder and nurse classes in both settings. Ultimately, all models encountered similar challenges when predicting mathematician and education teacher classes; however, the GCN performed better than the recurrence-based models.

figure

Fig. 7. ROC–AUC of models.

figure

Fig. 8. Confusion matrix.

5.5. Model Complexity

We examined model complexity using multiply-accumulates (MACs) and floating-point operations (FLOPs) to assess the computational cost. The number of hidden and architectural layers affects the complexity of the models, as documented in Table 6. The GRU exhibits the highest complexity, compared with the RNN and LSTM models. This result is attributed to the optimal GRU configuration, which used 181 hidden layers and two architecture layers. Both the RNN and LSTM have the same number of architecture layers, which is one to perform optimally; however, the RNN has more hidden layers than the LSTM. Although the RNN has more hidden layers than the LSTM, the LSTM model is more computationally expensive due to its more complex architecture, which includes gating mechanisms absent in the RNN. The GCN with the best hyperparameter configuration, using 250 hidden units in a single layer, is the most computationally efficient and possesses a simpler architecture than recurrent-based models.

Table 6. Models complexity.
Models MACs FLOPs Parameters
GCN 687.01 kMac 1374.02 kFlops 26.25k
RNN 21.46 MMac 42.92 MFlops 143.12k
LSTM 32.64 MMac 65.28 MFlops 215.02k
GRU 53.43 MMac 106.86 MFlops 352.05k

6. Discussions

Table 7. Test samples incorrectly predicted by the LSTM model without ontology integration.
Test samples Roles
Sandy grew 6 carrots. Sam grew 3 carrots. How many carrots did they grow in total? Mathematician
Fred grew 38 cantelopes. Tim grew 44 cantelopes. How many cantelopes did they grow in total? Mathematician
Sara grew 4 onions, Sally grew 5 onions, and Fred grew 9 onions. How many onions did they grow in all? Mathematician
In which group of people’s homes will usually have a grocery store? Education teacher
The bat needed to go back to the benched players, and where did it go? Education teacher
If one picked many flowers to display, what would they put them in? Education teacher

Different model configurations and behaviors lead to different convergence speeds for each model. Based on the training curves in Fig. 6, which plot the loss value against the epochs, all models exhibited similar trends across scenarios. This indicates that the presence or absence of an ontology has a significant impact on model convergence particularly for recurrence-based models. Furthermore, according to the model performance shown in Table 5, the models trained on ontology-enriched data exhibited improved performance. This is because the ontology data, which contain detailed information about roles, enhance the generalization ability of the models. The ontology significantly impacts the RNN model, where the F1 score reaches \(0.77\) when ontology information is included, but its performance degrades by more than \(0.30\) when it is excluded. This effect is observed in the GRU and LSTM models, but is less significant than in the RNN. As shown in Table 7, the LSTM model yielded incorrect predictions for the two classes (mathematicians and education teachers). However, these specific samples were successfully predicted using the LSTM model after the integration of the ontology. The GCN model consistently demonstrated a stable performance, exhibiting minimal degradation in precision and F1 score. Notably, its recall and accuracy scores decreased by only \(0.01\) across both training configurations. The hypothesis that using ontology data to enrich training data improves model performance has been proven to be correct. Another advantage of using data from an ontology is that improved performance can be achieved without increasing model complexity, as incorporating detailed information naturally enhances the results. In this case, detailed role related information derived from OccO including roles, skills, abilities, and their definitions, was effectively captured and interpreted by the model, thereby improving classifier performance.

The analysis of the confusion matrix presented in Fig. 8 reveals that both ontology-inclusive and ontology-exclusive models encountered consistent difficulties in accurately classifying samples belonging to the mathematician and education teacher classes. This challenge arises because some words in the mathematics class sample overlap with those in the education-teacher class. Therefore, models that learn the features of both samples have difficulty in distinguishing them. OOV is another factor contributing to these challenges due to the limitations of GloVe, which only has 400k vocabulary and can only perform feature extraction at the word level, not at the character level.

Based on the overall performance, the LSTM and GRU surpassed the RNN. This proves that, according to previous studies 33, an RNN is not able to learn long-sequence data well, which in this case is 151. The promising performance results of the LSTM and GRU can be considered for model selection when developing a framework for prompt generation with automated role-play techniques that allow for black-box optimization of the LLM. An additional consideration for the LSTM and GRU models is their complexity. The LSTM model is considered computationally more efficient because it has lower complexity than the GRU model; however, it is capable of matching the performance of the GRU. In addition, the GCN emerges as the optimal choice if applications demand a model that performs reliably across both ontology-involved and ontology-excluded settings. However, the results recorded in this study cannot confirm whether the same experimental setup performs similarly if this study includes more data, and if the number of target classes for model classification is greater than four. Therefore, it is necessary to reexplore Optuna by considering a new model configuration.

7. Ablation Study

We conducted a dedicated study to examine whether the proposed feature extraction method provided greater support to the models than features derived directly from an LLM. The experimental workflow followed the procedure illustrated in Fig. 4. The data preprocessing stage was omitted because of the advanced tokenization mechanism of the selected language model, which can handle raw input text. We employed a DistilBERT-based uncased architecture as an encoder-only LLM to generate LLM-derived word embeddings. The data were embedded at the word rather than sentence level to ensure architectural consistency with the original models. This consideration allowed the resulting features to be directly integrated without modifying the model structures. Consequently, the dimensionality of each word embedding increased to 768 compared to the 100-dimensional embeddings obtained using GloVe, leading to a corresponding change in the input feature size for the GCN, RNN, LSTM, and GRU models, while maintaining all other configurations unchanged. The investigation was conducted in an ontology-enriched data setting with identical model parameters, numbers of epochs, optimizer settings, and maximum token lengths. DistilBERT-base-uncased employs subword-level tokenization, that is, a single word can be represented by multiple embedding vectors. This poses a challenge for the GCN model, which requires a single-vector representation per node. To address this, mean pooling was applied to aggregate multiple vectors into a single representation with the goal of enabling each node in the graph-based data to be associated with unified word embedding.

Table 8 presents a performance comparison of the models trained with the proposed 100-dimensional feature extraction and the models trained with 768-dimensional LLM-derived features under the ontology-enriched data setting. This trend was most evident in the LSTM and GRU models. In contrast, GCN models trained using LLM-derived features did not exhibit effective learning behavior because their performance was substantially lower than that of the GCN models trained with the proposed feature extraction. Experimentally, we found that the GCN exhibited a lack of convergence because the training loss remained largely unchanged. The RNN models attained an F1 score of \(0.61\) when trained with LLM-derived features. The score decreased by approximately 16% compared with the corresponding model trained with the proposed feature extraction method. The LSTM and GRU models benefited from LLM-derived features. LSTM exhibited an improvement of 3% in accuracy and 4% in the F1 score, whereas GRU achieved a gain of 2% in both the metrics. Overall, the use of LLM-derived features with higher-dimensional vector embeddings requires the reconstruction of the model architecture. This requirement is particularly evident in the GCN and RNN models, which are less robust than the GRU and LSTM models.

Table 8. Performance comparison of models under an ontology-enhanced setup using proposed feature extraction versus LLM-derived features.
Models Proposed LLM-derived
Precision Recall Accuracy F1 measure Precision Recall Accuracy F1 measure
GCN 0.88 0.88 0.88 0.87 0.06 0.25 0.25 0.10
RNN 0.79 0.77 0.77 0.77 0.58 0.69 0.69 0.61
LSTM 0.92 0.92 0.92 0.91 0.96 0.95 0.95 0.95
GRU 0.92 0.92 0.92 0.92 0.95 0.95 0.94 0.94

8. Conclusions

This study utilized three recurrent variants and GNN-based models to address the research gap shown in a previous study 9, where role determination in the prompt used to test the LLM was performed manually. The developed models were trained using ontology data from the OccO to enrich the training data and enable the models to capture patterns relevant to the four roles: mathematicians, education teachers, recorders, and nurses. Two scenarios were tested on each model to exemplify the effect of ontology data on model performance using two metrics: confusion matrix and ROC–AUC. The experimental results showed that all the models achieved their highest performance in the scenario where the training data were enriched by an ontology. Performance evaluation revealed distinct capabilities across the recurrent architectures. The baseline RNN model demonstrated an accuracy of \(0.77\) and an AUC of \(0.89\). In contrast, the LSTM and GRU models exhibited superior performance, achieving an accuracy of \(0.92\) with AUC values of \(0.96\) and \(0.97\), respectively. These findings highlight the potential utility of these advanced RNN variants for LLM-prompt optimization applications utilizing role-play methodologies. Furthermore, the GCN model, characterized by its computational efficiency and comparable stability, warrants consideration for implementation despite exhibiting a slightly lower performance ceiling than the LSTM and GRU models.

Despite these excellent results, the following limitations must be considered. The word-embedding process employed in this study employs GloVe, which means that words without representation (out-of-vocabulary) are handled by assigning them a vector of zero. This elevates the possibility of essential features in the data that are relevant to the role; however, eschew representation in GloVe is overlooked. In addition, this study did not reveal the performance of the RNN variant models in bidirectional mode. We suggest either augmenting or adding more data and incorporating a broader predefined set of roles to enhance the ability of the models to predict more representative roles pertinent to a given prompt.

The proposed models are intended to function as intermediate components within the LLM workflow, facilitating the identification of the most appropriate role for a given prompt. Future research might focus on character-level embedding methods to overcome out-of-vocabulary problems and thus enable more maximized feature extraction to address the limitations outlined. Additionally, future research might also explore the performance of RNN, LSTM, and GRU in the bidirectional mode and transformer models by extending the training and ontology data to ensure that the predicted roles exceeded four. We highlight the potential for further exploration of GNN-based models, encouraging future work to incorporate directed and weighted graph-constructed data. This would allow the capture of semantic weights and contextual word positioning relative to target words, extending beyond the limitations of local context analysis.

References
  1. [1] A. Bhargava, C. Witkowski, S.-Z. Looi, and M. Thomson, “What’s the Magic Word? A Control Theory of LLM Prompting,” arXiv preprint, arXiv:2310.04444, 2023. https://doi.org/10.48550/arXiv.2310.04444
  2. [2] Y. Zhou, A. I. Muresanu, Z. Han, K. Paster, S. Pitis, H. Chan, and J. Ba, “Large Language Models Are Human-Level Prompt Engineers,” 11th Int. Conf. on Learning Representations, 2022. https://doi.org/10.48550/arXiv.2211.01910
  3. [3] H. Touvron, T. Lavril, G. Izacard, X. Martinet, M.-A. Lachaux, T. Lacroix, B. Rozière, N. Goyal, E. Hambro, F. Azhar et al., “LLaMA: Open and Efficient Foundation Language Models,” arXiv preprint, arXiv:2302.13971, 2023.
  4. [4] S. K. Singh, S. Kumar, and P. S. Mehra, “Chat GPT & Google Bard AI: A Review,” 2023 Int. Conf. on IoT, Communication and Automation Technology (ICICAT), 2023. https://doi.org/10.1109/ICICAT57735.2023.10263706
  5. [5] J. Achiam, S. Adler, S. Agarwal, L. Ahmad, I. Akkaya, F. L. Aleman, D. Almeida, J. Altenschmidt, S. Altman, S. Anadkat et al., “GPT-4 Technical Report,” arXiv preprint, arXiv:2303.08774, 2023. https://doi.org/10.48550/arXiv.2303.08774
  6. [6] S. Wu, O. Irsoy, S. Lu, V. Dabravolski, M. Dredze, S. Gehrmann, P. Kambadur, D. Rosenberg, and G. Mann, “BloombergGPT: A Large Language Model for Finance,” arXiv preprint, arXiv:2303.17564, 2023. https://doi.org/10.48550/arXiv.2303.17564
  7. [7] K. Singhal, T. Tu, J. Gottweis, R. Sayres, E. Wulczyn, M. Amin, L. Hou, K. Clark, S. R. Pfohl, H. Cole-Lewis et al., “Toward expert-level medical question answering with large language models,” Nature Medicine, Vol.31, No.3, pp. 943-950, 2025. https://doi.org/10.1038/s41591-024-03423-7
  8. [8] X. Wang, C. Li, Z. Wang, F. Bai, H. Luo, J. Zhang, N. Jojic, E. P. Xing, and Z. Hu, “PromptAgent: Strategic Planning with Language Models Enables Expert-level Prompt Optimization,” arXiv preprint, arXiv:2310.16427, 2023. https://doi.org/10.48550/arXiv.2310.16427
  9. [9] A. Kong, S. Zhao, H. Chen, Q. Li, Y. Qin, R. Sun, X. Zhou, E. Wang, and X. Dong, “Better Zero-Shot Reasoning with Role-Play Prompting,” Proc. of the 2024 Conf. of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Vol.1: Long Papers), pp. 4099-4113, 2024. https://doi.org/10.18653/v1/2024.naacl-long.228
  10. [10] J. Beverley, S. Smith, M. A. Diller, W. D. Duncan, J. Zheng, J. W. Judkins, W. R. Hogan, R. McGill, D. Dooley, and Y. He, “The Occupational Ontology (OccO): Building a Bridge between Global Occupational Standards,” OSS2023: Ontologies for Services and Society, 9th Joint Ontology Workshops (JOWO 2023), 2023. https://doi.org/10.2139/ssrn.5345722
  11. [11] L. Zhang, B. Li, K. K. Thekumparampil, S. Oh, and N. He, “DPZero: Private Fine-Tuning of Language Models without Backpropagation,” arXiv preprint, arXiv:2310.09639, 2023. https://doi.org/10.48550/arXiv.2310.09639
  12. [12] J. Cheng, X. Liu, K. Zheng, P. Ke, H. Wang, Y. Dong, J. Tang, and M. Huang, “Black-Box Prompt Optimization: Aligning Large Language Models without Model Training,” Proc. of the 62nd Annual Meeting of the Association for Computational Linguistics (Vol.1: Long Papers), pp. 3201-3219, 2024. https://doi.org/10.18653/v1/2024.acl-long.176
  13. [13] R. Wang, F. Mi, Y. Chen, B. Xue, H. Wang, Q. Zhu, K.-F. Wong, and R. Xu, “Role Prompting Guided Domain Adaptation with General Capability Preserve for Large Language Models,” Findings of the Association for Computational Linguistics: NAACL 2024, pp. 2243-2255, 2024. https://doi.org/10.18653/v1/2024.findings-naacl.145
  14. [14] Z. Liu, C. Gan, J. Wang, Y. Zhang, Z. Bo, M. Sun, H. Chen, and W. Zhang, “OntoTune: Ontology-Driven Self-training for Aligning Large Language Models,” Proc. of the ACM on Web Conf. 2025, pp. 119-133, 2025. https://doi.org/10.1145/3696410.3714816
  15. [15] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin, “Attention is All You Need,” Advances in Neural Information Processing Systems, Vol.30, 2017.
  16. [16] F. D. Keles, P. M. Wijewardena, and C. Hegde, “On The Computational Complexity of Self-Attention,” Proc. of the 34th Int. Conf. on Algorithmic Learning Theory, Vol.201, pp. 597-619, 2023.
  17. [17] B. Peng, E. Alcaide, Q. Anthony, A. Albalak, S. Arcadinho, S. Biderman, H. Cao, X. Cheng, M. Chung, L. Derczynski et al., “RWKV: Reinventing RNNs for the Transformer Era,” Findings of the Association for Computational Linguistics: EMNLP 2023, pp. 14048-14077, 2023. https://doi.org/10.18653/v1/2023.findings-emnlp.936
  18. [18] B. Peng, D. Goldstein, Q. Anthony, A. Albalak, E. Alcaide, S. Biderman, E. Cheah, X. Du, T. Ferdinan, H. Hou et al., “Eagle and Finch: RWKV with Matrix-Valued States and Dynamic Recurrence,” arXiv preprint, arXiv:2404.05892, 2024. https://doi.org/10.48550/arXiv.2404.05892
  19. [19] T. N. Kipf and M. Welling, “Semi-Supervised Classification with Graph Convolutional Networks,” arXiv preprint, arXiv:1609.02907, 2016. https://doi.org/10.48550/arXiv.1609.02907
  20. [20] A. Hikmah, S. Adi, and M. Sulistiyono, “The Best Parameter Tuning on RNN Layers for Indonesian Text Classification,” 2020 3rd Int. Seminar on Research of Information Technology and Intelligent Systems (ISRITI), pp. 94-99, 2020. https://doi.org/10.1109/ISRITI51436.2020.9315425
  21. [21] X. Chen, K. Hirota, Y. Dai, and Z. Jia, “Estimation of SOC Based on LSTM-RNN and Design of Intelligent Equalization Charging System,” J. Adv. Comput. Intell. Intell. Inform., Vol.24, No.7, pp. 855-863, 2020. https://doi.org/10.20965/jaciii.2020.p0855
  22. [22] S. Hochreiter and J. Schmidhuber, “Long Short-Term Memory,” Neural Computation, Vol.9, Issue 8, pp. 1735-1780, 1997. https://doi.org/10.1162/neco.1997.9.8.1735
  23. [23] H. Asrawi, A. Sunyoto, and B. Setiaji, “Implementation of Bidirectional Gated Recurrent Units for Text Classification,” 2023 6th Int. Conf. on Information and Communications Technology (ICOIACT), pp. 464-469, 2023. https://doi.org/10.1109/ICOIACT59844.2023.10455822
  24. [24] W. Gu, S. Zheng, R. Wang, and C. Dong, “Forecasting Realized Volatility Based on Sentiment Index and GRU Model,” J. Adv. Comput. Intell. Intell. Inform., Vol.24, No.3, pp. 299-306, 2020. https://doi.org/10.20965/jaciii.2020.p0299
  25. [25] S. Roy and D. Roth, “Solving General Arithmetic Word Problems,” Proc. of the 2015 Conf. on Empirical Methods in Natural Language Processing, pp. 1743-1752, 2015. https://doi.org/10.18653/v1/D15-1202
  26. [26] M. Goswami, V. Sanil, A. Choudhry, A. Srinivasan, C. Udompanyawit, and A. Dubrawski, “AQuA: A Benchmarking Tool for Label Quality Assessment,” Advances in Neural Information Processing Systems, Vol.36, pp. 79792-79807, 2023. https://doi.org/10.52202/075280-3494
  27. [27] M. J. Hosseini, H. Hajishirzi, O. Etzioni, and N. Kushman, “Learning to Solve Arithmetic Word Problems with Verb Categorization,” Proc. of the 2014 Conf. on Empirical Methods in Natural Language Processing (EMNLP), pp. 523-533, 2014. https://doi.org/10.3115/v1/D14-1058
  28. [28] A. Srivastava, A. Rastogi, A. Rao, A. A. Md Shoeb, A. Abid, A. Fisch, A. R. Brown, A. Santoro, A. Gupta, A. Garriga-Alonso et al., “Beyond the imitation game: Quantifying and extrapolating the capabilities of language models,” Trans. on Machine Learning Research, 2023.
  29. [29] M. Geva, D. Khashabi, E. Segal, T. Khot, D. Roth, and J. Berant, “Did Aristotle Use a Laptop? A Question Answering Benchmark with Implicit Reasoning Strategies,” Trans. of the Association for Computational Linguistics, Vol.9, pp. 346-361, 2021. https://doi.org/10.1162/tacl_a_00370
  30. [30] A. Talmor, J. Herzig, N. Lourie, and J. Berant, “CommonsenseQA: A Question Answering Challenge Targeting Commonsense Knowledge,” Proc. of the 2019 Conf. of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Vol.1 (Long and Short Papers), pp. 4149-4158, 2019. https://doi.org/10.18653/v1/N19-1421
  31. [31] D. Jin, E. Pan, N. Oufattole, W.-H. Weng, H. Fang, and P. Szolovits, “What Disease Does This Patient Have? A Large-Scale Open Domain Question Answering Dataset from Medical Exams,” Applied Sciences, Vol.11, Issue 14, Article No.6421, 2021. https://doi.org/10.3390/app11146421
  32. [32] J. Pennington, R. Socher, and C. Manning, “GloVe: Global Vectors for Word Representation,” Proc. of the 2014 Conf. on Empirical Methods in Natural Language Processing (EMNLP), pp. 1532-1543, 2014. https://doi.org/10.3115/v1/D14-1162
  33. [33] F. M. Shiri, T. Perumal, N. Mustapha, and R. Mohamed, “A Comprehensive Overview and Comparative Analysis on Deep Learning Models: CNN, RNN, LSTM, GRU,” arXiv preprint, arXiv:2305.17473, 2023. https://doi.org/10.48550/arXiv.2305.17473

*This site is desgined based on HTML5 and CSS3 for modern browsers, e.g. Chrome, Firefox, Safari, Edge, Opera.

Last updated on Sep. 19, 2026