# Topic Detection Based on Sentence Embeddings and Agglomerative Clustering with Markov Moment
## Methods
### Approximation-Estimation Test
Analytically, this moment can be detected as a point at which an incomplete (without a linear term) parabolic approximation becomes more precise than the linear one. In other words, in the neighborhood of this point, the quadratic error of incomplete parabolic approximation becomes smaller than the quadratic error of linear approximation. When clusters merge or one of the isolated points joins any of them, there should be a sharp jump in the minimum distance's numerical value. It is the moment when the clustering process is complete. At such a moment, the values of the set of minimum distances are more accurately approximated by an incomplete quadratic parabola (without a linear term), rather than the direct line [15; 16]. Within this approach, the iteration of the agglomerative process of clustering, at which there is a change in the nature of the increase in the function of minimum distances from linear to parabolic, is defined as the Markov stopping moment. We now turn to formal mathematical notation. Consider the set of minimum distances obtained after \(m-1\) iteration of any agglomerative clustering algorithm. It has the form \(\{F_{1},\,F_{2},\,\ldots,\,F_{m-1}\}\); for all of the agglomerative clustering methods, except for the centroid one, it is linearly ordered relative to numerical values of its elements: \(0\leq F_{1}\,\leq\,F_{2}\,\leq\,\ldots,\,\leq\,F_{m-1}\). We use this set to derive the statistical criterion for completing the clustering process in an arbitrary Euclidean space \(\mathbb{R}^{n}\). We use the previously constructed parabolic approximation-estimation test in order to determine the moment when the character of a monotonic increase in the numerical sequence changes from linear to parabolic [23; 24]. We distinguish between a linear approximation in the class of functions of the form \(l(x)=ax+b\) and an incomplete parabolic approximation (without a linear term) in the class of functions \(q(x)=cx^{2}+d\). The quadratic errors in \(k\) nodes for linear and incomplete parabolic approximation will be, respectively, equal to:  
\[\delta_{l}^{2}(k)=\sum_{i=0}^{k-1}(a\cdot i+b-y_{i})^{2};\qquad\delta_{q}^{2}( k)=\sum_{i=0}^{k-1}(c\cdot i^{2}+d-y_{i})^{2}. \tag{2}\]  
If, in our reasoning, the number of approximation nodes is not essential or obvious from the context, then the corresponding quadratic errors will simply be denoted by \(\delta_{l}^{2},\,\) and \(\delta_{q}^{2}\). When comparing \(\delta_{l}^{2}\) and \(\delta_{q}^{2}\), there are three possible cases: \(\delta_{q}^{2}<\delta_{l}^{2},\quad\delta_{q}^{2}>\delta_{l}^{2};\quad\delta_{ q}^{2}=\delta_{l}^{2}\). We say that the sequence \(y_{n}\) has linear increase at the nodes (points): \(y_{0},y_{1},\ldots,y_{k-1}\), if \(y_{n}\) is monotonic and the quadratic errors of linear and incomplete parabolic approximation over these nodes are related by the inequality: \(\delta_{q}^{2}>\delta_{l}^{2}\). If, under the same conditions, the inequality: \(\delta_{q}^{2}<\delta_{l}^{2}\), holds, then we say that the sequence \(y_{n}\) has parabolic increase at points: \(y_{0},y_{1},\ldots,y_{k-1}\). If, for a set of approximation nodes: \(y_{0},y_{1},\ldots,y_{k-1}\), the equality \(\delta_{q}^{2}=\delta_{l}^{2}\) holds, then the point \(y_{k-1}\) is called critical. We calculate coefficients \(a,b\) of a linear function \(ax+b\) and the coefficients \(c,d\) for an incomplete quadratic function \(cx^{2}+d\) approximating the nodes \(y_{0},y_{1},\ldots,y_{k-1}\)[23; 24]. First, using the method of least squares, we calculate the coefficients \(a,b\) of the linear function \(f(x)=ax+b\) approximating the nodes \(y_{0},y_{1},\ldots,y_{k-1}\).