This section describes the development of BF-LLMA-SCD, comprising three main stages: preprocessing, LLM adaptation, and classification. As illustrated in
Figure 1, BF-LLMA-SCD receives a document containing a set of input sequences, denoted by
to
. These sequences are then passed to the preprocessing stage. Every two consecutive sequences form a pair, generating
pairs. These pairs serve as the refined input to the next stage. The LLM Adaptation component is powered by fine-tuning decoder-based LLMs for SCD. This stage generates contextualized representations, which are passed to the classification stage. This stage consists of one Fully Connected (FC) layer followed by the Sigmoid activation function to produce the final predictions
to
, which represent the state of the boundary’s style: changed or not changed. Each of these three stages is described in the following subsections.
Table 3 summarizes the key symbols used in this paper.
4.1. Preprocessing
One of the straightforward ways to represent a boundary is by concatenating two sequences as a single input separated by a separator token. The input sequences are converted into tokens before being processed. For BF-LLMA-SCD, the input length is 512 tokens, which represents a concatenation of two sequential sequences. Therefore, any input with a length less than 512 tokens will be padded using a special token. In larger cases, one of the truncation strategies can be applied. The only-first truncation strategy is the default one that truncates a token at a time from the first sequence to reach 256 tokens. However, if the length of the first sequence exceeds 512 tokens, only the first 512 tokens of this sequence will be processed, while the second sequence will be discarded. Thus, applying the only-first truncation strategy may lead to losing the boundary’s features and result in an incorrect representation. Therefore, another truncation strategy was applied for BF-LLMA-SCD, known as the boundary-focused strategy [
45]. It focuses on boundaries between sequences to enrich the representation of style changes. In contrast to the only-first truncation, this strategy considers both sequences and balances tokens between them. It preserves tokens located nearest to the boundary in both sequences, while discarding the remaining tokens.
Algorithm 1 explains the application of the boundary-focused strategy. It considers a list of documents and the maximum available length used for an LLM . The sequences are converted into tokens before measuring the lengths to perform an accurate truncation operation. The total length of the actual input sequences includes the special symbol in addition to the length of the two sequences. This separator is usually inserted between two sequences to indicate the boundary between them. For BF-LLMA-SCD, it helps the model to learn the separation between two writing styles. Focusing on boundaries during the truncation process occurs only if the total length of the two sequences is greater than the maximum length . Thus, the length of each sequence will be within the average length or less. A pair then contains the two truncated sequences separated by . Algorithm 1 returns a list of all pairs for every document in a dataset.
Figure 2 delineates an example of truncating input sequences. For simplification in this example, the maximum length is set to 15.
Figure 2 shows two sentences (the sentences were extracted from “PAN 2022/D3 \train \problem-3.txt” [
66]) with two truncation strategies: only-first and boundary-focused truncation. The tokenizer used in this example is for LLaMA 3. The only-first truncation results in a pair that contains only the first sequence because the input’s length exceeds 15, potentially overlooking crucial features of the boundary. The blue tokens in
Figure 2 represent the tokens selected using the only-first strategy. Conversely, boundary-focused truncation integrates the last six tokens from the first sequence with the first six tokens of the subsequent sequence. This strategy ensures a more consistent representation of the boundary. The yellow tokens in
Figure 2 represent the tokens selected by using the boundary-focused strategy.
| Algorithm 1 Boundary-focused strategy for BF-LLMA-SCD |
Input: : A dataset, : A maximum input length for an LLM, Output: : A list of pairs of sequences for each document in a dataset
- 1:
- 2:
for all
do - 3:
segmenting_paragraphs () //Text segmentation - 4:
for to ||−1 do - 5:
do_tokenizer(, ) - 6:
if (||+|| −3 ) > then - 7:
- 8:
- 9:
- 10:
Undo_tokenizer(,) - 11:
end if - 12:
+“”+ - 13:
.insert() - 14:
end for - 15:
end for - 16:
Return
|
4.2. Large Language Model Adaptation
LLaMA [
59] was adopted as a pen-source decoder-based LLM. It offers the flexibility of fine-tuning for SCD on all available SCD instances. To mitigate the limitations of requiring intensive resources, the Labeled optimizer Rate Adaptation (LoRA) method is adopted. All original LLM weights
are frozen. Instead, the LoRA adapter is updated, which consists of two weight matrices
B and
A, where
B∈
,
A∈
, and the rank
r is lower than
and
, as shown in Equation (
1). The initialization values of
B are zero, while
A uses a random Gaussian initialization.
After training LLMs with LoRA, the resulting
A and
B matrices are used to get the fine-tuned weight matrices
. The matrix multiplication operation is first performed on
A and
B matrices for all relevant layers. The resulting matrices are then added to the original weights
. Thus, the original weight matrices
in Equation (
1) are replaced by the fine-tuned weight matrices
in the test phase. Equation (
2) shows this final step in the fine-tuning process.
To initialize the LoRA adapter, the rank
r must be adjusted as a hyperparameter. It represents the number of linearly independent rows (or columns) in a matrix. Linearly independent rows (or columns) occur when they cannot be formed by a combination of other rows (or columns). It is worth noting that the rank is invariant when calculated using either rows or columns [
67]. For a lower-rank matrix, the number of linearly independent rows is less than the total number of its rows. This lower-rank matrix is useful for data compression during fine-tuning. To set an optimal
r value, Hu et al. [
68] have found that small
r values led to competitive results, and increasing
r values do not obtain significant improvements [
68]. Dettmers et al. [
5] also showed that the value of
r did not affect performance when LoRA was adopted in all LLM layers. Therefore, decreasing
r will reduce the number of parameters that must be fine-tuned as well as the memory usage. For BF-LLMA-SCD, the results of preliminary experiments were similar using different
r values. Thus, a small
r was adopted, which is 8.
Targeted weight matrices in LoRA are hyperparameters. Transformer-based LLMs have four weight matrices in the self-attention module and two in the MLP module. The weight matrices
,
, and
help transform input data into query, key, and value vectors, respectively, for computing attention scores. The fourth weight matrix
plays a role in transforming the output of the attention mechanism into a final output representation. MLP weight matrices apply nonlinear transformations. Although the LoRA adapter can be attached to any weight matrices, the original empirical investigation of Hu et al. [
68] for LoRA was conducted to fine-tune the weight matrices of the self-attention module and freeze the MLP modules. Hu et al. [
68] found that fine-tuning both
and
achieved almost similar performance to fine-tuning all four weights. For BF-LLMA-SCD, two weight matrices were adopted:
and
.
Despite adopting LoRA, BF-LLMA-SCD struggled with training and testing in our computing environment. Thus, Quantization LoRA (QLoRA) was adopted reduce resources and time consumption during LLM fine-tuning. Dettmers et al. [
5] introduced different QLoRA approaches, including 4-bit NormalFloat. The NormalFloat is a special data type for compressing a normal distribution of weights from a high-precision format into a smaller one. At the end of this process, the values are restored back to the higher precision. This compression seeks to handle memory efficiently and perform faster computations. Deciding the best value for compression is critical. Dettmers and Zettlemoyer [
69] studied quantization for LLMs. They conducted more than 35,000 experiments with 16-bit inputs and different
b-bit parameters, including 3, 4, 8, and 16 bits. They showed that adopting 4-bit precision achieved almost optimal accuracy. Therefore, 4-bit precision was adapted for BF-LLMA-SCD.
Figure 3 illustrates the self-attention components with LoRA in a single transformer-based LLM layer. It elaborates the architectural flow and focuses on how LoRA was integrated. The process begins with feeding the input embeddings
X resulting from the previous layer. This feeding comes in parallel to three distinct linear projection pathways: query, key, and value. The query and value projections demonstrate the application of LoRA. In these two projections, the input embeddings
X are passed into two parallel sub-paths. In the first sub-path, the original weights
∈
are multiplied by
X∈
, where
remains frozen during weight updates. In the second sub-path, the input embeddings
X are passed simultaneously through LoRA. It comprises two trainable matrices
A and
B.
A∈
performs a down-projection, where
r .
A is represented as an isosceles trapezoid where the shorter parallel side corresponds to the LoRA rank
r and the longer parallel side corresponds to the input dimension
.
B∈
performs an up-projection. It is represented as an isosceles trapezoid as well, where the longer parallel side corresponds to the output dimension
.
X is first multiplied by
A to be in the
r dimension, and the result is then multiplied by
B to be in the
dimension. During the forward pass, the output from
and the LoRA adapter paths are then element-wise summed via the addition operation represented by ⊕. The resulting matrix is then used for the subsequent attention computation. During the backward pass, gradients are updated only for
A and
B, where the frozen
are not updated.
4.3. Classification
Rich features extracted from a fine-tuned decoder-based LLM are fed into a classification layer. However, such LLMs are primarily designed for text generation, and were trained on the next token prediction task. Hence, such LLMs maintain a contextualized representation for every token, where the last hidden state is represented in a three-dimensional matrix. Therefore, pooling operations can be applied to this matrix to obtain a two-dimensional matrix for SCD.
Although a decoder-based LLM usually does not explicitly contain special tokens to aggregate representations of a sequence, such LLMs can be adopted for SCD by using a last-token method. Example LLMs with left-to-right attention are autoregressive models, which predict the next token in a sequence based on the previous tokens in the same sequence. Hence, the last token’s representations can accumulate the context of the entire sequence. For BF-LLMA-SCD, the last-token method takes the last non-padding token located in the last hidden state.
After that, the pooled representations extracted from the last LLM layers are fed into a classification layer. One FC layer was adopted as it was the most commonly used in SOTA solutions. The Sigmoid activation function was used. It is placed at the final layer before detecting changes using a threshold of 0.5 to round outputs to 0 and 1. It is noteworthy that LLMs provided on the Huggingface (
https://huggingface.co, accessed on 14 February 2026) platform are also equipped with a linear classification layer head on top of LLMs for classification tasks. This head adopts the last-token method as the pooling operation. Subsequently, a single FC, as a linear layer, is adopted in this head. BF-LLMA-SCD adopts this available head (AutoModelForSequenceClassification at
https://huggingface.co/transformers/v3.0.2/model_doc/auto.html, accessed on 14 February 2026).
4.4. Training and Testing
Algorithm 2 outlines the primary instructions used for fine-tuning BF-LLMA-SCD for SCD. It receives a dataset prepared for the training phase (
), a decoder-based LLM, the maximum available input length for the LLM (
), a learning rate for the model optimization (
), and the number of epochs (
). After preparing the dataset as pairs, each one is fed into the LLM followed by the classification layer to generate predictions. The optimizer uses gradients to update the model’s parameters. These parameters are returned after the training is completed. A loss function states the loss of predicting
. It obtains zero when the predicted change position
is equal to that of the ground-truth. Otherwise, the loss obtains a positive number, where a higher value indicates a greater deviation between the predicted and true positions, and vice versa. The binary cross-entropy loss function defined in Equation (
3) is commonly used in deep learning [
71].
N is the total number of boundaries and
is a ground-truth state for boundary
i, while
is a predicted state. The optimizer updates the learnable weights
based on the computed loss,
.
The computational complexity of Algorithm 2 is related to pairs in a dataset (
) and LLMs. The computational complexity of the latter is equal to the total number of learnable parameters [
72]. They include the parameters in embedding layers, a forward pass, a backward pass, and an optimizer update. For the forward pass, input sequences flow through the entire LLM, including the self-attention, MLP, and LoRA. The complexity of the self-attention part related to the query, key, value, and output projection matrices is
. MLP consists of two linear layers, where the first layer maps from the feature dimension
F to an expanded intermediate dimension 4
F, while the second layer performs the reverse. Thus, the total number of parameters of the weight matrix in MLP is
. It is noted that the number of layers in a transformer-based LLM is typically few. In particular, it does not exceed 24 layers within the models used in this thesis. Such models limit the length of a sequence to a specific number, with a maximum of 512 used in this paper. Thus, these two values are constant. Therefore, the computational complexity is
. Each LoRA adapter involves
with the size
, where
F. The use of LoRA also significantly reduced the memory footprint. Thus, the overall time complexity of the forward pass is
. The backward pass requires approximately twice as much computation as forward propagation because the gradients need to be propagated to both the weights and inputs. The optimizer updates two LoRA adapters for the query and value projections instead of all LLM parameters. The LoRA operations then consume
per transformer layer. For Algorithm 2, the complexity focusing on dominant terms is
.
| Algorithm 2 Training of BF-LLMA-SCD |
Input: : A training set, : A decoder-based LLM, : A maximum input length for the LLM, : Learning rate, : Number of epochs Output: : Learnable weights for BF-LLMA-SCD-based model
- 1:
Optimizing(, ) - 2:
LLM_load(, ) //Loading with 4-bit precision for QLoRA - 3:
8 //The rank for LoRA - 4:
[, ] //The targeted weight matrices for LoRA - 5:
LoRA (, r, ) - 6:
Algorithm 1 (, ) - 7:
for to do - 8:
for all do - 9:
() - 10:
FC() - 11:
Sigmoid() - 12:
binary_cross_entropy () - 13:
Optimizing(,, ) // is updated with this resulting - 14:
end for - 15:
end for - 16:
Return
|
Algorithm 3 shows the primary instructions used for evaluating the BF-LLMA-SCD-based model. It receives the learnable parameters to predict the changes in the writing style. The original weight metrics
are merged with the modified weights within LoRA. The performance of the BF-LLMA-SCD-based model is reported after being measured using identified metrics. Algorithm 3 involves only a single forward pass to predict a single output. Consequently, the computational complexity of Algorithm 3 dominated by the forward pass is
.
| Algorithm 3 Testing of LLMF-SCD |
Input: : A test set, : The maximum input length for LLMs, : Learnable weights for the LLMF-SCD-based model Output: : Performance of the BF-LLMA-SCD-based model
- 1:
//Predictions for all documents - 2:
LLM_load(, ) //Loading with 4-bit precision for QLoRA - 3:
8 //The rank for LoRA - 4:
[, ] //The targeted weight matrices for LoRA - 5:
LoRA (, r, ) - 6:
Algorithm 1 (, ) //Transition-focused strategy for LLMF-SCD - 7:
for all
do - 8:
(,) - 9:
FC() - 10:
Sigmoid() - 11:
for all do - 12:
- 13:
.insert() - 14:
end for - 15:
end for - 16:
do_metrics (, ) - 17:
Return
|