<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Incremental Mixture of Normalizing Flows for Dynamic Topic Modelling</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Federico Ravenda</string-name>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Andrea Raballo</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Antonietta Mira</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Fabio Crestani</string-name>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Science and High Technology, Insubria University</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Faculty of Biomedical Sciences, Università della Svizzera italiana</institution>
          ,
          <addr-line>Lugano</addr-line>
          ,
          <country country="CH">Switzerland</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>Faculty of Informatics, Università della Svizzera italiana</institution>
          ,
          <addr-line>Lugano</addr-line>
          ,
          <country country="CH">Switzerland</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>With the increasing availability of large-scale textual data in various domains, understanding the evolution of topics over time has become crucial for extracting meaningful insights and capturing the dynamic nature of information flow. In this work, we propose a model based on Mixtures of Normalizing Flows, able to extract topics from a collection of time-varying documents in a dynamic way. Our model takes as input embeddings generated by a pre-trained transformer-based language model for each timestamp, and learns the parameters of a complex high dimensional mixture density distribution, grouping documents into clusters, each representing a diferent topic. The parameters of the mixture distribution are updated at each timestamp and topic representations are generated using the TF-IDF procedure. A preliminary analysis shows that the topics generated using this procedure are competitive with those generated by state-of-the-art dynamic topic modelling.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Topic Modelling</kwd>
        <kwd>BERT</kwd>
        <kwd>Temporal Clustering</kwd>
        <kwd>Probabilistic Deep Learning</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        Topic models are useful tools for uncovering hidden thematic patterns and structures within a
collection of documents. Among the many models proposed, Latent Dirichlet Allocation (LDA)
[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], stands out as a prevalent and widely-used topic model. This probabilistic model represents
topics as distributions over words, while, simultaneously, characterizing each document as
a mixture of topics. By employing LDA, we can efectively capture the underlying structure
and relationships between words and topics, enabling a comprehensive understanding of the
content and composition of documents within a corpus.
      </p>
      <sec id="sec-1-1">
        <title>However, topics often change over time and it would be unrealistic to assume that documents</title>
        <p>from very diferent time instants would be generated by the exact same distribution. Thus, in this
paper we aim to design an architecture that would enable the modeling of topics that rise and fall
in popularity in time. Alternatively, topics that emerge and disappear, enabling the exploration
of the relationship between topics and external temporal factors. In fact, unlike traditional static
TOPIC 1
Find N most
Relevant
Words</p>
        <p>-0.14 -0.52 -0.41 -0.4 -0.54 0.32 -0.50 0.50 0.50 0.5
BERT -0.45 0.13 -0.05 0.32 0.49 -0.24 0.16 -0.05 -0.10 -0.54
2.68 0.85 1.34 1.05 0.04 -0.37 1.03 -0.90 -1.12 0.45</p>
        <p>TOPIC 2
Find N most
Relevant
Words</p>
        <p>CLUSTERING
MODEL
TOPIC 3
Find N most
Relevant
Words</p>
        <p>
          Timestep 1
Timestep 2
Timestep 3
topic models, Dynamic Topic Models (DTMs) are designed to capture the temporal dynamics and
changing patterns of topics within a document collection [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ].
        </p>
      </sec>
      <sec id="sec-1-2">
        <title>Diferent methodologies have emerged to streamline the creation of topics by leveraging</title>
        <p>
          word and document embeddings clustering [
          <xref ref-type="bibr" rid="ref3 ref4">3, 4</xref>
          ]. In particular BERTopic [
          <xref ref-type="bibr" rid="ref5">5</xref>
          ] is a
state-of-theart widely used topic modeling algorithm that utilizes BERT [
          <xref ref-type="bibr" rid="ref6">6</xref>
          ] embeddings and clustering
techniques to identify and extract meaningful topics from text data. It combines the power
of transformer-based language models and eficient clustering to provide a comprehensive
approach to topic modeling.
        </p>
        <p>In this work, a BERTopic-inspired approach is discussed and the pipeline of work is
summarised in Fig. 1 and in depth explained in Section 2. Unlike BERT in which clustering of
documents is carried out independently of their temporal nature, in the approach we propose
the idea is to study how the mixture distributions evolves over time (i.e. how components of
the mixture, which represent topics, change progressively) using time-varying collection of
documents.</p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>2. Methodology</title>
      <sec id="sec-2-1">
        <title>This section describes briefly the method we propose for the extraction of dynamic topics from data.</title>
        <sec id="sec-2-1-1">
          <title>2.1. Mixture of Normalizing Flows</title>
        </sec>
      </sec>
      <sec id="sec-2-2">
        <title>Normalizing Flows (NFs) [7] have emerged as a prominent class of generative models, ofering</title>
        <p>
          lfexible and tractable approaches for modeling complex data distributions. In this work, we
present a novel approach based on Mixture of Normalizing Flows [
          <xref ref-type="bibr" rid="ref8 ref9">8, 9</xref>
          ]. By combining the
benefits of mixture models and normalizing flows, based on preliminary analysis, the proposed
approach enables efective modeling of multivariate data with complex dependencies.
        </p>
      </sec>
      <sec id="sec-2-3">
        <title>Formally, a Mixture of Normalizing Flows represents a probability distribution as a mixture of</title>
        <p>transformed distributions, where each component in the mixture is associated with a particular
latent variable. The latent variable determines the choice of the component in the mixture, and
the transformed distribution captures the data distribution after applying a series of bijective
transformations.</p>
        <p>Consider a random variable  ∈ R representing the observed data, and a latent variable
 that follows a categorical distribution with  categories. Mixture of Normalising Flow is
defined as:</p>
        <p>() = ∑︁  ( = ) (| = )</p>
        <p>=1
where  ( = ) represents the prior probability of latent variable  taking the value , and
 (| = ) represents the likelihood of observed data  conditioned on the value of  = .</p>
        <p>
          Each  (| = ) is modeled as a transformed distribution, typically using a normalizing
lfow. A normalizing flow is a series of invertible transformations applied to a base distribution,
such that the resulting transformed distribution captures the complex data structure. For our
implementation we chose a Masked Autoregressive Flow (MAF) [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ] since it is well-suited for
modeling data with complex conditional distributions. Specifically we work with the following
mixture model:
        </p>
        <p>(; ) =  1 1(; 1) + . . . +   (; )
where the  components are fixed a priori. In practice, Mixture of Normalizing Flows are trained
by maximizing the log-likelihood of the observed data using techniques such as maximum
likelihood estimation or variational inference.</p>
        <sec id="sec-2-3-1">
          <title>2.2. From Static to Dynamic Topic Modelling</title>
        </sec>
      </sec>
      <sec id="sec-2-4">
        <title>The proposed model architecture consists of a mixture of normalizing flows, which is updated</title>
        <p>incrementally as new time steps as it is processed. At each time step, the documents in the
collection are fed into the existing model to learn the distribution. The initial model is trained
using the first time step, and subsequent time steps update the model incrementally. The scheme
used to train our model and update the parameters of the distribution over time is described in</p>
      </sec>
      <sec id="sec-2-5">
        <title>Algorithms 1 and 2 below.</title>
        <p>Algorithm 1 Training Process</p>
      </sec>
      <sec id="sec-2-6">
        <title>1: Initialization: Initialize the model with a single layer representing the first time step. Each</title>
        <p>layer consists of a mixture of normalizing flows capturing specific topics.</p>
      </sec>
      <sec id="sec-2-7">
        <title>2: Training: Train the initial layer using the documents from the first time step. Update</title>
        <p>the parameters of the mixture of normalizing flows using gradient-based optimization to
maximize the likelihood of the observed data.</p>
      </sec>
      <sec id="sec-2-8">
        <title>3: Clustering: Compute the likelihoods of the documents for each component in the mixture.</title>
      </sec>
      <sec id="sec-2-9">
        <title>Apply clustering techniques to identify the dominant topics for each time step based on the</title>
        <p>highest likelihood.</p>
      </sec>
      <sec id="sec-2-10">
        <title>4: Extracting Representative Words: All documents belonging to the same cluster are merged</title>
        <p>
          into a single large document. Once the large documents have been created, a TF-IDF [
          <xref ref-type="bibr" rid="ref11">11</xref>
          ]
matrix is calculated to represent the frequency of terms within the documents belonging to
the diferent clusters.
        </p>
      </sec>
      <sec id="sec-2-11">
        <title>Algorithm 2 Updating Scheme</title>
      </sec>
      <sec id="sec-2-12">
        <title>1: for timestamp i in [timestamp 2, . . . , timestamp T] do</title>
      </sec>
      <sec id="sec-2-13">
        <title>2: Freezing and Adding Layers: Freeze the weights of the initial layer to preserve the learned</title>
        <p>knowledge. Add a new layer to the model to capture the topics in the next time step.</p>
      </sec>
      <sec id="sec-2-14">
        <title>3: Training and Update: Train the new layer using the documents from the next time step.</title>
      </sec>
      <sec id="sec-2-15">
        <title>Optimize the parameters of the mixture of normalizing flows in the new layer using the same training process as described earlier.</title>
      </sec>
      <sec id="sec-2-16">
        <title>In summary, the proposed methodology involves training a mixture of normalizing flows for</title>
        <p>each time step, identifying dominant topics through clustering, extracting representative words,
and incrementally updating the model by freezing previous layers and adding new ones. This
iterative process allows to capture topics evolution and to analyse temporal dynamics in the
document collections.</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Analysis and Results</title>
      <sec id="sec-3-1">
        <title>In order to assess the goodness of the model we propose, we want to compare the results</title>
        <p>
          obtained with those in BERTopic’s Table 3 paper with respect to the Tweet’s Trump dataset (a
collection of 44’253 tweets, excluding retweets, from 2009 to 2021) in which BERTopic and LDA
Sequence (inspired by [
          <xref ref-type="bibr" rid="ref12">12</xref>
          ]) models are considered. Topic Coherence and Diversity metrics are
used as measures of model’s goodness.
        </p>
        <p>
          • Topic Coherence [
          <xref ref-type="bibr" rid="ref13">13</xref>
          ] measures the semantic coherence or interpretability of topics. It
quantifies how closely related the words within a topic are to each other. Higher values
indicate stronger semantic relatedness among the words in a topic, reflecting a more
coherent topic.
• Topic Diversity measures the distinctiveness or uniqueness of topics in a topic model. As
discussed in [
          <xref ref-type="bibr" rid="ref14">14</xref>
          ], it measures the percentage of unique words for all topics.
        </p>
      </sec>
      <sec id="sec-3-2">
        <title>The results we obtained are shown in Table 1. They are slightly worse than those obtained by</title>
      </sec>
      <sec id="sec-3-3">
        <title>BERTopic, but overperform LDA Sequence in both metrics. One of the reasons why metrics scores are lower than those of BERTopic could be that no fine-tuning operation is performed in the topic representations generated by our approach (in BERTopic diferent models are implemented e.g., GPT, KeyBertInspired, and Zero Shot Classifier).</title>
        <p>I-MoNF
LDA Sequence
BERTopic
Topic Coherence
0.072
0.009
0.079</p>
        <p>Topic Diversity
0.818
0.715
0.863</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4. Discussion and Future Works</title>
      <sec id="sec-4-1">
        <title>Our proposed model presents a temporal clustering approach based on mixtures of normalizing</title>
        <p>lfows, whose parameters dynamically evolve over time. One significant advantage of this
clustering model is its probabilistic nature, allowing us to infer the characteristics of topics
not only from the generated qualitative representations but also from the parameters of the
learned distribution over time. For instance, a change in the estimated mean could signify topic
evolution, while a small variance might represent a cohesive cluster, that is a coherent topic.</p>
      </sec>
      <sec id="sec-4-2">
        <title>Moreover, normalizing flows are particularly suitable for high-dimensional data, without any</title>
        <p>intermediate dimensionality reduction step.</p>
        <p>Even if preliminary results from our analysis demonstrate that the implemented model
performs to the level of the state-of-the-art dynamic topic models, future developments are to
be considered to be able to scale the model to larger collections of data and to improve the topic
representation. More specifically:
• It is necessary to evaluate the model on datasets traditionally used to assess the quality
of dynamic topic modeling models, to properly compare the model performance with
recognised standards.
• In order to obtain more consistent topic representations, a sliding window approach
would be useful.
• Considering the rise and fall of a new topic, think of adjusting the number of mixture
components based on the parameters provided by the learned distribution at each iteration.
• Consider exploring alternative deep probabilistic models instead of normalizing flows,
i.e., mixture of density networks, which are faster learning approaches.</p>
      </sec>
      <sec id="sec-4-3">
        <title>All of these will be part of future work.</title>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>D. M.</given-names>
            <surname>Blei</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. Y.</given-names>
            <surname>Ng</surname>
          </string-name>
          ,
          <string-name>
            <surname>M. I. Jordan</surname>
          </string-name>
          ,
          <article-title>Latent dirichlet allocation</article-title>
          ,
          <source>Journal of machine Learning research 3</source>
          (
          <year>2003</year>
          )
          <fpage>993</fpage>
          -
          <lpage>1022</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>S.</given-names>
            <surname>Bahrainian</surname>
          </string-name>
          ,
          <string-name>
            <given-names>I.</given-names>
            <surname>Mele</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Crestani</surname>
          </string-name>
          ,
          <article-title>Modeling discrete dynamic topics</article-title>
          ,
          <source>in: Proceedings of the ACM Symposium on Applied Computing, SAC</source>
          <year>2017</year>
          , Marrakech, Morocco, April 3-
          <issue>7</issue>
          ,
          <year>2017</year>
          ,
          <year>2017</year>
          , pp.
          <fpage>858</fpage>
          -
          <lpage>865</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>S.</given-names>
            <surname>Sia</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Dalmia</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S. J.</given-names>
            <surname>Mielke</surname>
          </string-name>
          ,
          <article-title>Tired of topic models? clusters of pretrained word embeddings make for fast and good topics too!</article-title>
          , arXiv preprint arXiv:
          <year>2004</year>
          .
          <volume>14914</volume>
          (
          <year>2020</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>D.</given-names>
            <surname>Angelov</surname>
          </string-name>
          ,
          <article-title>Top2vec: Distributed representations of topics</article-title>
          , arXiv preprint arXiv:
          <year>2008</year>
          .
          <volume>09470</volume>
          (
          <year>2020</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>M.</given-names>
            <surname>Grootendorst</surname>
          </string-name>
          , Bertopic:
          <article-title>Neural topic modeling with a class-based tf-idf procedure</article-title>
          ,
          <source>arXiv preprint arXiv:2203.05794</source>
          (
          <year>2022</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>J.</given-names>
            <surname>Devlin</surname>
          </string-name>
          , M.-
          <string-name>
            <given-names>W.</given-names>
            <surname>Chang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Lee</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Toutanova</surname>
          </string-name>
          , Bert:
          <article-title>Pre-training of deep bidirectional transformers for language understanding</article-title>
          , arXiv preprint arXiv:
          <year>1810</year>
          .
          <volume>04805</volume>
          (
          <year>2018</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>D.</given-names>
            <surname>Rezende</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Mohamed</surname>
          </string-name>
          ,
          <article-title>Variational inference with normalizing flows</article-title>
          ,
          <source>in: International conference on machine learning, PMLR</source>
          ,
          <year>2015</year>
          , pp.
          <fpage>1530</fpage>
          -
          <lpage>1538</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>G. G.</given-names>
            <surname>Pires</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M. A.</given-names>
            <surname>Figueiredo</surname>
          </string-name>
          ,
          <article-title>Variational mixture of normalizing flows</article-title>
          , arXiv preprint arXiv:
          <year>2009</year>
          .
          <volume>00585</volume>
          (
          <year>2020</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>S.</given-names>
            <surname>Ciobanu</surname>
          </string-name>
          ,
          <article-title>Mixtures of normalizing flows</article-title>
          ,
          <source>in: Proceedings of ISCA 34th International Conference on</source>
          , volume
          <volume>79</volume>
          ,
          <year>2021</year>
          , pp.
          <fpage>82</fpage>
          -
          <lpage>90</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>G.</given-names>
            <surname>Papamakarios</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Pavlakou</surname>
          </string-name>
          ,
          <string-name>
            <surname>I. Murray</surname>
          </string-name>
          ,
          <article-title>Masked autoregressive flow for density estimation</article-title>
          ,
          <source>Advances in neural information processing systems</source>
          <volume>30</volume>
          (
          <year>2017</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>J.</given-names>
            <surname>Ramos</surname>
          </string-name>
          , et al.,
          <article-title>Using tf-idf to determine word relevance in document queries</article-title>
          ,
          <source>in: Proceedings of the first instructional conference on machine learning</source>
          , volume
          <volume>242</volume>
          ,
          <string-name>
            <surname>Citeseer</surname>
          </string-name>
          ,
          <year>2003</year>
          , pp.
          <fpage>29</fpage>
          -
          <lpage>48</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <surname>D. M. Blei</surname>
            ,
            <given-names>J. D.</given-names>
          </string-name>
          <string-name>
            <surname>Laferty</surname>
          </string-name>
          ,
          <article-title>Dynamic topic models</article-title>
          ,
          <source>in: Proceedings of the 23rd international conference on Machine learning</source>
          ,
          <year>2006</year>
          , pp.
          <fpage>113</fpage>
          -
          <lpage>120</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>G.</given-names>
            <surname>Bouma,</surname>
          </string-name>
          <article-title>Normalized (pointwise) mutual information in collocation extraction</article-title>
          ,
          <source>Proceedings of GSCL 30</source>
          (
          <year>2009</year>
          )
          <fpage>31</fpage>
          -
          <lpage>40</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <surname>A. B. Dieng</surname>
            ,
            <given-names>F. J.</given-names>
          </string-name>
          <string-name>
            <surname>Ruiz</surname>
            ,
            <given-names>D. M.</given-names>
          </string-name>
          <string-name>
            <surname>Blei</surname>
          </string-name>
          ,
          <article-title>Topic modeling in embedding spaces, Transactions of the Association for Computational Linguistics 8 (</article-title>
          <year>2020</year>
          )
          <fpage>439</fpage>
          -
          <lpage>453</lpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>