Submitted:
17 April 2026
Posted:
20 April 2026
You are already at the latest version
Abstract
Keywords:
1. Introduction
- Pre-training on the large corpus or text data from diverse sources;
- Fine-tuning of the model to a target application domain with application specific data;
- Prompt adaptation providing context basis.
- 1.
- Using a fine-tuned LLM model to execute real-time decisions for insulin regulation in an artificial pancreas system.
- 2.
- Introduction of a novel technique to seamlessly represent quantified data into LLM embedding space as amplitude modulated carrier tokens.
- 3.
- Closed-loop fine-tuning of fuzzy LLM controller with multiple randomized metabolic models of T1D virtual patients.
- 4.
- Validation of fine-tuned fuzzy LLM controller in UVa/Padova simulator for 10 virtual patients from adult population.
2. Preliminaries
2.1. Hovorka Model
2.2. Fuzzy Logic Control Basics
2.3. Large Language Models
3. Proposed LLM-Fuzzy Framework
3.1. Fuzzy Embeddings
3.2. LLM for Fuzzy Inference
| Listing 1. Tiny Llama prompt for fuzzy decision making. |
| <|system|> You are an automatic insulin delivery advisor for type 1 diabetes.</s> <|user|> Historical glucose: <G10><G9><G8><G7><G6><G5><G4><G3><G2><G1>. Historical insulin dosages: <U10><U9><U8><U7><U6><U5><U4><U3><U2><U1></s> <|assistant|> Next insulin dose: <U> |
3.3. Closed-Loop System with LLM
3.4. Training Objective
4. Fine-Tuning Implementation
4.1. Metabolic Model in GPU
| Listing 2. Virtual patients parametrization. |
|
BW = torch.tensor([70., 75. ...]) state = torch.tensor(init_state).repeat(batch_size,1) # ingestion time, min/ Digested CHO mmol meals = [(8*60,250), (12*60,250), (19*60,250)] |
| Listing 3. Model derivative calculation. |
|
def ap_model(t,state,uin): VG = 0.16*BW ... Q1 = state[:,0] Q2 = state[:,1] ... G = Q1/VG # mmol/L ... Q1dot = EGP0*(1.0-x3) + UG - FR - (x1+F01c/(VG*G))*Q1 + k12*Q2 ... dstate = torch.hstack([ Q1dot.unsqueeze(1), Q2dot.unsqueeze(1),...]) return (dstate,G) |
| Listing 4. Hovorka model integration. |
|
(dstate,G) = ap_model(tt,state,u_new) state = state + dstate*Ts state_extrap = state for k in range(0,Textrap): (dstate,Gk) = ap_model(tt,state_extrap,u_new) state_extrap = state_extrap + dstate*Ts |
4.2. LoRA Configuration
| Listing 5. LLM Initialization with LoRA Adapter. |
|
llm_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0" llm = AutoModelForCausalLM.from_pretrained(llm_name,device_map="auto") tokenizer = AutoTokenizer.from_pretrained(llm_name) lora_config = LoraConfig(r=16,lora_alpha=32,...) llm = get_peft_model(llm, lora_config) |
4.3. Fuzzy Embeddings
| Listing 6. LLM embedding of glucose concentration. |
|
input_terms = [’hypoglycemia’,’in range’,’hyperglycemia’] input_terms_tok = tokenizer(input_terms,padding=True,...)... input_terms_vec0 = llm.model.embed_tokens(input_terms_tok) input_terms_vec = hypo_glucose(yt)*input_terms_vec0[0,:,:] +target_glucose(yt)*input_terms_vec0[1,:,:] +hyper_glucose(yt)*input_terms_vec0[2,:,:] |
4.4. Inference and Defuzzification
| Listing 7. Calculating new control action. |
|
combined_embeds = torch.cat([vect_msg1,input_terms_vec,...],... outputs = llm(inputs_embeds=combined_embeds,use_cache=False) output_logits = outputs.logits[:,-1] zero_dose_p = output_logits.gather(1,output_terms_tok[0,0]) low_dose_p = output_logits.gather(1,output_terms_tok[1,0]) high_dose_p = output_logits.gather(1,output_terms_tok[2,0]) mf_block_norm = softmax(torch.cat([zero_dose_p,low_dose_p,high_dose_p],... agg_mu = torch.einsum(’br,rx->bx’, mf_block_norm, mf_vals) u_new = BW*(torch.trapz(agg_mu * x_vals.unsqueeze(0), x_vals, dim=1) / (torch.trapz(agg_mu, x_vals, dim=1) + 1e-8)) |
4.5. Training Loop
| Listing 8. Training Loop. |
|
for t in range(0,num_training_steps): ... optimizer.zero_grad() total_loss = ((Gk - 105/18)*(Gk - 105/18)).max() total_loss.backward() optimizer.step() yt = torch.hstack([yt[:,input_toks_per_term:],G]) ut = torch.hstack([ut[:,output_toks_per_term:],u_per_kg]) |
4.6. Deployment
5. Results
5.1. Fine-Tuning Performance
5.2. Simulation with UVa/Padova

6. Conclusions
Funding
Data Availability Statement
Conflicts of Interest
References
- American Diabetes Association. Standards of Care in Diabetes to Guide Prevention, Diagnosis, and Treatment for People Living with Diabetes; American Diabetes Association: Arlington, VA, USA, 2023. [Google Scholar]
- National Institute for Health and Care Excellence. Type 1 Diabetes in Adults: Diagnosis and Management; National Institute for Health and Care Excellence: London, UK, 2017. [Google Scholar]
- Nakrani, M.N.; Wineland, R.H.; Anjum, F. Physiology, Glucose Metabolism. In StatPearls [Internet]; StatPearls Publishing: Treasure Island, FL, USA, 2023; Available online: https://www.ncbi.nlm.nih.gov/books/NBK560599/ (accessed on 1 June 2023).
- Melo, K.F.S.; Bahia, L.R.; Pasinato, B.; Porfirio, G.J.M.; Martimbianco, A.L.; Riera, R.; Calliari, L.E.P.; Minicucci, W.J.; Turatti, L.A.A.; Pedrosa, H.C.; et al. Short-acting insulin analogues versus regular human insulin on postprandial glucose and hypoglycemia in type 1 diabetes mellitus: A systematic review and meta-analysis. Diabetol Metab. Syndr. 2019, 11. [Google Scholar] [CrossRef] [PubMed]
- Man, C.D.; Micheletto, F.; Lv, D.; Breton, M.; Kovatchev, B.; Cobelli, C. The UVA/PADOVA Type 1 Diabetes Simulator: New Features. J Diabetes Sci Technol. 2014, 26–34. [Google Scholar] [CrossRef] [PubMed]
- Fushimi, E.; De Battista, H.; Garelli, F. A Dual-Hormone Multicontroller for Artificial Pancreas Systems. IEEE J. Biomed. Health Inform. 2022, 26, 4743–4750. [Google Scholar] [CrossRef] [PubMed]
- Peng, Z.; Xie, X.; Tan, Q.; Kang, H.; Cui, J.; Zhang, X.; Li, W.; Feng, G. Blood glucose sensors and recent advances: A review. J. Innov. Opt. Health Sci. 2022, 15. [Google Scholar] [CrossRef]
- Huyett, L.M.; Dassau, E.; Zisser, H.C.; Doyle, F.J. Glucose Sensor Dynamics and the Artificial Pancreas. IEEE Control. Syst. Mag. 2018, 38, 30–46. [Google Scholar] [CrossRef]
- Berget, C.; Messer, L.H.; Forlenza, G.P. A Clinical Overview of Insulin Pump Therapy for the Management of Diabetes: Past, Present, and Future of Intensive Therapy. Diabetes Spectr. 2019, 32, 194–204. [Google Scholar] [CrossRef]
- Lewis, D.; Leibrand, S. Real-World Use of Open Source Artificial Pancreas Systems. J. Diabetes Sci. Technol. 2016. [Google Scholar] [CrossRef]
- Knebel, T.; Neumiller, J.J. Medtronic MiniMed 670G Hybrid Closed-Loop System. Clin. Diabetes 2019, 37, 94–95. [Google Scholar] [CrossRef]
- Kublin, O.; Stępień, M. The Nightscout system—Description of the system and its evaluation in scientific publications. Pediatr. Endocrinol. Diabetes Metab. 2020, 26, 140–143. [Google Scholar] [CrossRef]
- Gomez, E.J.; Pérez, M.E.H.; Vering, T.; Cros, M.R.; Bott, O.; García-Sáez, G.; Pretschner, P.; Brugués, E.; Schnell, O.; Patte, C.; et al. The INCA System: A Further Step Towards a Telemedical Artificial Pancreas. IEEE Trans. Inf. Technol. Biomed. 2008, 12, 470–479. [Google Scholar] [CrossRef]
- Pfeiffer, E.F. Artificial pancreas: State of the Art. Int. J. Artif. Organs 1988, 11, 13–26. [Google Scholar] [CrossRef] [PubMed]
- Bondia, J.; Romero-Vivó, S.; Ricarte, B.; Díez, J.L. Insulin Estimation and Prediction. IEEE Control. Syst. Mag. 2018, 38, 47–66. [Google Scholar] [CrossRef]
- Seron, M.M.; Braslavsky, J.H.; Goodwin, G.C. Fundamental Limitations in Filtering and Control; Springer: London, UK, 1997; ISBN 9781447112440. [Google Scholar]
- Ramkissoon, C.M.; Aufderheide, B.; Bequette, B.W.; Vehi, J. A Review of Safety and Hazards Associated With the Artificial Pancreas. IEEE Rev. Biomed. Eng. 2017, 10, 44–62. [Google Scholar] [CrossRef]
- Borri, A.; Cacace, F.; Gaetano, A.; Germani, A.; Manes, C.; Palumbo, P.; Panunzi, S.; Pepe, P. Observers for Nonlinear Time-Delay Systems with Application to the Artificial Pancreas IEEE Control. Syst. Mag. 2017, 37, 33–49. [Google Scholar]
- Sanz, R.; Garcia, P.; Diez, J.-L.; Bondia, J. Artificial Pancreas System With Unannounced Meals Based on a Disturbance Observer and Feedforward Compensation. IEEE Trans. Control. Syst. Technol. 2021, 29, 454–460. [Google Scholar] [CrossRef]
- Turksoy, K.; Samadi, S.; Feng, J.; Littlejohn, E.; Quinn, L.; Cinar, A. Meal Detection in Patients With Type 1 Diabetes: A New Module for the Multivariable Adaptive Artificial Pancreas Control System. IEEE J. Biomed. Health Inform. 2016, 20, 47–54. [Google Scholar] [CrossRef]
- Paoletti, N.; Liu, K.S.; Chen, H.; Smolka, S.A.; Lin, S. Data-Driven Robust Control for a Closed-Loop Artificial Pancreas. IEEE/Acm Trans. Comput. Biol. Bioinform. 2020, 17, 1981–1993. [Google Scholar] [CrossRef]
- Lee, S.; Kim, J.; Park, S.W.; Jin, S.-M.; Park, S.-M. Toward a Fully Automated Artificial Pancreas System Using a Bioinspired Reinforcement Learning Design: In Silico Validation. IEEE J. Biomed. Health Inform. 2021, 25, 536–546. [Google Scholar] [CrossRef] [PubMed]
- Chakrabarty, A.; Zavitsanou, S.; Doyle, F.J.; Dassau, E. Event-Triggered Model Predictive Control for Embedded Artificial Pancreas Systems. IEEE Trans. Biomed. Eng. 2018, 65, 575–586. [Google Scholar] [CrossRef]
- Chakrabarty, A.; Healey, E.; Shi, D.; Zavitsanou, S.; Doyle, F.J.; Dassau, E. Embedded Model Predictive Control for a Wearable Artificial Pancreas. IEEE Trans. Control. Syst. Technol. 2020, 28, 2600–2607. [Google Scholar] [CrossRef]
- Batmani, Y.; Khodakaramzadeh, S.; Moradi, P. Automatic Artificial Pancreas Systems Using an Intelligent Multiple-Model PID Strategy. IEEE J. Biomed. Health Inform. 2022, 26, 1708–1717. [Google Scholar] [CrossRef] [PubMed]
- Meneghetti, L.; Terzi, M.; Favero, S.; Susto, G.A.; Cobelli, C. Data-Driven Anomaly Recognition for Unsupervised Model-Free Fault Detection in Artificial Pancreas. IEEE Trans. Control. Syst. Technol. 2020, 28, 33–47. [Google Scholar] [CrossRef]
- Ruiz-Velázquez, E.; García-Rodríguez, J.; Quiroz, G.; Femat, R. Robust μ-synthesis: Towards a unified glucose control in adults, adolescents and children with T1DM. J. Frankl. Inst. 2020, 357, 9633–9653. [Google Scholar] [CrossRef]
- Cassany, L.; Gucik-Derigny, D.; Cieslak, J.; Henry, D.; Franco, R.; Ferreira de Loza, A.; Ríos, H.; Olcomendy, L.; Pirog, A.; Bornat, Y.; Renaud, S.; Catargi, B. A Robust H-∞ Control Approach for Blood Glucose Regulation in Type-1 Diabetes. IFAC-PapersOnLine 2021, 54, 460–465. [Google Scholar] [CrossRef]
- Cassany, L.; Gucik-Derigny, D.; Cieslak, J.; Henry, D.; Franco, R.; De Loza, A.F.; Rios, H.; Olçomendy, L.; Pirog, A.; Bornat, Y.; et al. A Robust Control solution for Glycaemia Regulation of Type-1 Diabetes Mellitus. In 2021 European Control Conference (ECC); IEEE: Delft, Netherlands, 2021; pp. 327–332. [Google Scholar] [CrossRef]
- Mandal, S.; Sutradhar, A. Robust controller for artificial pancreas for patients with type-1 diabetes. Res. Biomed. Eng. 2023, 39, 437–450. [Google Scholar] [CrossRef]
- Zadeh, L.A. Fuzzy Logic. Computer 1988, 21(4), 83–93. [Google Scholar] [CrossRef]
- Lee, C.C. Fuzzy Logic in Control Systems: Fuzzy Logic Controller. I. IEEE Transactions on Systems, Man, and Cybernetics 1990, 20(2), 404–18. [Google Scholar] [CrossRef]
- Mamdani, E.H.; Assilian, S. An Experiment in Linguistic Synthesis with a Fuzzy Logic Controller. International Journal of Man-Machine Studies 1975, 7(1), 1–13. [Google Scholar] [CrossRef]
- Grant, P. A New Approach to Diabetic Control: Fuzzy Logic and Insulin Pump Technology. Medical Engineering & Physics 2007, 29(7). [Google Scholar] [CrossRef]
- Mauseth, R.; Wang, Y.; Dassau, E. Proposed Clinical Application for Tuning Fuzzy Logic Controller of Artificial Pancreas Utilizing a Personalization Factor. Journal of Diabetes Science and Technology 2010, 4(4). [Google Scholar] [CrossRef] [PubMed]
- Yan, S.-R.; Alattas, K.A.; Bakouri, M.; Alanazi, A.K.; Mohammadzadeh, A.; Mobayen, S.; Zhilenkov, A.; Guo, W. Generalized Type-2 Fuzzy Control for Type-I Diabetes: Analytical Robust System. Mathematics 2022, 10(690). [Google Scholar] [CrossRef]
- Liu, M.; Zhang, H.; Xu, Z.; Ding, K. The fusion of fuzzy theories and natural language processing: A state-of-the-art survey. Appl. Soft Comput. 2024. [Google Scholar] [CrossRef]
- Zhang, H.; Shang, J. Natural Language Processing and Applications. In Tsinghua University Press; 2025; p. 9789819797387. [Google Scholar]
- Adel, N.; Crockett, K.; Carvalho, J.P.; Cross, V. Fuzzy Influence in Fuzzy Semantic Similarity Measures. 2021 IEEE International Conference on Fuzzy Systems (FUZZ-IEEE), 2021 IEEE 1–7. [Google Scholar]
- Adel, N.; Crockett, K.; Livesey, D.; Carvalho, J.P. IEEE Access202210 81506–81521; An interval type-2 fuzzy ontological similarity measure.
- Hoang, C.; Sachan, D.; Mathur, P. Improving retrieval augmented neural machine translation by controlling source and fuzzy-match interactions. Findings of the Association for Computational Linguistics: EACL 2023 2023, 289–295. [Google Scholar]
- Yan, R.; Yu, Y.; Qiu, D. Emotion-enhanced classification based on fuzzy reasoning. International Journal of Machine Learning and Cybernetics 13(3), 839–850. [CrossRef]
- Li, Q.; Li, L.; Li, Q.; Zhong, J. A comprehensive exploration on spider with fuzzy decision text-to-SQL model. IEEE Transactions on Industrial Informatics 2019, 16(4), 2542–2550. [Google Scholar] [CrossRef]
- Novák, V. Fuzzy logic in natural language processing. 2017 IEEE international conference on fuzzy systems (FUZZ-IEEE); 2017; pp. 1–6. [Google Scholar] [CrossRef]
- Vaswani, A.; Shazeer, N.; Parmar, N.; et al. Attention Is All You Need. arXiv. 2023.
- Hu, E.J.; Shen, Y.; Wallis, P.; et al. LoRA: Low-Rank Adaptation of Large Language Models. arXiv. 2021.
- Aghajanyan, A.; Zettlemoyer, L.; Gupta, S. Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning. arXiv. 2020.
- Nosrati, K.; Tepljakov, A.; Belikov, J.; Petlenkov, E. When control meets large language models: From words to dynamics. arXiv. 2026.
- Hovorka, R.; Canonico, V.; Chassin, L.J.; Haueter, U.; Massi-Benedetti, M.; Federici, M.O.; Wilinska, M.E. Nonlinear model predictive control of glucose concentration in subjects with type 1 diabetes. Physiol. Meas. 2004, 25, 905. [Google Scholar] [CrossRef] [PubMed]
- Carson, E.R.; Cobelli, C.; Finkelstein, L. The mathematical modeling of metabolic and endocrine systems: model formulation, identification, and validation; Wiley: New York, 1983; Available online: https://api.semanticscholar.org/CorpusID:83410068.
- Cao, S.G.; Rees, N.W.; Feng, G. Analysis and design of fuzzy control systems using dynamic fuzzy global models. Fuzzy Sets and Systems 1995, 75(1), 47–62. [Google Scholar] [CrossRef]
- Cao, S.G.; Rees, N.W.; Feng, G. Mamdani-type fuzzy controllers are universal fuzzy controllers. Fuzzy Sets and Systems 2001, 123(3), 359–367. [Google Scholar] [CrossRef]
- Touvron, H.; Lavril, T.; Izacard, G.; et al. LLaMA: Open and Efficient Foundation Language Models. arXiv. 2023.
- Su, J.; Lu, Y.; Pan, S.; et al. RoFormer: Enhanced Transformer with Rotary Position Embedding. arXiv. 2023.
- Ba, J.L.; Kiros, J.R.; Hinton, G.E. Layer Normalization. 2016.
- Kingma, D.P.; Ba, J. Adam: A Method for Stochastic Optimization. arXiv. 2017.












| Parameter | Symbol | Unit | Value |
|---|---|---|---|
| Glucose distrib. volume | L | ||
| Insulin distrib. volume | L | ||
| Non-insulin glucose flux | mmol/min | ||
| Transfer rate from to | 1/min | 0.0066 | |
| Deactivation rate | 1/min | 0.006 | |
| Deactivation rate | 1/min | 0.06 | |
| Deactivation rate | 1/min | 0.03 | |
| Insulin sens. of glucose transport | L/min/mU | ||
| Insulin sens. of glucose distribution | L/min/mU | ||
| Insulin sens. of EGP | L/min/mU | ||
| EGP at 0 insulin | mmol/min | ||
| Carbohydrate bioavailability | - | 0.8 | |
| Time to max carbohydrate | min | 40 | |
| Time to max insulin | min | 55 | |
| Insulin elimination from plasma | 1/min | 0.138 |
| Fuzzy Set | Term | Token IDs | Tokens | Embedding |
|---|---|---|---|---|
| hypoglycemia | 10163, 468, 368, 19335, 423 | hyp-og-ly-cem-ia | ||
| in range | 297, 3464, 2, 2, 2 | in -range | ||
| hyperglycemia | 11266, 16808, 19335, 423, 2 | hyper-gly-cem-ia | ||
| zero | 5225 | zero | ||
| low | 4482 | low | ||
| high | 1880 | high |
| ID | BG | LBGI | HBGI | BGRI | RoC | A+B | E+F | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 143 | 0 | 0 | 97 | 3 | 0 | 0 | 3 | 3 | 0.5 | 63 | 0 |
| 2 | 131 | 0 | 0 | 100 | 0 | 0 | 0 | 1 | 1 | 0.3 | 90 | 0 |
| 3 | 142 | 0 | 0 | 100 | 0 | 0 | 0 | 2 | 2 | 0.5 | 62 | 0 |
| 4 | 140 | 0 | 0 | 99 | 1 | 0 | 0 | 2 | 2 | 0.5 | 64 | 0 |
| 5 | 158 | 0 | 0 | 73 | 26 | 0 | 0 | 5 | 5 | 0.7 | 32 | 0 |
| 6 | 133 | 0 | 0 | 95 | 5 | 0 | 0 | 2 | 2 | 0.5 | 79 | 0 |
| 7 | 168 | 0 | 0 | 60 | 40 | 0 | 0 | 7 | 7 | 0.9 | 27 | 0 |
| 8 | 112 | 0 | 3 | 96 | 0 | 0 | 1 | 1 | 2 | 0.7 | 80 | 0 |
| 9 | 135 | 0 | 0 | 98 | 2 | 0 | 0 | 2 | 2 | 0.5 | 78 | 0 |
| 10 | 125 | 0 | 0 | 100 | 0 | 0 | 0 | 1 | 1 | 0.4 | 86 | 0 |
| AVG | 138 | 0 | 0 | 97 | 3 | 0 | 0 | 2 | 2 | 0.6 | 75 | 0 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).