In the last few years, the internet has become the main source for news for citizens both in EU [3] and in USA [4] . Such a rapid change in the media system has created a symmetric change in the way news are delivered: before the diffusion of the web, information was intermediated by journals, newspapers, radio and TV newscast, that represented the authority, being publicly responsible for the diffusion of reliable news. Nowadays, such intermediation is not present anymore: every blog or account on Facebook or Twitter assumes truthfulness just for existing online [5] [6] [7] [8] . Due to this abrupt change of paradigm in the fruition of news, we observe a great increase of the diffusion of misinformation [9] [10] [11] , that appears on the web via the use of automated [12] [13] [14] [15] [16] [17] [18] or genuine accounts [6, [18] [19] [20] [21] [22] . It has been observed that the diffusion of disinformation or misinformation campaigns leans on the emotionality of users [5, 6, 8, 23] .
Twitter is one of the most famous microblogging service, where people freely express their views and feelings in short messages, called tweets [24] . Twitter is reknown to be used especially for the political communications [25] , due to the limited amount of characters, perfectly suitable for political slogans, and for the quick sharing of messages. Due to the availability of its data, via the official API, it represents an extremely rich resource of "spontaneous emotional information" [26] . Sentiment analysis, also known as opinion mining, is a collection of techniques in order to automatically detect the positive or negative connotation of texts. An overview of the latest tools, updates and open issues in sentiment analysis can be found in [27] [28] [29] (see also the references therein). Some examples of applications, where predictions are formulated based on the sentiment extracted from on-line texts are provided in [30] [31] [32] [33] [34] [35] [36] [37] . In [38] , sentiment analysis is used to investigate the emotion transmission in e-communities; while in [39] , it is employed in order to investigate on the interplay between macroscopic socio-economic, political or cultural events and the public mood trends, showing that these events have a significant and immediate effect on various aspects of public mood. The Ref. [26] provides a matrix-factorization method to predict individuals' opinions toward specific topics they had not directly given. In [40] , the authors consider the sentiment curve of Twitter posts along time in order to infer the causes of sentiment variations, leveraging on the idea that the emerging topics discussed in the variation period could be highly related to the reasons behind the variations. In [41] , the authors present the data prediction as a process based on two different levels of granularity: i) a fine-grained analysis to make tweet-level predictions on various aspects, such as sentiment, topics, volume, location, timeframe, and ii) a coarse-grained analysis to predict the outcome of a real-world event, by aggregating and combining the fine-grained predictions. With respect to this classification, the present work can be placed in the stream of literature regarding the fine-grained analysis to model/predict the sentiment of Twitter posts.
While an important body of research target the issue of predicting the information cascades [42] [43] [44] [45] [46] [47] [48] [49] , to the best of our knowledge, there are not works that provide models for the evolution of Twitter sentiment. We aim at filling in this gap, presenting a model that is able to reproduce the sentiment curve of the tweets related to specific topics and periods and to provide a prediction of the sentiment of the future posts based on the observed past. We achieve this purpose employing a recent variant of the Pólya urn, introduced in [1] and called Rescaled Pólya (RP) urn. In brief, the RP urn model differs from the standard Pólya urn for the presence of a "local" reinforcement, i.e. elements that are recently observed have a greater impact on the near future and may be identified as the "fashion" of the moment. In the online social networks applications, this local reinforcement aims at representing the persistence of an emotional response to a public event, capturing the phenomenon observed in [5] . Moreover, it is able to correctly reproduce the sentiment dynamics of the tweets, outperforming the standard Pólya urn model, as we will see, on several different data sets. Its prediction ability is also quite high. Finally, it is worthwhile to underline that the proposed model may be also employed in other contexts.
The sequel of the work is so structured. In Section 2 we will present the model: after introducing the standard Pólya model in Subsection 2.1, in Subsection 2.2 we formally describe the Rescaled Pólya urn model in general. Then, we focus on the case with two colors and, next to the general model (Complete model), we identify two special cases ("Only fashion" model and "No fashion" model). In Section 3, we describe the considered datasets and we illustrate the performed analysis and the obtained results. Finally, in Section 4 we comment the results and draw our conclusions. The paper is enriched by an appendix regarding the evolution of the estimated model parameters.
The standard Pólya urn (see [50] [51] [52] ) is a stochastic model driven by a reinforcement mechanism (also known as "rich get richer" principle): the probability that a given event occurs increases with the number of times the same event occurred in the past. This rule is a key feature governing the dynamics of many biological, economic and social systems (see, e.g. [52] ) and it seems plausible that it plays a role also in the sentiment dynamics of the Twitter posts as the emotional state of an individual influences the emotions of others [38, 53] . The Pólya urn model has been widely studied and generalized (some recent variants can be found in [1, 2, [54] [55] [56] [57] [58] [59] [60] [61] [62] [63] [64] [65] ) and in its simplest form, with k-colors, works as follows. An urn contains N 0 i balls of color i, for i = 1, . . . , k, and, at each discrete time, a ball is extracted from the urn and then it is returned inside the urn together with α > 0 additional balls of the same color. Therefore, if we denote by N n i the number of balls of color i in the urn at time n, we have
where ξ n i = 1 if the extracted ball at time n is of color i, and ξ n i = 0 otherwise. The parameter α regulates the reinforcement mechanism: the greater α, the greater the dependence of N n i on n h=1 ξ h i .
The "Rescaled" Pólya (RP) urn model, introduced in [1] , is characterized by the introduction of the parameter β, together with the initial parameters (b 0 i ) i=1,...,k and (B 0 i ) i=1,...,k , next to the parameter α of the original model, so that
Therefore, the urn initially contains b 0 i +B 0 i > 0 balls of color i and the parameter β ≥ 0, together with α > 0, regulates the reinforcement mechanism. More precisely, the term βB n−1 i links N n i to the "configuration" at time n − 1 through the "scaling" parameter β, and the term αξ n i links N n i to the outcome of the extraction at time n through the parameter α. Note that the case β = 1 corresponds to the standard Pólya urn with an initial number N 0 i = b 0 i + B 0 i of balls of color i. When β ∈ [0, 1), this variant of the Pólya urn is characterized by a "local" reinforcement, i.e. a reinforcement mechanism mainly based on the most recent observations, and by a random persistent fluctuation of the predictive mean ψ n i = E[ξ n+1 i = 1| "past"]. As we will show, this latter feature is capable of capturing the trend fluctuations in the sentiment curve of Twitter posts (see Figs. 1-6).
More formally, given a vector x = (x 1 , . . . , x k ) ∈ R k , we define |x| = k i=1 |x i |. Moreover, we set b 0 = (b 0 1 , . . . , b 0 k ) and B 0 = (B 0 1 , . . . , B 0 k ) , we assume |b 0 | > 0 and we define p 0 = b0 |b0| . At each discrete time (n + 1) ≥ 1, a ball is drawn at random from the urn, obtaining the random vector ξ n+1 = (ξ n+1 1 , . . . , ξ n+1 k ) defined as ξ n+1 i = 1 when the extracted ball at time n + 1 is of color i 0 otherwise .
The number of balls in the urn is so updated:
Therefore, setting r * n = |N n | = |b 0 | + |B n |, we get
Moreover, denoting by F = (F n ) n≥0 the filtration representing the information along time (formally, this means to set F 0 equal to the trivial σ-field and F n = σ(ξ 1 , . . . , ξ n ) for n ≥ 1), the conditional probabilities ψ n = (ψ n 1 , . . . , ψ n k ) of the extraction process, also called predictive means, are
This urn model has been studied in [1, 2] . All the mathematical proofs and details can be found in these papers.
With two colors, the quantity of interest are only ξ n = ξ n 1 = 1 − ξ n 2 and ψ n = ψ n 1 = 1 − ψ n 2 .
In the sequel, we consider the RP urn model with β = 1 (i.e. the standard Pólya urn model) and with β < 1. In the first case, we have
In the second case, by (1), (2), (3) and (4), using
Since β < 1, the dependence of ψ n on ξ h exponentially increases with h, because of the factor β n−h , and so the main contribution is given by the most recent extractions. We refer to this phenomenon as "local" reinforcement. The case β = 0 is an extreme case, for which ψ n depends only on the last extraction ξ n . Note that, when β = 1, i.e. the case of the standard Pólya urn, all the past observations ξ h equally contribute to ψ n , with a weight equal to α. This different dependence on the past leads to a different behaviour of ψ n along time (see [1] ): in the standard Pólya urn, the process (ψ n ) asymptotically stabilizes, converging almost surely toward a random variable, while in the RP urn, the process (ψ n ) persistently fluctuates (see Figs. 1-6). If we set
we get for a large n
Summing up, the model dynamics can be approximated for n large by
where p 0 , γ * , β, B 0 are the parameters. Note that α does not appear among the parameters for the above approximated dynamics, but it is included in the new parameter γ * . Moreover, the quantity B 0 is exponentially fast negligible, because we have B n = β n B 0 + (1 − β) n k=1 β n−k ξ k , with β < 1. Therefore, the fundamental parameters are p 0 , γ * and β: p 0 is a deterministic component, γ * tunes the weight in the predictive mean ψ n+1 of the random "fluctuation" component B n+1 with respect to the deterministic one, and β regulates the dependence of the present state B n+1 on the previous state B n and on the present observation ξ n+1 . We refer to ( B n ) n as the "fashion" process, since it reproduces the trend variations of the considered phenomenon (in our case, the sentiment of Twitter posts) . In the following applications, we consider the following cases:
• Complete RP model: The three parameters θ = (p 0 , γ * , β) are free to vary.
• "Only Fashion" RP model: γ * = 1 (and p 0 = 0 irrelevant). This means that the predictive mean is not driven by any deterministic component, but it coincides with the fashion process. The free parameter is given by θ = β. • "No Fashion" RP model: γ * = 0 (and β = 0 irrelevant). In this case ψ n is equal to the constant p 0 and, consequently, the free parameter is given by θ = p 0 .
Data have been collected from the Twitter platform, using the official API to Stream the exchange of messages on several topics. In the following, the various datasets are described in more details.
• Italy, Migration debate Data were collected through the Filter API since 23rd of January to 22nd of February 2019 and targeted the Italian debate on migration. Data were previously analysed in [18] . In the dataset, the information about the nature, automated or not, of the users is present. The bot detection algorithm embedded is a lightweight version of the classifier proposed in [12] ; more details on the dataset can be found in [18] . • Italy, 10 days of traffic
The dataset collects the entire traffic, compatibly with the Filter API sampling, of messages in Italian in the days from the first to the 10th of September 2019: the keyword used for the query were the Italian vowels, in order to collect all messages that may contain some word. The bot detection algorithm used was developed in [16] . • Italy, COVID-19 epidemic
The dataset covers the period from February 21st to April to 20th 2020, including tweets in Italian language, and was previously analysed in [22] . The keywords used for the query are relative to the COVID-19 epidemic; more details can be found in the original reference. The dataset includes information on the automated or not nature of the accounts, detected using the algorithm developed in [16] .
For every message, the relative sentiment was calculated using the polyglot python module developed in [66] . This module provides a numerical value v for the sentiment and we fix a threshold T = 0.35 so that we classify as a tweet with positive sentiment those with v > T and as a tweet with negative sentiment those with v < −T . We discard tweets with a value v ∈ [−T, T ]. Tables 1-3 show some descriptives of the considered datasets: 
We apply the RP model with k = 2: the time series of the tweets represents the time series of the extractions from the urn, that is the random variables ξ n . The event {ξ n = 1} means that tweet n exhibits a positive sentiment, while {ξ n = 0} means that tweet n exhibits a negative sentiment. The parameters have been estimated by maximum likelihood. More precisely, we have divided the observations into S slots. For each slot s = 1, . . . , S − 1, with training data of the slots t = 0, . . . , s − 1, we have estimated the best parameters θ(s) for the different proposed models: Standard Pólya, Complete RP, Only Fashion RP, No Fashion RP. (See Appendix, Sec. A for a further discussion.) With these parameters, for each observation ξ n+1 of the s-th slot, we have estimated the probability ψ n , that is the predictive mean, as a function of the estimated parameters and of the observed history ξ 1 , . . . , ξ n . The predictive mean ψ n represents our prediction of the future value ξ n+1 . We have quantified the ability of the considered model to predict the future outcomes by means of the relative squared error with respect to the method that predicts the future outcome taking the value assumed by the majority in the past. More precisely, we have computed the following quantity: 
where N is the size of the dataset and m s is the value assumed by the majority in the slots 0, . . . , s − 1. This quantity measures the ability of the model to predict the future outcomes: the greater it is, the better is the prediction with respect to the method based on the past majority. The values SS rel obtained for the different considered models are also compared with the "theoretical" value of SS rel computed replacing ψ n byψ = N n=[N/S]+1 ξ n /(N − [N/S]), that is the mean value on all the period between [N/S] + 1 and N . The term "theoretical" is used in order to point out thatψ is of course not a prediction, but it gives the a posteriori best constant fit once we have collected all the data until time N . Summing up, our aim is twofold: to obtain a value of SS rel greater than 1, that means that the considered models beat the performance of the method based on the majority, and to get a value greater or equal to the "theoretical" value, that means that the proposed models perform better or similarly than the (theoretical) a posteriori best constant fit.
We summerize the results in Tables 4-6 . For each considered dataset, we have also analysed the subset obtained by the restriction to the tweets classified as sent by a bot. In the tables the best values are highlighted in bold. We can observe that, for the "Migration" and "Covid" datasets, the considered models perform more or less two times better than the method based on the majority and this performance is similar to (indeed, in the most cases slightly better than) the one given by the (theoretical) a posteriori best constant fit. For the "10 days traffic" dataset, the performance of the considered models is one and half times better than the method based on the majority and this performance is similar to the one given by the (theoretical) a posteriori best constant fit. Moreover, the performances of the "Complete RP" model and of the "Only fashion RP" model do not significantly differ; while the "No Fashion RP" model performs less well. Therefore, in the next subsection, we will discard this last model. 
We provide some tables and figures in order to point out how the different considered models are able to reproduce the trend fluctuation of the sentiment curve. More precisely, in Figures 1-6 
where ξ n+1 and ψ n refer to the values on the curves with a given smoothing. We can observe that, as explained before in Section 2.2, the RP urn model is able to reproduce the fluctuations of the observed sentiment curve, while the standard Pólya urn model produces a curve that converges to a value. 
Online Social Networks (OSN) represent a perfect environment for the study of the emotional reaction to public events. It has been observed that the sentiment of a message may be a driver for the diffusion of a message in online social networks [5, 6, 8, 23] . Interestingly, Ref. [5] shows that, on different arguments, the sensitivity, i.e. the emotional reaction to the event, finds a sort of stability.
Leveraging on this feature of the online debate, we apply here a modification of the Pólya urn model, embedding a "local" reinforcement effect [1, 2] , representing a sort of "fashion" contribution and capturing the persistence of a common sentiment. Similarly to the standard Pólya urn, the future outcome depends on the entire story, but, differently from the original model, in the Rescaled Pólya urn, the influence of the recent outcomes has a greater impact on future extractions. This represents the "fashion" effect and its introduction properly captures the evolution of the sentiment of the online debate. The results collected in Section 3 show that indeed the Rescaled Pólya model outperforms greatly the standard Pólya model. Moreover, the RP urn model permits to have reliable predictions from past observations: in particular, the model parameters are fitted using the data from all the previous slots, thus capturing a sensitivity to a certain emotional reaction for the argument, as in [5] . In this sense, when we focus on a single argument, as in the case of the Migration or Covid data sets, we have better results than when the argument is not specified, as in the case of 10 days traffic data set. Summarising, the present paper has essentially two targets: to propose a novel model for the prediction of the sentiment in the online debate and to examine and study the implications of the Rescaled Pólya urn. Building a simple and realistic model improves our understanding of the phenomenon: in the particular case, the presence of a local reinforcement, i.e. the "fashion" effect described above, shows how persistent is the emotional reaction to a public event. It is worth to be mentioned that the application to Online Social Media is one of the possible applications of the proposed RP urn model: due to its abstractness and generality, it can be applied to any kind of phenomenon showing a local "fashion" behaviour. As it can be observed from the evolution of the model parameters, all of them converge smoothly to a fixed value. Estimating the parameters using only the closest slots, is going to be the target of near future research.
Giacomo Aletti and Irene Crimaldi contributed to the theoretical definition of the Rescaled Pólya urn model; Fabio Saracco performed the data collection and cleaning; Giacomo Aletti performed the simulation; all the authors wrote, revised and approved the manuscript. 
As it is mentioned in the main text, in order to fit the parameters of the model, we divided the entire dataset in time slots. Next, we use all slots previous to the one under consideration to fit the parameters. In this sense, we observe an evolution of the parameters as a matter of the evolution of the datasets, which is different when focusing on the different nature of users in the debate. Such a difference is particularly evident in the Migration debate. Human accounts show a nearly constant parameter dynamics: while β is nearly constant in the Complete model, γ * and p 0 display a smooth slow variation of nearly the 10% of their value, see Fig. 7 . The dynamics of the parameters for automated accounts is completely different, see Fig. 8 : in the Complete model, while β is slowly decreasing (but still experiencing a much greater decrease than the one observed for human accounts), parameters γ * and p 0 display a step-like dynamics, ending shortly after S = 25. A similar, but less evident, dynamics can be observed in the "10 days of traffic" dataset, see Fig. 9 and 10: in this case, all parameters converge to 1 quite soon in the case of the entire dataset. Instead, we can see that p 0 converge, but to something more than 0.6 quite immediately for the social bot subset, while the value of γ * oscillates between 0.5 and 0, before converging to something less than 0.4. β is nearly 1 for both cases.
In the case of the online debate during the COVID-19 epidemic, Fig.s 11 and 12 , the differences are extremely low, with the values of γ * quite flickering before converging to a value little lower than the one obtained for the entire dataset. All other parameters are quite similar, both in the value and in the dynamics.
Actually, it is not clear if this evolution of the parameters for the BOT subset is due to the limited numerosity of the dataset or to an indeed different dynamics. This issue is not the focus of this work and it is going to be the target of further analyses. : "Covid" dataset (Entire): Model parameters evolution. All parameters are nearly constant or slowly converging. This slow convergence is probably due to the fact that the fit of the parameters is mostly driven by the long range history. In the case of the "COVID" dataset, S = 1000. Figure 12 : "Covid" dataset (Only BOTs' posts): Model parameters evolution. Differently to the other datasets, the parameters evolution for the Bots' posts follows the one for the entire dataset, displaying a greater noise contribution for γ * . In the case of the "Covid" dataset, S = 1000.