Logo: to the web site of Uppsala University

uu.sePublications from Uppsala University
Change search
Link to record
Permanent link

Direct link
Magnusson, Måns
Publications (10 of 16) Show all publications
Yrjänäinen, V., Boström, I., Jonasson, J. & Magnusson, M. (2026). Posterior Sampling of Word Embeddings. Statistics and computing, 36, Article ID 232.
Open this publication in new window or tab >>Posterior Sampling of Word Embeddings
2026 (English)In: Statistics and computing, ISSN 0960-3174, E-ISSN 1573-1375, Vol. 36, article id 232Article in journal (Refereed) Published
Abstract [en]

We study Bayesian inference for probabilistic word embedding models, including skip-gram with negative sampling (SGNS) and continuous bag-of-words (CBoW). These models are widely used for inference, but their posteriors are non-identifiable under general linear transformations, which prevents meaningful Bayesian uncertainty quantification. We provide a simple and principled identifiability constraint that yields a well-defined posterior without altering the data model. Building on this, we develop scalable, fully Bayesian posterior sampling algorithms for SGNS and CBoW using Pólya–Gamma augmentation. Our block Gibbs samplers yield exact samples from the posterior and scale well to large corpora due to their straightforward parallelisation. We discuss the efficient implementation of the Gibbs sampler, and provide a fast TensorFlow reference implementation. In a combination of simulations and empirical experiments, we demonstrate that the sampler is both accurate and computationally efficient. It matches the accuracy of NUTS-HMC at a fraction of the computational cost and avoids the variance underestimation of mean-field variational inference. On large real datasets, we show that posterior means yield improved predictive performance, while posterior credible intervals provide meaningful uncertainty quantification for semantic similarity.

Place, publisher, year, edition, pages
Springer Nature, 2026
Keywords
Probabilistic Modelling, Markov Chain Monte Carlo, Bayesian statistics, Natural Language Processing, Gibbs sampling
National Category
Probability Theory and Statistics
Research subject
Statistics
Identifiers
urn:nbn:se:uu:diva-596087 (URN)10.1007/s11222-026-10996-5 (DOI)001901580800002 ()2-s2.0-105053322946 (Scopus ID)
Funder
Uppsala UniversityWallenberg AI, Autonomous Systems and Software Program (WASP)National Academic Infrastructure for Supercomputing in Sweden (NAISS)
Note

De två första författarna delar förstaförfattarskapet.

Available from: 2026-08-20 Created: 2026-08-20 Last updated: 2026-10-29Bibliographically approved
Hurtado Bodell, M., Magnusson, M. & Keuschnigg, M. (2026). Seeded Topic Models in Digital Archives: Analyzing Interpretations of Immigration in Swedish Newspapers, 1945–2019. Sociological Methods & Research, 55(1), 120-156
Open this publication in new window or tab >>Seeded Topic Models in Digital Archives: Analyzing Interpretations of Immigration in Swedish Newspapers, 1945–2019
2026 (English)In: Sociological Methods & Research, ISSN 0049-1241, E-ISSN 1552-8294, Vol. 55, no 1, p. 120-156Article in journal (Refereed) Published
Abstract [en]

Sociologists are discussing the need for more formal ways to extract meaning from digital text archives. We focus attention on the seeded topic model, a semi-supervised extension to the standard topic model that allows sociological knowledge to be infused into the computational learning of meaning structures. Seed words help crystallize topics around known concepts, while utilizing topic models’ functionality to identify associations in text based on word co-occurrences. The method estimates a concept’s shared interpretation (or framing) via its associations with other frequently co-occurring topics. In a case study, we extract longitudinal measures of media frames regarding immigration from a vast corpus of millions of Swedish newspaper articles from the period 1945–2019. We infer turning points that partition the immigration discourse into meaningful eras and locate Sweden’s era of multicultural ideals that coined its tolerant reputation.

Place, publisher, year, edition, pages
Sage Publications, 2026
National Category
Sociology (excluding Social Work, Social Psychology and Social Anthropology)
Identifiers
urn:nbn:se:uu:diva-548764 (URN)10.1177/00491241241268453 (DOI)001296403100001 ()2-s2.0-85201947374 (Scopus ID)
Funder
Swedish Research Council, 2018–05170Swedish Research Council, 2018–06063
Available from: 2025-01-28 Created: 2025-01-28 Last updated: 2026-05-13Bibliographically approved
Sargeant, H., Waldetoft, H. & Magnusson, M. (2025). Classifying Hate: Legal and Ethical Evaluations of ML-Assisted Hate Crime Classification and Estimation in Sweden. In: FAccT '25: Proceedings of the 2025 ACM Conference on Fairness, Accountability, and Transparency. Paper presented at 8th Conference on Fairness Accountability and Transparency - FAccT, June 23-26, 2025, Athens, Greece (pp. 195-208). Association for Computing Machinery (ACM)
Open this publication in new window or tab >>Classifying Hate: Legal and Ethical Evaluations of ML-Assisted Hate Crime Classification and Estimation in Sweden
2025 (English)In: FAccT '25: Proceedings of the 2025 ACM Conference on Fairness, Accountability, and Transparency, Association for Computing Machinery (ACM), 2025, p. 195-208Conference paper, Published paper (Refereed)
Abstract [en]

Hate crimes, driven by biases against specific demographic groups, harm not only individuals but undermine the security, trust, and cohesion of entire communities. Accurately identifying such crimes remains a significant challenge due to under-reporting, limited training, and the complexity of determining bias motivations. In this paper, we analyze the results of a text classification model developed to improve the precision of hate crime statistics and identification in Sweden. Empirical results indicate the model outperforms traditional manual police classification of hate crimes, achieving higher precision across various crime types and regions. We further disaggregate performance to pinpoint persistent challenges and highlight categories where both human and machine decision-makers struggle. While the model focuses on statistical estimation rather than direct case-level decision-making, we discuss the broader implications of algorithmic transparency, accountability, and explainability. Ultimately, this research illustrates how transformer-based neural networks can responsibly bolster the detection and understanding of hate crimes, informing policies to better protect vulnerable communities.

Place, publisher, year, edition, pages
Association for Computing Machinery (ACM), 2025
Keywords
Hate Crime Classification, Automated Crime Classification, Algorithmic, Bias, Criminal Justice, Responsible AI, Procedural Justice
National Category
Other Legal Research Computer Sciences
Identifiers
urn:nbn:se:uu:diva-567961 (URN)10.1145/3715275.3732016 (DOI)001543679300014 ()2-s2.0-105010813731 (Scopus ID)979-8-4007-1482-5 (ISBN)
Conference
8th Conference on Fairness Accountability and Transparency - FAccT, June 23-26, 2025, Athens, Greece
Available from: 2025-10-02 Created: 2025-10-02 Last updated: 2025-10-02Bibliographically approved
Sargeant, H., Östling, A. & Magnusson, M. (2025). Detecting Legal Citations in United Kingdom Court Judgments. In: Christos Christodoulopoulos, Tanmoy Chakraborty, Carolyn Rose, Violet Peng (Ed.), Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing: . Paper presented at 2025 Conference on Empirical Methods in Natural Language Processing, Suzhou, China (pp. 26810-26836). Association for Computational Linguistics
Open this publication in new window or tab >>Detecting Legal Citations in United Kingdom Court Judgments
2025 (English)In: Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing / [ed] Christos Christodoulopoulos, Tanmoy Chakraborty, Carolyn Rose, Violet Peng, Association for Computational Linguistics, 2025, p. 26810-26836Conference paper, Published paper (Refereed)
Abstract [en]

Legal citation detection in court judgments underpins reliable precedent mapping, citation analytics, and document retrieval. Extracting references to legislation and case law in the United Kingdom is especially challenging: citation styles have evolved over centuries, and judgments routinely cite foreign or historical authorities. We conduct the first systematic comparison of three modelling paradigms on this task using the Cambridge Law Corpus: (i) rule-based regular expressions; (ii) transformer-based encoders (BERT, RoBERTa, LEGAL-BERT, ModernBERT); and (iii) large language models (GPT-4.1). We produced a gold-standard high-quality corpus of 190 court judgments containing 45,179 fine-grained annotations for UK and non-UK legislation and case references. ModernBERT achieves a macro-averaged F1 of 93.3%, only marginally ahead of the other encoder-only models, yet significantly outperforming the strongest regular-expression baseline (35.42% F1) and GPT-4.1 (76.57% F1).

Place, publisher, year, edition, pages
Association for Computational Linguistics, 2025
National Category
Other Legal Research
Identifiers
urn:nbn:se:uu:diva-575931 (URN)10.18653/v1/2025.emnlp-main.1361 (DOI)
Conference
2025 Conference on Empirical Methods in Natural Language Processing, Suzhou, China
Available from: 2026-01-14 Created: 2026-01-14 Last updated: 2026-05-04Bibliographically approved
Sargeant, H. & Magnusson, M. (2025). Formalising Anti-Discrimination Law in Automated Decision Systems. In: FAccT '25: Proceedings of the 2025 ACM Conference on Fairness, Accountability, and Transparency. Paper presented at 8th Conference on Fairness Accountability and Transparency - FAccT, June 23-26, 2025, Athens, Greece (pp. 181-194). Association for Computing Machinery (ACM)
Open this publication in new window or tab >>Formalising Anti-Discrimination Law in Automated Decision Systems
2025 (English)In: FAccT '25: Proceedings of the 2025 ACM Conference on Fairness, Accountability, and Transparency, Association for Computing Machinery (ACM), 2025, p. 181-194Conference paper, Published paper (Refereed)
Abstract [en]

Algorithmic discrimination is a critical concern as machine learning models are used in high-stakes decision-making in legally protected contexts. Although substantial research on algorithmic bias and discrimination has led to the development of fairness metrics, several critical legal issues remain unaddressed in practice. The paper addresses three key shortcomings in prevailing ML fairness paradigms: (1) the narrow reliance on prediction or outcome disparity as evidence for discrimination, (2) the lack of nuanced evaluation of estimation error and assumptions that the true causal structure and data-generating process are known, and (3) the overwhelming dominance of US-based analyses which has inadvertently fostered some misconceptions regarding lawful modelling practices in other jurisdictions. To address these gaps, we introduce a novel decisiontheoretic framework grounded in anti-discrimination law of the United Kingdom, which has global influence and aligns closely with European and Commonwealth legal systems. We propose the "conditional estimation parity" metric, which accounts for estimation error and the underlying data-generating process, aligning with UK legal standards. We apply our formalism to a real-world algorithmic discrimination case, demonstrating how technical and legal reasoning can be aligned to detect and mitigate unlawful discrimination. Our contributions offer actionable, legally-grounded guidance for ML practitioners, policymakers, and legal scholars seeking to develop non-discriminatory automated decision systems that are legally robust.

Place, publisher, year, edition, pages
Association for Computing Machinery (ACM), 2025
Keywords
UK anti-discrimination law, algorithmic discrimination, algorithmic, fairness, machine learning, statistical decision-theory, estimation, error, epistemic uncertainty
National Category
Computer Sciences Statistics in Social Sciences
Identifiers
urn:nbn:se:uu:diva-567963 (URN)10.1145/3715275.3732015 (DOI)001543679300013 ()2-s2.0-105010834805 (Scopus ID)979-8-4007-1482-5 (ISBN)
Conference
8th Conference on Fairness Accountability and Transparency - FAccT, June 23-26, 2025, Athens, Greece
Available from: 2025-10-01 Created: 2025-10-01 Last updated: 2025-10-01Bibliographically approved
Magnusson, M., Torgander, J., Bürkner, P.-C., Zhang, L., Carpenter, B. & Vehtari, A. (2025). posteriordb: Testing, Benchmarking and Developing Bayesian Inference Algorithms. In: Li, Y Mandt; S Agrawal; S Khan, E (Ed.), International Conference on Artificial Intelligence and Statistics: . Paper presented at 28th International Conference on Artificial Intelligence and Statistics-AISTATS-Annual, May 03-05, 2025, Thailand. JMLR-JOURNAL MACHINE LEARNING RESEARCH
Open this publication in new window or tab >>posteriordb: Testing, Benchmarking and Developing Bayesian Inference Algorithms
Show others...
2025 (English)In: International Conference on Artificial Intelligence and Statistics / [ed] Li, Y Mandt; S Agrawal; S Khan, E, JMLR-JOURNAL MACHINE LEARNING RESEARCH , 2025Conference paper, Published paper (Refereed)
Abstract [en]

The general applicability and robustness of posterior inference algorithms is critical to widely used probabilistic programming languages such as Stan, PyMC, Pyro, and Turing.jl. When designing a new inference algorithm, whether it involves Monte Carlo sampling or variational approximation, the fundamental problem is evaluating its accuracy and efficiency across a range of representative target posteriors. To solve this problem, we propose posteriordb, 1 a database of models and data sets defining target densities along with reference Monte Carlo draws. We further provide a guide to the best practices in using posteriordb for algorithm evaluation and comparison. To provide a wide range of realistic posteriors, posteriordb currently comprises 120 representative models with data, and has been instrumental in developing several inference algorithms.

Place, publisher, year, edition, pages
JMLR-JOURNAL MACHINE LEARNING RESEARCH, 2025
Series
Proceedings of Machine Learning Research, ISSN 2640-3498 ; 258
National Category
Computer Sciences
Identifiers
urn:nbn:se:uu:diva-579310 (URN)001593416700134 ()
Conference
28th International Conference on Artificial Intelligence and Statistics-AISTATS-Annual, May 03-05, 2025, Thailand
Funder
Swedish Research Council, 2022-06725Swedish Research Council, 2022-03381
Available from: 2026-02-13 Created: 2026-02-13 Last updated: 2026-02-13Bibliographically approved
Sivula, T., Magnusson, M., Matamoros, A. A. & Vehtari, A. (2025). Uncertainty in Bayesian leave-one-out cross-validation based model comparison. Bayesian Analysis
Open this publication in new window or tab >>Uncertainty in Bayesian leave-one-out cross-validation based model comparison
2025 (English)In: Bayesian Analysis, ISSN 1936-0975, E-ISSN 1931-6690Article in journal (Refereed) Epub ahead of print
Abstract [en]

It is useful to estimate the expected predictive performance of models planned to be used for prediction. We focus on leave-one-out cross-validation (LOO-CV), which has become a popular method for estimating predictive performance of Bayesian models. Given two models, we are interested in comparing the predictive performances and associated uncertainty, which can also be used to compute the probability of one model having better predictive performance than the other model. We study the properties of the Bayesian LOO-CV estimator and the related uncertainty quantification for the predictive performance difference, and analyse when a normal approximation of this uncertainty is well calibrated and whether taking into account higher moments could improve the approximation. We provide new results of the properties both theoretically in the linear regression case and empirically for hierarchical linear, latent linear, and spline models and discuss the challenges. We show that problematic cases include: comparing models with similar predictions, misspecified models, and small data. In these cases, there is a weak connection between the distributions of the LOO-CV estimator and its error. We show that that the problematic skewness of the error distribution for the difference, which occurs when the models make similar predictions, does not fade away when the data size grows to infinity in certain situations. Based on the results, we also provide some practical recommendations for the users of Bayesian LOO-CV for comparing predictive performance of models.

Place, publisher, year, edition, pages
International Society for Bayesian Analysis, 2025
National Category
Probability Theory and Statistics
Identifiers
urn:nbn:se:uu:diva-575932 (URN)10.1214/25-BA1569 (DOI)
Available from: 2026-01-14 Created: 2026-01-14 Last updated: 2026-06-30Bibliographically approved
Sargeant, H. & Magnusson, M. (2024). Bias in Legal Data for Generative AI. In: Generative AI and Law (GenLaw’24’): . Paper presented at Generative AI and Law (GenLaw’24’), 27 July 2024, Vienna, Austria. The GenLaw Center
Open this publication in new window or tab >>Bias in Legal Data for Generative AI
2024 (English)In: Generative AI and Law (GenLaw’24’), The GenLaw Center , 2024Conference paper, Published paper (Other academic)
Abstract [en]

As large legal corpora become more abundant, itsuse in developing generative legal AI is poisedto transform the legal sector. However, the useof case law data necessitates a more critical ex-amination of the ethical and legal implicationsfor the development of generative legal AI tools.This research conducts a survey of various typesof bias, their sources, and potential impacts.

Place, publisher, year, edition, pages
The GenLaw Center, 2024
National Category
Other Legal Research Criminology
Identifiers
urn:nbn:se:uu:diva-548765 (URN)
Conference
Generative AI and Law (GenLaw’24’), 27 July 2024, Vienna, Austria
Available from: 2025-01-28 Created: 2025-01-28 Last updated: 2025-07-07Bibliographically approved
Yrjänäinen, V., Mohammadi Norén, F., Borges, R., Jarlbrink, J., Åberg Brorsson, L., Olsson, A. P., . . . Magnusson, M. (2024). The Swedish parliament corpus 1867–2022. In: Nicoletta Calzolari; Min-Yen Kan; Veronique Hoste; Alessandro Lenci; Sakriani Sakti; Nianwen Xue (Ed.), Proceedings of the 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024): . Paper presented at 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024), 20-25 May, 2024, Torino, Italy (pp. 16100-16112). European Language Resources Association
Open this publication in new window or tab >>The Swedish parliament corpus 1867–2022
Show others...
2024 (English)In: Proceedings of the 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024) / [ed] Nicoletta Calzolari; Min-Yen Kan; Veronique Hoste; Alessandro Lenci; Sakriani Sakti; Nianwen Xue, European Language Resources Association, 2024, p. 16100-16112Conference paper, Published paper (Refereed)
Abstract [en]

The Swedish parliamentary records are an important source material for social science and humanities researchers. We introduce a new research corpus, the Swedish Parliament Corpus, which is larger and more developed than previously available research corpora for the Swedish parliament. The corpus contains annotated and structured parliamentary records over more than 150 years, through the bicameral parliament (1867–1970) and the unicameral parliament (1971–). In addition to the records, which contain all speeches in the parliament, we also provide a database of all members of parliament over the same period. Along with the corpus, we describe procedures to ensure data quality. The corpus facilitates detailed analysis of parliamentary speeches in several research fields.

Place, publisher, year, edition, pages
European Language Resources Association, 2024
Series
International Conference on Computational Linguistics, ISSN 2951-2093
Keywords
parliamentary data, Sweden, political debate, language resource, politics, data curation
National Category
General Language Studies and Linguistics Natural Language Processing
Identifiers
urn:nbn:se:uu:diva-548701 (URN)001612977900623 ()978-2-493814-10-4 (ISBN)
Conference
2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024), 20-25 May, 2024, Torino, Italy
Available from: 2025-01-28 Created: 2025-01-28 Last updated: 2026-08-27Bibliographically approved
Kantanen, P., Bülow, E., Lahtinen, A., Magnusson, M., Paananen, J. & Lahti, L. (2024). Validating and Extracting Information from National Identification Numbers in R: The Case of Finland and Sweden. The R Journal, 16(3), 4-14
Open this publication in new window or tab >>Validating and Extracting Information from National Identification Numbers in R: The Case of Finland and Sweden
Show others...
2024 (English)In: The R Journal, E-ISSN 2073-4859, Vol. 16, no 3, p. 4-14Article in journal (Refereed) Published
Abstract [en]

National identification numbers (NIN) and similar identification code systems are widely used for uniquely identifying individuals and organizations in Finland, Sweden, and many other countries. To increase the general understanding of such techniques of identification, openly available methods and tools for NIN analysis and validation are needed. The hetu and sweidnumbr R packages provide functions for extracting embedded information, checking the validity, and generating random but valid numbers in the context of Finnish and Swedish NINs and other identification codes. In this article, we demonstrate these functions from both packages and provide theoretical context and motivation on the importance of the subject matter. Our work contributes to the growing toolkit of standardized methods for computational social science research, epidemiology, demographic studies, and other register-based inquiries.

Place, publisher, year, edition, pages
The R Foundation, 2024
National Category
Demography Information Systems, Social aspects
Identifiers
urn:nbn:se:uu:diva-562223 (URN)10.32614/RJ-2024-023 (DOI)001509263200002 ()2-s2.0-105008777534 (Scopus ID)
Available from: 2025-06-30 Created: 2025-06-30 Last updated: 2025-06-30Bibliographically approved
Organisations

Search in DiVA

Show all publications