## 3 Materials and Methods
### Methods
#### 3.2.2 Generation of Personalized Medical Advice  
In the age of big data, the increasing demand for personalized medical care matches well with the growing volume of medical data. The internet abounds with high-quality medical advice from medical experts, tailored to patients' conditions. By leveraging advanced computer technology, we can effectively gather and share this knowledge, providing robust support for generating personalized medical advice. 1. Information collection The generation of personalized medical advice primarily depends on two types of information: Basic Information: Includes gender, age, etc., collected before using the tool. Special Information: Includes diagnostic results, personal experiences, drug allergy history, concurrent symptoms, etc., gathered during the use of the diagnostic tool. \begin{table}
\begin{tabular}{c c} \hline \hline
**Component** & **Category Count** \\ \hline States & Different operational phases of the system, representing specific behaviors or attributes. \\ Events & External factors that trigger state changes, such as user input or sensor feedback. \\ Transitions & Rules for transitioning between states, associated with specific events and conditions. \\ Actions & Specific operations performed during state transitions. \\ \hline \hline \end{tabular}
\end{table} 
Table 3: State-machine component table. Figure 4: Program flowchart. Retrieval matching strategy  
The evolution of text-retrieval technology has progressed from the initial Boolean retrieval models [36] to modern deep-learning-based models, such as the Transformer architecture [37]. These technologies have strong information-retrieval capabilities. However, in specific scenarios, particularly with limited data volumes, they may not fully meet precise retrieval requirements. This study adopts a keyword-weight-matching method. Initially, patient-related information is collected via the M.I.N.I tool, and this is then cleaned and filtered to extract keywords and assign weights. Using these keywords, a preliminary match is performed on a pre-stored high-quality mental and psychological Q&A dataset in MySQL 5.7, forming subsets of question-answer pairs. These subsets are then ranked according to their weight scores, and the top N-ranked data are selected as the candidate set. The advantage of this method is its focus on key information, significantly enhancing the quality of the final data, while also substantially reducing the computational load of subsequent semantic matching. The process schematic is illustrated in Figure 5.  
3 Semantic matching model  
Semantic matching, the process of measuring textual similarity, has evolved from early neural network-based methods, like Word2 Vec [38] and GloVe [39], to Long Short-Term Memory networks (LSTM/BiLSTM) [40]. In 2018, [PERSON] et al. [5] introduced the BERT model, based on the Transformer architecture, which excels in learning deep language representations from unlabeled text and exhibits remarkable multi-tasking capabilities. Its Cross-Encoder structure, depicted in Figure 6, assesses the relationship between two texts by providing a direct relational score, considering both inputs in their entirety. A variant of BERT, RoBERTa, shows superior performance in tasks like semantic sentence matching. Figure 5: Keyword-weight matching. Letters a–f represent different weight values. This study employs the RoBERTa model and a Cross-Encoder structure to develop a semantic-matching model, fine-tuned with knowledge in mental and psychological health. It evaluates the relevance between Text_Question (question) and Text_Answer (answer), as shown in Figure 7. Equations (1) and (2) illustrate the ReLU and Sigmoid activation functions, respectively, commonly used in neural networks and deep learning. \[ReLU(x)=\max(0,x) \tag{1}\]  
\[Sigmoid(x)=\frac{1}{1+e^{-x}} \tag{2}\]  
The model architecture includes the following four main layers, as detailed in Table 4.  
Figure 6: Cross-Encoder structure. Figure 7: RoBERTa model based on Cross-Encoder.