## 2 Segmentation-Enhanced Topic Modeling for Automated Text Annotation
### Text Segmentation with TopicDiff-LDA  
For its input, TopicDiff-LDA is fed \(N_{D}\) preprocessed documents, one document of \(n\) sentences a time. The algorithm utilizes the LDA model trained on the whole set of documents, as described in the previous section. The number of segments \(N_{S}\) in the collection is initially equal to \(N_{D}\). To identify topic-specific segments in the document, a sliding window with a minimum segment length of \(h\) sentences is implemented. Figure 2 illustrates the application of the window with \(h\) set at 3, where rectangles stand for sentences \(s_{i}\), \(i=1,\dots,n\), and shades indicate the scope of LDA model-based computing in each iteration. The vertical dotted line shows a candidate boundary \(b\) (set equal to \(h\) in the beginning) of two adjacent segments \(segA=[s_{1}\), \(s_{b}]\) (the darker shade) and \(segB=[s_{b+1}\), \(s_{b+h}]\) (the lighter shade). The size of \(segA\) grows (potentially reaching \(n-h\)) as \(b\) is incremented. The size of \(segB\) remains fixed (equal to \(h\)), with its left and right boundaries sliding to the right. Topic probability distributions of \(segA\) and \(segB\) are generated with the  
Figure 1: An overview of the proposed approach. LDA model, and stored in vectors \(X\) and \(Y\), respectively. To assess the semantic similarity of \(segA\) and \(segB\), the Manhattan distance \(dist=\sum_{i=1}^{m}\lvert X_{i}-Y_{i}\rvert\) is calculated (see [40] for a justification of the selected metric). The vector size \(m\) is equal to the number of topics in the trained LDA model (determined by the optimal coherence score \(c_{v}^{opt}\) obtained with an elbow method during the model development; see [41] but also [42]). When \(dist\) exceeds threshold \(t_{opt}=\underset{t}{\text{argmin}}\)\(perplexity_{N_{S}}(t)\), \(b\) is set as the boundary of a new topic-specific segment (i.e., \(segA\)) and \(N_{S}\) is incremented. The perplexity score for \(N_{S}\) segments in the whole document collection corresponding to a given distance threshold \(t\) is computed as \(perplexity_{N_{S}}=exp\left\{-\frac{\sum_{i=1}^{N_{S}}\log p(w_{i})}{\sum_{i=1} ^{N_{S}}N_{w_{i}}}\right\}\), where \(N_{w_{i}}\) denotes the number of words in segment \(i\), and \(\log p(w_{i})\) is the log-likelihood of words in the segment. The document processing is terminated when there are not enough sentences left to construct \(segB\). The algorithm is run recursively, as specified in Algorithm 1. ``` Input: documents, minimum segment size (\(h\)), LDA topic probability distribution Output: document segments (\(DS\)) Objective function:\(Perplexity(DS_{t})\), subject to \(\left\{t\in\mathbb{R}^{+},\ t\
eq 0\right\}\)
1: Initialize \(t_{sed}\)
2:\(DS_{t_{opt}}=\text{Search}(t_{sed})\)//call Search function
3: store the best solution: \(DS_{t_{opt}}\)
4:function\(\text{Search}(t_{sed})\)//returns \(DS_{t_{opt}}\)
5:initialize \(\delta=rand()\)
6:\(perpl_{min}=Perplexity(\text{Segmentation}(t_{sed}))\)//call Segmentation function
7:for(\(i=1\) to \(max\_iterations\))do
8:\(t_{i}=t_{i-1}+\delta\)
9:\(perpl_{i}=Perplexity(\text{Segmentation}(t_{i}))\)//call Segmentation function
10:if(\(perpl_{i}<perpl_{min}\)) then
11:\(t_{opt}=t_{i}\)
12:\(perpl_{min}=perpl_{i}\)
13: update \(\delta\)//determined by the specific optimization algorithm deployed
14:return(\(DS_{t_{opt}}\))
15:function Segmentation(\(t\))//returns segmented documents
16:initialize array \(DS_{t}\)
17:for each document do
18:\(s=\text{Sentence\_tokenize}(document)\)//split document into sentences
19:\(DS_{t}=\text{TS}(s,\ t,\ DS_{t})\)//call TS function
20:return(\(DS_{t}\))
21:functionTS(\(s,\ t,\ DS_{t}\))//returns segmented text
22:\(n=\text{Length}(s)\)//number of sentences
23:for(\(i=1\) to \(n\))do
24:\(b=i+h-1\)
25:if(\(b\leq\ n-h\)) then
26:\(segA=[s_{1},s_{b}]\)//define segA

Figure 2: The concept of a sliding window with \(h=3\) to define segment candidates in TopicDiff-LDA.