Abstract
Roughly 50 million people worldwide live with epilepsy, and about a third of them do not respond to anti-epileptic drugs, which makes predicting a seizure before it begins clinically meaningful. We propose a new end-to-end framework based on large language models (LLMs) for predicting seizure onset using electroencephalogram (EEG) data. The framework rests on two contributions: (i) a vocabulary that transcribes multichannel EEG signals into a discrete codebook that is interpretable by LLM-style decoders, and (ii) the exploration of two LLM variants, GPT-2 and Llama-3, adapted to this vocabulary through transfer learning by fine-tuning, with the goal of predicting seizure onset with the lowest possible error. The vocabulary is obtained by fitting a k-means codebook on one-second multichannel EEG patches from the training cohort; the LLM variants are then trained on the resulting token stream with a causal pre-training pass followed by a fine-tuning pass that flags preictal windows. We evaluate the framework on the CHB-MIT scalp EEG dataset under a strict person-disjoint cross-patient split (16 training, 3 validation and 5 test cases, with 22 held-out seizure events) and, because the interictal class dominates the windows, report prediction-focused metrics rather than accuracy: pre-onset sensitivity (Sensp), false alarms per hour (FAR/h), lead time, and sensitivity at fixed FAR. The configuration that maximises sensitivity (codebook , GPT-style LLM, focal loss plus weighted sampler) predicts 16 of 22 test seizures ahead of onset (Sensp ) with a median lead time of 280 s, at the price of 4.17 false alarms per hour. For the implemented 600 s prediction horizon, a rate-matched homogeneous Poisson process at 4.165 alarms/h yields a 50.1% chance-alarm probability, compared with the observed 72.7% event sensitivity. A persistence-smoothing operating point pulls FAR below 0.5/h but trades away most of the sensitivity. These results demonstrate an end-to-end route from discrete EEG motifs to pre-onset alarms under a strict person-disjoint protocol. The resulting sensitivity–FAR frontier provides a transparent cross-patient baseline and identifies representation learning and alarm-policy calibration as complementary directions for improving the framework.
1. Introduction
Epilepsy is a chronic neurological disorder in which abnormal hypersynchronous cortical activity produces recurrent seizures. The World Health Organization estimates that more than 50 million people live with epilepsy and that about one third do not respond adequately to medications [1]. For refractory patients, a warning issued before onset could support protective actions, assistive notification, or closed-loop stimulation. The target is therefore not merely the detection of seizures after onset but the prediction of seizures from preictal EEG with positive lead time.
Many CHB-MIT seizure-prediction studies use hand-crafted spectral or nonlinear features, CNN, recurrent networks, or hybrid CNN–LSTM models [2,3,4]. These systems can report high performance within the patient, but recent methodological audits show that overlapping windows, non-person-disjoint partitions, and loose prediction/detection definitions can inflate apparent performance [5,6]. We therefore frame the study as held-out cross-patient prediction and credit only alarms that occur strictly before the annotated onset.
Large language models are attractive for EEG because decoder-only transformers learn long-range dependencies from token streams [7,8,9]. The obstacle is that EEG is continuous, multichannel, and high-rate, whereas language models expect discrete vocabularies. Foundation EEG models such as LaBraM and NeuroLM address this through large-scale pre-training, but at substantial data and compute cost [10,11]. This paper explores the opposite end of the spectrum: a compact, training-only k-means codebook that turns raw EEG into one-second motifs, followed by small GPT-2 and Llama-3-style decoders fine-tuned for the prediction of the onset of seizures.
Contributions are twofold. First, we define an EEG vocabulary in which each token is the nearest centroid of a one-second, 23-channel patch fitted from training subjects only. Second, we compare EEGGPT and EEGLlama under the same causal pre-training and supervised fine-tuning protocol. The evaluation reports codebook quality, window-level discrimination, event-level prediction sensitivity, false alarms per hour, and lead time.
2. Materials and Methods
2.1. Dataset and Person-Disjoint Split
We used the CHB-MIT scalp EEG database [2], sampled at 256 Hz with 23 bipolar channels and 198 annotated seizure events. Because chb01 and chb21 correspond to the same person, both cases were assigned to the same data partition to prevent identity leakage. The final split is person-disjoint: 16 training cases, 3 validation cases, and 5 test cases representing 4 distinct persons. The closed test fold contains 22 seizure events and is used only once for the final event-level evaluation. Table 1 reports the case, person, and event counts assigned to each partition.
Table 1.
Person-disjoint CHB-MIT split used in this work.
2.2. EEG Preprocessing and Positive-Window Definition
EDF recordings are resampled at 256 Hz, restricted to 23 canonical bipolar channels, band-pass filtered from 0.5 to 70 Hz, notched at 60 Hz, and standardized per channel. Missing channels are filled with zero and recorded. Windows with maximum absolute amplitude above 3000 V are discarded as saturation artifacts while preserving high-amplitude peri-ictal activity.
Each positive sample is a 60-second window positioned around the onset of the seizure. The parameter controls how many seconds of that window are preictal. Four settings are evaluated: opt-A (), opt-B (), opt-C (), and opt-D (). opt-D is the strict prediction case because the window contains no ictal samples. Table 2 summarizes the preictal and ictal composition of the four configurations. For each seizure and , eight positive windows are generated with small random changes. Negative windows are sampled at least 1200 s away from any seizure boundary, avoiding a shortcut in which negatives come only from seizure-free files.
Table 2.
Positive-window configurations. is the number of preictal seconds inside each 60 s positive window.
2.3. Codebook-and-LLM Framework
The proposed framework has two modules (Figure 1). The first module fits a vocabulary of k-means in raw training EEG patches. A 60-second window of shape is divided into 60 patches of shape ; each patch is replaced by the index of its nearest centroid in . Each centroid is an EEG motif: a one-second multichannel prototype summarizing a recurrent region of the training patch space. The frozen codebook then tokenizes the validation and test subjects, avoiding tokenizer leakage.
Figure 1.
End-to-end codebook-and-language-model framework. Raw multichannel EEG is segmented into one-second patches, quantized into discrete motifs, modeled by a compact decoder-only LLM, and converted into event-level alarms through thresholding, persistence, and cooldown.
The second module consumes the token stream with a compact decoder-only LLM. EEGGPT uses learned positional embeddings, GELU feed-forward blocks, and pre-LayerNorm. EEGLlama follows the LlamaModel recipe with RMSNorm, rotary positional embeddings, and SwiGLU blocks. Both use layers, heads, , , dropout 0.1, and a maximum length of 64 tokens. Both models are trained first for the prediction of the causal next-token in the EEG vocabulary and then fine-tuned with a -pooled binary classifier. We compare BCE and focal loss with weighted sampling.
2.4. Evaluation
In the codebook stage, we monitor validation reconstruction RMSE, active-token use, and event sensitivity at FAR /h; is retained as the operating vocabulary because it combines the highest observed mean controlled-FAR sensitivity with a reconstruction error on the plateau of the sweep. In the LLM stage, validation , AUC, and MCC provide complementary checkpoint diagnostics. For continuous evaluation, the fine-tuned model is applied with a 4 s stride. An alarm is fired when the probability exceeds the validation-selected threshold for consecutive windows, and a 10 min cooldown suppresses duplicate alarms. Alarms strictly before onset are counted as predictions, whereas alarms at or after onset are counted separately as detections. FAR/h is computed from alarms in interictal periods located at least 1200 s from a seizure boundary. To contextualize event sensitivity at a given alarm rate, a homogeneous Poisson process with rate r alarms/hour and eligible pre-onset horizon H hours has chance-alarm probability . The continuous-evaluation implementation used a maximum pre-onset lead of 600 s, hence h. At the high-sensitivity operating point, /h gives . This analytical reference assumes stationary, independent Poisson alarms and is used for descriptive context rather than as an inferential significance test.
3. Results and Discussion
3.1. Contribution (i): EEG Vocabulary
Table 3 summarizes the codebook sweep using reproducible descriptive quantities. RMSE improves only modestly beyond , while gives the highest observed mean Sensp at FAR /h. We therefore retain as an operational choice rather than as a statistically superior vocabulary. With only three seeds, inferential comparisons are not reported.
Table 3.
Codeboo sweep across three seeds. Results are descriptive; no inferential comparison is made for .
3.2. Contribution (ii): LLM Variants
Table 4 compares EEGGPT and EEGLlama under the same vocabulary and fine-tuning protocol. The window-level AUC values cluster around 0.5, while EEGGPT attains the highest mean within both evaluated objectives. We therefore use these metrics as checkpoint diagnostics and rely on the continuous event-level analysis to characterize how the learned probability streams translate into pre-onset alarms and false-alarm rates.
Table 4.
Descriptive validation comparison of LLM variants across 10 training seeds.
3.3. Integrated Continuous Prediction
The integrated system is evaluated on continuous held-out EDFs. Table 5 shows that the most sensitive configuration predicts 16 of 22 seizures before onset (Sensp ) with a median lead time of 280 s at 4.165 FAR/h. This operating point produces, on average, one alarm every 14.4 min and therefore represents the sensitivity-oriented end of the observed frontier. With the implemented 10-min horizon, the rate-matched Poisson probability is 0.501, corresponding to approximately 11 of 22 events expected to contain at least one random alarm, whereas 16 events were predicted by the model. The observed sensitivity is therefore 22.6 percentage points above this analytical chance reference. This descriptive difference does not by itself establish statistical significance and does not make 4.165 FAR/h clinically acceptable. Increasing persistence moves the system toward lower-FAR operation by suppressing isolated probability excursions, although it also reduces the number of pre-onset alarms. The joint reporting of Sensp, FAR/h, lead time, and chance context captures this clinically relevant operating trade-off more completely than a single window-level metric.
Table 5.
Continuous event-level prediction on held-out test EEG.
Figure 2 visualizes the sensitivity–FAR trade-off of the event-level operating points in Table 5; the inset enlarges the low-FAR region so that closely spaced configurations remain distinguishable.
Figure 2.
Clinical operating frontier after event-level alarm post-processing. Markers show the sensitivity and FAR values reported in Table 5; the inset enlarges the overlapping low-FAR region without displacing the observations. The practical trade-off is between high pre-onset sensitivity and clinically tolerable FAR.
The high-sensitivity and low-FAR operating points characterize two complementary uses of the framework. The focal+sampler EEGGPT configuration emphasizes seizure coverage, whereas persistence-based configurations emphasize alarm suppression. Together they show that the discrete vocabulary and decoder can support a tunable event-level alarm pipeline. Controlled comparisons with token-histogram classifiers, raw-window convolutional models, and an EEGGPT variant trained without causal pre-training constitute the next experimental step for separating the contributions of tokenization, sequence modeling, and pre-training.
3.4. Clinical Interpretation and Protocol Safeguards
Figure 3 shows the sensitivity/FAR movement across positive-window definitions before applying stronger smoothing. Moving from detection-like windows toward stricter preictal windows increases the opportunity to learn pre-onset structure, but it also exposes the classifier to more ambiguous preictal/interictal boundaries. This explains why the best sensitivity point and the best deployment point do not coincide.
Figure 3.
Prediction sensitivity and false-alarm rate across positive-window definitions at and persistence .
Table 6 summarizes the methodological safeguards that distinguish this evaluation from the simpler CHB-MIT protocols. The tokenizer never sees the test subjects; the test fold is person-disjoint; thresholds are selected using the validation data; and alarms after the onset are explicitly separated from the pre-onset predictions. The pooled held-out evaluation measures performance across four distinct test persons using one global alarm policy. A patient-stratified extension reporting event counts, interictal exposure, FAR/h, sensitivity, and confidence intervals would quantify cross-patient heterogeneity and support the development of validation-only patient-adaptive operating points.
Table 6.
Protocol safeguards and their impact on interpretation.
3.5. Comparison with Prior CHB-MIT Studies
Table 7 shows how the proposed framework compares with representative CHB-MIT seizure-prediction reports. This comparison should not be interpreted as a direct leaderboard. Although this study uses held-out patients and strict pre-onset criteria, Truong et al. [3], CBAM-3D [12], CLEP [13], MVNN [14], and OPP [15] use protocols ranging from cross-validation within the patient to subject-specific calibration. Given these constraints, while the proposed method is not numerically dominant, it is transparent and lightweight, and it evaluates the more challenging task of predicting seizures in different patients.
Table 7.
Representative CHB-MIT seizure-prediction comparison.
4. Conclusions and Future Work
We presented a lightweight codebook-and-language-model framework for strict prediction of seizure-onset from scalp EEG. The k-means vocabulary converts raw multichannel CHB-MIT recordings into one-second motifs, and compact decoder-only LLM variants learn over the resulting token stream. Under a held-out person-disjoint test protocol, the most sensitive EEGGPT operating point predicts 16 of 22 seizures before onset with a median lead time of 280 s, but at 4.17 FAR/h. Persistence smoothing reduces FAR below 0.5/h but collapses sensitivity. This study contributes a leakage-controlled pipeline that connects training-only EEG tokenization, compact decoder modeling, and continuous pre-onset alarm evaluation. Its principal empirical result is the quantified sensitivity–FAR frontier across model and persistence settings, which establishes a reproducible cross-patient baseline for subsequent improvements in representation learning and decision calibration.
For the specified 600 s prediction horizon, the high-sensitivity point exceeds the rate-matched analytical Poisson reference (72.7% observed versus 50.1% expected by chance). Nevertheless, this comparison is descriptive, and the associated 4.165 FAR/h remains unsuitable for unattended clinical deployment.
Future experiments will add matched token-histogram and raw-window baselines, isolate the contribution of causal pre-training, evaluate analytic and randomized chance-alarm controls, and report patient-level estimates with uncertainty. Larger unlabeled EEG corpora, trainable vector-quantized encoders, validation-only patient adaptation, and explainability analyses provide additional routes for improving the sensitivity–FAR frontier while preserving the person-disjoint evaluation protocol.
Author Contributions
Conceptualization, A.P., N.P.-P. and D.B.; methodology, A.P.; software, A.P.; validation, A.P., N.P.-P., and M.H.; formal analysis, A.P.; investigation, A.P., N.P.-P.; resources, N.P.-P. and D.B.; data curation, A.P.; writing—original draft preparation, A.P.; writing—review and editing, A.P., N.P.-P., M.H., O.C. and D.B.; visualization, A.P. and N.P.-P.; supervision, N.P.-P. and D.B.; project administration, N.P.-P., D.B.; funding acquisition, N.P.-P. and D.B. All authors have read and agreed to the published version of the manuscript.
Funding
This work was supported by the Universidad San Francisco de Quito through the Poli-Grants Program under Grants No. 41983 and 42995.
Institutional Review Board Statement
Not applicable.
Informed Consent Statement
Not applicable.
Data Availability Statement
No new data were created in this study. The EEG recordings analyzed in this work are publicly available through the CHB-MIT Scalp EEG Database, PhysioNet, version 1.0.0, at https://physionet.org/content/chbmit/1.0.0/ (accessed on 28 July 2026) (DOI: https://doi.org/10.13026/C2K01R).
Acknowledgments
Authors thank the Applied Signal Processing and Machine Learning Research Group of USFQ for providing the computing infrastructure used to implement and execute the experiments.
Conflicts of Interest
The authors declare no conflicts of interest.
References
- World Health Organization. Epilepsy: A Public Health Imperative. 2020. Available online: https://www.who.int/publications/i/item/epilepsy-a-public-health-imperative (accessed on 23 June 2026).
- Shoeb, A.H. Application of Machine Learning to Epileptic Seizure Onset Detection and Treatment. Ph.D. Thesis, Massachusetts Institute of Technology, Cambridge, MA, USA, 2009. [Google Scholar]
- Truong, N.D.; Nguyen, A.D.; Kuhlmann, L.; Bonyadi, M.R.; Yang, J.; Ippolito, S.; Kavehei, O. Convolutional neural networks for seizure prediction using intracranial and scalp electroencephalogram. Neural Netw. 2018, 105, 104–111. [Google Scholar] [CrossRef] [Scilit] [PubMed]
- Esmaeilpour, A.; Shahiri Tabarestani, S.; Niazi, A. Deep learning-based seizure prediction using EEG signals: A comparative analysis of classification methods on the CHB-MIT dataset. Eng. Rep. 2024, 6, e12918. [Google Scholar] [CrossRef] [Scilit]
- Ali, E.; Angelova, M.; Karmakar, C. Epileptic seizure detection using CHB-MIT dataset: The overlooked perspectives. R. Soc. Open Sci. 2024, 11, 230601. [Google Scholar] [CrossRef] [Scilit] [PubMed]
- Bhattacharjee, S.; Duma, G.M.; Mento, G.; Danieli, A.; Antoniazzi, L.; Del Popolo Cristaldi, F.; Bonanni, P.; Testolin, A. Methodological issues in evaluating machine learning models for EEG seizure prediction: Good cross-validation accuracy does not guarantee generalization to new patients. Appl. Sci. 2023, 13, 4262. [Google Scholar] [CrossRef] [Scilit]
- Vaswani, A.; Shazeer, N.; Parmar, N.; Uszkoreit, J.; Jones, L.; Gomez, A.N.; Kaiser, Ł.; Polosukhin, I. Attention is all you need. In Advances in Neural Information Processing Systems; Neural Information Processing Systems Foundation: San Diego, CA, USA, 2017; Volume 30. [Google Scholar]
- Radford, A.; Wu, J.; Child, R.; Luan, D.; Amodei, D.; Sutskever, I. Language Models Are Unsupervised Multitask Learners; Technical Report; OpenAI: San Francisco, CA, USA, 2019. [Google Scholar]
- Touvron, H.; Lavril, T.; Izacard, G.; Martinet, X.; Lachaux, M.A.; Lacroix, T.; Rozière, B.; Goyal, N.; Hambro, E.; Azhar, F.; et al. Llama: Open and efficient foundation language models. arXiv 2023, arXiv:2302.13971. [Google Scholar]
- Jiang, W.B.; Zhao, L.; Lu, B.L. LaBraM: A large brain model for learning generic representations with tremendous EEG data in BCI. In Proceedings of the International Conference on Learning Representations (ICLR), Vienna, Austria, 7–11 May 2024. [Google Scholar]
- Jiang, W.B.; Wang, Y.; Lu, B.L.; Li, D. NeuroLM: A universal multi-task foundation model for bridging the gap between language and EEG signals. arXiv 2024, arXiv:2409.00101. [Google Scholar]
- Lu, X.; Wen, A.; Sun, L.; Wang, H.; Guo, Y.; Ren, Y. An epileptic seizure prediction method based on CBAM-3D CNN-LSTM model. IEEE J. Transl. Eng. Health Med. 2023, 11, 417–423. [Google Scholar] [CrossRef] [Scilit] [PubMed]
- Guo, L.; Yu, T.; Zhao, S.; Li, X.; Liao, X.; Li, Y. CLEP: Contrastive learning for epileptic seizure prediction using a spatio-temporal-spectral network. IEEE Trans. Neural Syst. Rehabil. Eng. 2023, 31, 3915–3926. [Google Scholar] [CrossRef] [Scilit] [PubMed]
- Lucasius, C.; Grigorovsky, V.; Nariai, H.; Galanopoulou, A.S.; Gursky, J.; Moshé, S.L.; Bardakjian, B.L. Biomimetic deep learning networks with applications to epileptic spasms and seizure prediction. IEEE Trans. Biomed. Eng. 2024, 71, 1056–1067. [Google Scholar] [CrossRef] [Scilit] [PubMed]
- Koutsouvelis, P.; Chybowski, B.; Gonzalez-Sulser, A.; Abdullateef, S.; Escudero, J. Preictal period optimization for deep learning-based epileptic seizure prediction. J. Neural Eng. 2024, 21, 066040. [Google Scholar] [CrossRef] [Scilit] [PubMed]
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.


