posted on 2025-05-01, 00:00authored byAndrea Paparella
Despite advancements in topic modeling and embedding techniques, deploying these methods entirely on smartphones remains challenging. Current desktop frameworks like BERTopic rely on computationally intensive transformer-based models, making them unsuitable for devices with limited processing power. This limitation restricts the feasibility of high-accuracy, on-device topic modeling and raises privacy concerns, as data must be sent to remote servers for processing.
Although model compression techniques have introduced Mini Language Models by reducing transformer size and computational demands, their application in mobile topic modeling is largely unexplored.
This thesis presents SWIFTopic, a Swift-based framework designed to bring topic modeling inference onto iOS devices. SWIFTopic is inspired by BERTopic, a Python-based framework, and adapts its core inference tasks—such as tokenization, embedding, dimensionality reduction, and Euclidean distance calculation—for on-device execution. While training tasks, including clustering, weighting, and representation tuning, are performed on a desktop environment, the post-training artifacts (e.g., cluster centers, generated topics, and dimensionality reduction data) are then integrated into SWIFTopic for iOS inference.
This framework is applied to a healthcare use case focused on detecting suicidal ideation. A BERTopic model is first trained on a desktop using a dataset of suicide-related and non-suicide-related texts. The training outputs are then transferred to SWIFTopic for topic inference on iOS. Through prompt-engineered labels, the application classifies the inferred topics as either “suicide” or “non-suicide,” achieving a classification accuracy of 82%.
The dataset used is anonymized and sourced from publicly accessible platforms. It incorporates English Historical Quotes, Book Corpus, Simple Wikipedia LM, and posts from Reddit. The Reddit data specifically comes from Kaggle and other published research datasets, while the remaining data is sourced from Hugging Face. Reddit users are made aware that their posts are publicly accessible through Reddit’s Terms and Conditions. No personal identifying information (eg, names, locations, or IP addresses) were collected. Further, none of the authors participated in any discussions; thus, it was not necessary to inform users that their posts may be used for research. Because the collected data set is publicly available and already deidentified, it qualifies as “Not Human Research.”
Performance evaluation shows that SWIFTopic maintains a low memory footprint (0.9% RAM usage) and competitive latency (~500 ms) during inference. Although it is 14.5 times slower than remote inference, it trades off speed for privacy, providing acceptable response times while ensuring data security through local processing.
This thesis represents a significant advancement in on-device natural language processing and mobile software engineering, introducing a new framework that enables developers to build smarter iOS apps without compromising user privacy.