Playing with Words at the National Library of Sweden -- Making a Swedish BERT
Summary
The authors, working at KBLab of the National Library of Sweden (KB), set out to build a Swedish-specific BERT, because multilingual models tend to underperform on smaller languages and suitable training data is scarce. They assembled a corpus of modern Swedish (1940s to late 2019) from KB's holdings: OCR'd newspapers, government reports (SOU), legal e-deposits, forum comments and Swedish Wikipedia. Before pre-training they cleaned the text heavily. They repaired systematic OCR errors using a lexicon, rebuilt sentences and paragraphs with spaCy plus custom scripts, and kept emojis as meaningful tokens. They then built a SentencePiece vocabulary and pre-trained the model with Google's original BERT code. On NER and POS tagging with the Stockholm-Umeå Corpus, the resulting KB-BERT beat both Google's M-BERT and an earlier Swedish model from Arbetsförmedlingen. The NER gains were clear, while the POS gains were marginal. The model is publicly released. The work shows that a national library's archives can supply a lower-resourced language with a strong base model, and that diverse registers in the corpus matter.
Key points
- The cleaned corpus has about 260M sentences, roughly 3,497M words and about 18.3 GB of text. Newspapers (allnews.txt, about 3.0B words) dominate, followed by SOU, e-deposit, social and sw-wiki. Fiction is underrepresented.
- The OCR repair targeted m ↔ rn confusions, such as "om" being turned into "örn" and "-arna" into "-ama". Candidates were checked against Saldo, the morphological resource from Språkbanken. Over 30,000 mappings were found, and about 13 million occurrences were corrected.
- The tokenizer is SentencePiece with a vocabulary of about 50k, chosen because Swedish has many compounds. Emojis and skin-tone modifiers were added to it by hand.
- Pre-training ran in three stages:
- 1M steps with sequence length 128 and batch size 512;
- 100k steps with sequence length 512 and batch size 128;
- roughly 1M more steps at 128/512.
- Compute came partly from in-house hardware and partly from Google TFRC Cloud TPUs, which were used only for non-copyrighted material.
- On NER (SUC 3.0, split 70/20/10), average FB1 was 0.927 for KB-BERT, 0.906 for M-BERT and 0.876 for AF-AI. HFST-SweNER is shown in the results but is not directly comparable. For POS, KB-BERT improved on M-BERT by less than 1%. NER showed little gain between 350k and 1M pre-training steps.
Interesting ideas
- I1. Lexicon-checked OCR repair. For a known confusion pair, generate the swapped spelling of each word. Add the swap to a correction table only when the original is missing from a morphological lexicon and the variant exists. This is cheap and targeted, and it could fit OCR'd Ukrainian or other Cyrillic archives with their own typical character confusions.
- I2. A minimum paragraph length as a noise filter. Fragments shorter than about ten sentences were discarded, along with broken sentences at paragraph edges. This removes context-poor OCR debris before pre-training.
- I3. Emojis as content and punctuation. Emojis were kept in the vocabulary and allowed to end sentences where they act as end punctuation. This is useful for any model expected to handle social-media text.
- I4. Diversity over sheer volume. The authors argue that adding small corpora of new registers (forums, official prose) helps robustness more than adding more of an existing genre. They report that messy social-media data seemed to help beyond that domain. This is a sensible principle when assembling corpora for any lower-resourced language.
- I5. Splitting compute by copyright status. Copyrighted material was trained in-house, while freely usable text went to external cloud compute. This is a practical pattern for institutions holding rights-restricted collections.
Cited by
- ARBERT & MARBERT: Deep Bidirectional Transformers for Arabic
- Bridging the Resource Gap: Exploring the Efficacy of English and Multilingual LLMs for Swedish
- BRAGD: Constrained Multi-Label POS Tagging for Faroese
Cite
@misc{malmsten2020playing,
title = {{Playing with Words at the National Library of Sweden -- Making a Swedish BERT}},
author = {Malmsten, Martin and Borjeson, Love and Haffenden, Chris},
year = {2020},
doi = {10.48550/arxiv.2007.01658},
eprint = {2007.01658},
archivePrefix = {arXiv},
url = {https://doi.org/10.48550/arxiv.2007.01658}
}References
- Ahearn, L. M. (2017). Living Language: An Introduction to Linguistic Anthropology. John Wiley & Sons, Chichester, second edition edition. find
- Anderson, B. (2016). Imagined Communities: Reflections on the Origin and Spread of Nationalism. Verso, London, revised edition edition. find
- Borin, L., Forsberg, M., and Lonngren, L. (2013). SALDO: a touch of yin to WordNet’s yang. Language Resources and Evaluation, 47(4):1191–1211, December. Place: Dordrecht Publisher: Springer WOS:000328213000011. ↗
- Branden, C., Möller, T., Pietsch, M., Soni, T., and Yeung, C. M. (2019). Open Sourcing German BERT: Insights into pre-training BERT from scratch. find
- Devlin, J., Chang, M.-W., Lee, K., and Toutanova, K. (2019). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. arXiv:1810.04805 [cs], May. arXiv: 1810.04805. ↗
- Honnibal, M. and Montani, I. (2017). spaCy 2: Natural language understanding with Bloom embeddings, convolutional neural networks and incremental parsing. To appear. find
- Kokkinakis, D., Niemi, J., Hardwick, S., Linden, K., and Borin, L. (2014). HFST-SweNER - A New NER Resource for Swedish. European Language Resources Assoc-Elra, Paris. Pages: 2537-2543 Publication Title: Lrec 2014 - Ninth International Conference on Language Resources and Evaluation WOS:000355611004025. find
- Kudo, T. and Richardson, J. (2018). Sentencepiece: A simple and language independent subword tokenizer and detokenizer for neural text processing. CoRR, abs/1808.06226. ↗ our card
- Linder, L., Jungo, M., Hennebert, J., Musat, C., and Fischer, A. (2020). Automatic Creation of Text Corpora for Low-Resource Languages from the Internet: The Case of Swiss German. arXiv:1912.00159 [cs], June. arXiv: 1912.00159. ↗
- Martin, L., Muller, B., Suárez, P. J. O., Dupont, Y., Romary, L., de la Clergerie, E. V., Seddah, D., and Sagot, B. (2020). CamemBERT: a Tasty French Language Model. arXiv:1911.03894 [cs], May. arXiv: 1911.03894. ↗ our card
- Pires, T., Schlinger, E., and Garrette, D. (2019). How multilingual is Multilingual BERT? arXiv:1906.01502 [cs], June. arXiv: 1906.01502. ↗ our card
- Rönnqvist, S., Kanerva, J., Salakoski, T., and Ginter, F. (2019). Is Multilingual BERT Fluent in Language Generation? arXiv:1910.03806 [cs], October. arXiv: 1910.03806. ↗
- Virtanen, A., Kanerva, J., Ilo, R., Luoma, J., Luotolahti, J., Salakoski, T., Ginter, F., and Pyysalo, S. (2019). Multilingual is not enough: BERT for Finnish. arXiv:1912.07076 [cs], December. arXiv: 1912.07076. ↗ our card
- Wolf, T., Debut, L., Sanh, V., Chaumond, J., Delangue, C., Moi, A., Cistac, P., Rault, T., Louf, R., Funtowicz, M., and Brew, J. (2019). Huggingface’s transformers: State-of-the-art natural language processing. ArXiv, abs/1910.03771. ↗ our card
- Wu, S. and Dredze, M. (2019). Beto, Bentz, Becas: The Surprising Cross-Lingual Effectiveness of BERT. arXiv:1904.09077 [cs], October. arXiv: 1904.09077. ↗ our card
This page in Markdown → https://md.research.elamur.ai/free/en/papers/malmsten-2020-playing-words-national-library-sweden/