Digitala Vetenskapliga Arkivet

Change search
CiteExportLink to record
Permanent link

Direct link
Cite
Citation style
  • apa
  • ieee
  • modern-language-association-8th-edition
  • vancouver
  • Other style
More styles
Language
  • de-DE
  • en-GB
  • en-US
  • fi-FI
  • nn-NO
  • nn-NB
  • sv-SE
  • Other locale
More languages
Output format
  • html
  • text
  • asciidoc
  • rtf
Literary Style Embeddings: A Contrastive Fine-tuning Approach on Long-Context Transformer Models for Literature in English
KTH, School of Electrical Engineering and Computer Science (EECS).
2025 (English)Independent thesis Advanced level (degree of Master (Two Years)), 20 credits / 30 HE creditsStudent thesisAlternative title
Litterära stilinbäddningar : Kontrastiv finjustering för långkontextuella transformermodeller inom engelsk litteratur (Swedish)
Abstract [en]

Text style embeddings prioritize writing style over semantics, with applications including recommendation systems and style-oriented retrieval. However, their use in long-context settings such as books remains under-explored, particularly regarding evaluation frameworks and the efficacy of fine-tuning in this domain. This thesis investigates contrastive fine-tuning for enhancing stylistic capture in long-context (512+ tokens) English literary embeddings, utilizing ModernBERT and gte-Qwen2-1.5B-instruct models. A long-context evaluation framework was developed, assessing performance on author/genre attribution (on publicly available literature and, for generalization, a dataset of works provided by BookBeat), a literature-adapted style similarity task (inspired by STEL-Or-Content) and stylometric regression. Results demonstrate that contrastive fine-tuning significantly improves model performance across all tasks and context lengths. On Project Gutenberg books, full-book author attribution accuracy increased by 8.6% (ModernBERT) and 4.1% (gte-Qwen2) post fine-tuning, with respective gains of 5.2% and 2.7% on the BookBeat dataset. The style similarity task (512 tokens) showed accuracy boosts of 5.7% (ModernBERT) and a substantial 33.5% (gte-Qwen2), while maintaining good semantic performance in stylistically identical scenarios, unlike dedicated style embedding models such as StyleDistance. Notably, while longer inference contexts generally improve performance, the benefit of using long contexts during the fine-tuning process itself was found to be negligible. Stylometric analysis further revealed that the fine-tuned ModernBERT improved regression across all categories, in contrast to the gte-Qwen2-based model which showed no notable change. By integrating these findings with comparisons to existing style embedding research, this work offers a method and insights for future research and industry applications in literary style analysis.

Abstract [sv]

Stilinbäddningar prioriterar skrivstil över semantik, med tillämpningar inom rekommendationssystem och stilorienterad sökning. Dock är deras tillämpning och utvärdering på långa texter, såsom böcker, outforskat. Denna uppsats utforskar kontrastiv finjustering för att förbättra stilfångst i långa engelska böcker (512+ tokens), med användning av ModernBERT och gte-Qwen2-1.5B-instruct då dessa modeller kan hantera långa texter. Vidare skapades ett nytt utvärderingsramverk, som bedömde prestanda på identifiering av författare på böcker från Project Gutenberg samt på ett dataset från BookBeat, en litteraturanpassad stillikhetsuppgift (inspirerad av STEL-Or-Content) och stilometrisk regression i långkontextuella förhållanden. Resultaten visar att kontrastiv finjustering avsevärt förbättrar modellprestanda på alla uppgifter och textlängder. På Project Gutenberg, ökade hela böckers författar-identifiering med 8,6% (ModernBERT) och 4,1% (gte-Qwen2) efter finjustering, respektive 5,2% och 2,7% på BookBeats verk. Stillikhetsuppgiften (512 tokens) visade förbättringar på 5,7% (ModernBERT) och 33,5% (gte-Qwen2), samtidigt som semantisk prestanda bibehölls i stilistiskt identiska scenarier, till skillnad från existerande stilinbäddningsmodeller såsom StyleDistance. Noterbart är att medan längre inferenskontexter generellt förbättrar prestanda, var nyttan av att använda långa texter under själva finjusteringen försumbar. Stilometrisk analys visade att den finjusterade ModernBERT förbättrade regressionen inom alla kategorier, i kontrast till den gte-Qwen2-baserade modellen som inte visade någon märkbar förändring. Detta arbete framhåller metodik och insikter för framtida forskning och industritillämpningar inom litterär stilanalys.

Place, publisher, year, edition, pages
2025. , p. 97
Series
TRITA-EECS-EX ; 2025:380
Keywords [en]
Style Embeddings, Long Context, Contrastive Learning, Author Attribution, Stylometrics, Fine-tuning
Keywords [sv]
Stilinbäddningar, Lång kontext, Kontrastiv inlärning, Författaridentifiering, Stilometri, Finjustering
National Category
Computer and Information Sciences
Identifiers
URN: urn:nbn:se:kth:diva-368247OAI: oai:DiVA.org:kth-368247DiVA, id: diva2:1987984
External cooperation
BookBeat AB
Supervisors
Examiners
Available from: 2025-08-10 Created: 2025-08-09 Last updated: 2025-08-10Bibliographically approved

Open Access in DiVA

fulltext(5064 kB)678 downloads
File information
File name FULLTEXT01.pdfFile size 5064 kBChecksum SHA-512
e02a41a0f48eb1d5304e424b74e7deb9187f9212ce1c404def798977005431f65b825891368238d5eaba68f55f18a694d048e7953d2729cab618c78148256daf
Type fulltextMimetype application/pdf

By organisation
School of Electrical Engineering and Computer Science (EECS)
Computer and Information Sciences

Search outside of DiVA

GoogleGoogle Scholar
Total: 679 downloads
The number of downloads is the sum of all downloads of full texts. It may include eg previous versions that are now no longer available

urn-nbn

Altmetric score

urn-nbn
Total: 1084 hits
CiteExportLink to record
Permanent link

Direct link
Cite
Citation style
  • apa
  • ieee
  • modern-language-association-8th-edition
  • vancouver
  • Other style
More styles
Language
  • de-DE
  • en-GB
  • en-US
  • fi-FI
  • nn-NO
  • nn-NB
  • sv-SE
  • Other locale
More languages
Output format
  • html
  • text
  • asciidoc
  • rtf