aainstitutetext: Scientific Data Division, Lawrence Berkeley National
Laboratory, Berkeley, CA 94720, USAbbinstitutetext: Physics Division, Lawrence
Berkeley National Laboratory, Berkeley, CA 94720, USAccinstitutetext: Berkeley
Institute for Data Science, University of California, Berkeley, CA 94720,
USAddinstitutetext: Department of Physics, University of California, Berkeley,
CA 94720, USAeeinstitutetext: Jagiellonian University, Krakow, Poland

# Integrating Particle Flavor into
Deep Learning Models for Hadronization

Jay Chan a Xiangyang Ju e Adam Kania b,c Benjamin Nachman d,b Vishnu Sangli e
and Andrzej Siodmok

###### Abstract

Hadronization models used in event generators are physics-inspired functions
with many tunable parameters. Since we do not understand hadronization from
first principles, there have been multiple proposals to improve the accuracy
of hadronization models by utilizing more flexible parameterizations based on
neural networks. These recent proposals have focused on the kinematic
properties of hadrons, but a full model must also include particle flavor. In
this paper, we show how to build a deep learning-based hadronization model
that includes both kinematic (continuous) and flavor (discrete) degrees of
freedom. Our approach is based on Generative Adversarial Networks and we show
the performance within the context of the cluster hadronization model within
the Herwig event generator.

##  1 Introduction

Despite the extensive predictability of Quantum Chromodynamics, the theory of
the strong force, we cannot yet calculate how the fundamental degrees of
freedom (quarks/gluons) combine to form the observable states (hadrons). At
the same time, it is essential that we be able to model this transition in
order to connect first-principles, perturbative calculations with data. Event
generators in wide use are based on one of two physically-inspired parametric
models with many tunable parameters: the cluster model Webber:1983if  (default
in Herwig Corcella:2000bw ; Bahr:2008pv ; Bellm:2015jjp ; Bellm:2019zci  and
Sherpa Gleisberg:2008ta ; Sherpa:2019gpd ) and the string model
Andersson:1983ia ; Sjostrand:1984ic  (default in Pythia Sjostrand:2007gs ;
Sjostrand:2006za ). These models have enabled a wide array of physics results
across particle and nuclear physics. However, it is also well-known that these
models do not describe all regions of phase space. As the science requires
more precision and examines more extreme regions of phase space, new and
systematically improvable hadronization models are needed.

Deep generative neural networks are promising tools to enhance the precision
of hadronization models due to their flexibility Butter:2022rso . There is a
long history of neural networks for modeling non-perturbative functions
NNPDF:2021njg  and recent studies have shown that deep generative models can
emulate the string and cluster hadronization when trained on paired sets of
partons and hadrons Ilten:2022jfm ; Ghosh:2022zdz . These techniques have also
been extended to the realistic setting where a pairing is not known and only
hadrons are observed Chan:2023ume ; Bierlich:2023zzd . However, all of the
studies so far have trained on simplified simulations without any
parton/hadron flavor.

In this paper, we extend the HadML Ghosh:2022zdz ; Chan:2023ume  setup to
include parton and hadron flavor. This is challenging because both continuous
(kinematic) and discrete (flavor) information must be generated at the same
time. HadML is based on a Generative Adversarial Network (GAN)
Goodfellow:2014:GAN:2969033.2969125 ; Creswell2018  because it naturally
accommodates the realistic case mentioned above***In fact, one can also view
the MLHad approach Bierlich:2023zzd  as a GAN where the generator is
parameterized as a normalizing flow 10.5555/3045118.3045281 ; Kobyzev2020  and
the discriminator is similar to the Wasserstein GAN setup pmlr-v70-arjovsky17a
. They also proposed a clever variation to avoid regenerating events in each
epoch of training through reweighting. Chan:2023ume .

This paper is organized as follows. Section 2 introduces the machine learning
methods of the new HadML model and how they are implemented in practice. The
dataset we use to stress-test this model, based on Herwig 7 (H7) Bellm:2019zci
, is described in Sec. 3 and numerical results are presented in Sec. 4. The
paper ends with conclusions and outlook in Sec. 5.

##  2 Methods

###  2.1 Generative Adversarial Network Framework

The overall setup is similar to that in the previous work Ghosh:2022zdz . A
conditional generator function $G\left(z,\lambda;\omega_{G}\right)$ with the
parameters $\omega_{G}$ is learned to map the initial cluster properties onto
the properties of the two†††The decay of heavy clusters can produce more than
two hadrons, but in most cases the collisions we consider produce mainly light
clusters that decay into two hadrons. Therefore, in this study, we have
limited ourselves to the case of decay into two hadrons, and we will
investigate more complex decays in future work. hadrons from each cluster
decay $\\{h_{1},h_{2}\\}\in\mathbb{R}^{2N_{h}}$. In addition to the four-
momenta, the generator function should also output the particle types of the
two hadrons. Here, $z\in\mathbb{R}^{N_{z}}$ is the input noise variable
sampled from the prior $p\left(z\right)$, and
$\lambda\in\mathbb{R}^{N_{\lambda}}$ is the conditional variable. In Ref
Ghosh:2022zdz , the generator function was conditioned on the cluster four-
momentum ($E$, $p_{x}$, $p_{y}$, $p_{z}$). In this paper, we consider
additional conditional variables from the two incoming cluster-forming quarks,
including their four-momenta and particle types. Since two hadrons from a
cluster decay must be back-to-back in the rest frame of cluster, the generator
$G$ can output the polar angles $\theta$ and $\phi$ of the “first hadron” in
the cluster rest frame instead of the 4-momenta of both hadrons. Similarly,
the incoming quarks are back-to-back in the cluster rest frame. Therefore, we
parametrize their four-momentum as the polar angles $\theta$ and $\phi$ of the
“first quark” in the cluster rest frame. Note that here $\phi$ is defined in
the range of $(-\pi/2,\ \pi/2)$, and the hadron (quark) with $\phi$ in this
range is defined to be the first hadron (quark).

A discriminator function
$D\left(\theta_{h_{1}},\phi_{h_{1}},\mathrm{PID}_{h_{1}},\mathrm{PID}_{h_{2}};\omega_{D}\right)$,
parameterized with $\omega_{D}$, is learned to represent the probability that
$\\{\theta_{h_{1}},\phi_{h_{1}},\mathrm{PID}_{h_{1}},\mathrm{PID}_{h_{2}}\\}$
came from cluster fragmentation rather than the generator $G$. Note that
$\theta_{h_{1}}$, $\phi_{h_{1}}$ are the polar angles of the first hadron, and
$\mathrm{PID}_{h_{1}}$, $\mathrm{PID}_{h_{2}}$ are the particle types of the
two hadrons. $G$ and $D$ are trained alternately where $G$ is trained to
maximize the loss function:

$L_{G}=-\mathbb{E}_{\lambda\sim\text{H7},\,z\sim
p\left(z\right)}\big{(}\log\left(D\left(\tau\left(\lambda\right)\right)\right)+\log\left(1-D\left(G\left(z,\lambda\right)\right)\right)\big{)}\,,$
(1)

where $\tau$ is the cluster fragmentation, and D is trained to minimize the
loss function:

$L_{D}=-\mathbb{E}_{\lambda\sim\text{H7},\,z\sim
p\left(z\right)}\big{(}\log\left(D\left(\tau\left(\lambda\right)\right)\right)+\log\left(1-D\left(G\left(z,\lambda\right)\right)\right)\big{)}+\gamma
R_{1}(\omega_{D})\,,$ (2)

where $\gamma$ is a regularization weight, which we set to 200. We use R1
regularization GANconverge  on real data points:

$R_{1}(\omega_{D})=\mathbb{E}_{\lambda\sim\text{H7}}[\|\nabla_{\tau(\lambda)}D_{\omega_{D}}(\tau(\lambda))\|^{2}].$
(3)

###  2.2 Machine Learning Implementation

The generator ($G$) and discriminator ($D$) functions are both parametrized as
neural networks. Each of them is a fully connected network with four hidden
layers, each with a width of 1,000 neurons. All intermediate layers in these
networks use a LeakyReLU xu2015empirical  activation function.

The non-discrete conditional inputs of $G$ are normalized to the range of
$(-1,\ 1)$, whereas the noise prior $p$ is a Gaussian distribution with a mean
of 0 and width of 1. The noise dimension $N_{z}$ is set to 64. The last layer
of $G$ is divided into the variables $\kappa\in\mathbb{R}^{2}$, which
correspond to hadron kinematics, and the variables
$\pi\in\mathbb{R}^{2N_{t}}$, which correspond to hadron types. Here, $N_{t}$
is the number of hadron types considered. For simplicity, we consider only the
40 most common hadron types (i.e. $N_{t}=40$)‡‡‡The most common hadron types
are identified from an independent and slightly different simulation sample
generated by H7. This is why the frequencies reported in Fig. 2 are not
strictly decreasing.. The hadron kinematics $\theta_{h_{1}}$ and
$\phi_{h_{1}}$ are extracted from $\kappa$ with a tanh activation function, as
in the previous work Ghosh:2022zdz . The hadron type, on the other hand, is a
categorical variable. In order to avoid zero gradients when using argmax in
training, we use the Gumbel-Softmax jang2017categorical  distribution to
approximate the distribution of hadron types:

$y_{i}=\frac{\exp\left(\left(\log\pi_{i}+g_{i}\right)/\tau\right)}{\sum_{i}\exp\left(\left(\log\pi_{i}+g_{i}\right)/\tau\right)},$
(4)

where $g_{i}$ are independent and identically distributed samples drawn from
Gumbel(0, 1). $\tau$ is a temperature parameter and as it approaches 0 the
Gumbel-Softmax distribution becomes identical to the categorical distribution.
We anneal $\tau$ by linearly decreasing it from 1.0 to 0.1 during training.
The hadron type distributions $y$ from the Gumbel-Softmax distribution are
then taken as the inputs for $D$, in addition to the hadron kinematics
$\theta_{h_{1}}$ and $\phi_{h_{1}}$. During inference, the generated hadron
types are obtained from the Gumbel-Softmax distribution with the argmax
operation. The last layer of $D$ uses a sigmoid activation function.

All neural networks are implemented and trained using PyTorch NEURIPS2019_9015
. The generator and discriminator are optimized alternately with Adam adam
with a learning rate of $3\times 10^{-4}$ for both networks. The training uses
a batch size of 40,000 and is performed for 25 epochs. The hyperparameters are
optimized with Weights and Biases wandb .

##  3 Dataset

The dataset was generated by the Herwig 7.2.1 Monte Carlo generator, which by
default uses a cluster hadronization model. In the first step of the cluster
model, partons are grouped into colorless objects called clusters (exited pre-
hadrons), which then decay into two hadrons (or lighter clusters§§§The heavier
clusters can also decay into lighter clusters before decaying into hadrons.
However, since in this publication, we are mainly interested in the generation
of individual hadron flavour. We leave the decays of the heavy clusters for a
future follow-up paper.). Since in our study, we wanted to integrate the
particle flavour into the HadML model, in addition to the kinematic
information (the four momenta of all light clusters in the event and their
decay products, hadrons), our dataset also contains information about the type
of hadrons ($\mathrm{PID}_{h_{1}}$, $\mathrm{PID}_{h_{2}}$), as well as the
Particle Data Group ParticleDataGroup:2022pth  Identification (PDG ID) of the
partons that make up a given light cluster. All datasets were generated in
electron-positron collisions at an energy of 91.2 GeV, which corresponds to
events recorded by LEP experiments at CERN. Data from LEP is crucial for
fitting hadronisation models, therefore such a sample is the most natural for
the development of new hadronization approaches. To test whether the HadML
model can adapt to different flavor compositions, we prepared two datasets
with different settings of the cluster model parameters responsible for the
generation of hadron types. To be more precise, the nominal dataset was
generated using H7’s default settings. For the variational dataset, we have
maximized the weights for producing charmed quark-antiquark pairs, strange
quark-antiquark pairs and diquark-antiquark pairs as well as the relative
weight $SngWt$ for the production of singlet baryons and the relative weight
$DecWt$ for the production of decuplet baryons in cluster hadronisation¶¶¶ To
achieve this, we used the following H7’s settings:
HadronSelector:PwtDIquark=10, HadronSelector:PwtBquark=10,
HadronSelector:PwtCquark=10, HadronSelector:SngWt=10 and
HadronSelector:DecWt=10. For details, please see H7’s manual Bahr:2008pv ..

##  4 Results

The two datasets described in Sec. 3 have the same distributions of
$\theta_{h}$ and $\phi_{h}$, which are nearly independent of hadron type. As
in our previous works, these distributions are well-modeled by HadML (Fig. 1)
and are essentially uniform in $\phi$ and Gaussian-like in $\theta$.

The lab-frame spectra of energies and angles differ between the nominal and
alternative samples because of the differences in hadron masses. Since the
masses are known, the lab-frame properties are therefore determined by how
well we model the frequency of the various flavor types. Figure 2 shows the
frequencies for H7 and HadML, inclusive in the flavor of the quark types
composing the decaying cluster. As expected, the pions are the most frequent
(PID IDs 111 and $\pm 211$), followed by the $\rho$ (PDG IDs 113 and $\pm
213$) and $\omega$ (PDG ID 223). Next are the kaons (PDG ID 3xx), protons (PDG
ID $\pm 2212$), and neutrons (PDG ID $\pm 2112$). A series of other
intermediate hadronic resonances follow the lightest baryons. The nominal and
alternative H7 models significantly differ in these rates, most notably for
the pion versus $\omega$ production and in the rate of baryons. HadML captures
these trends across the full spectrum at $\mathcal{O}(1\%)$ precision. This is
true even for the large drop in frequency between the pions and all other
hadrons as well as between the large raise in baryon production between the
nominal and alternative H7 models.

Figure 1: Flavor-inclusive density contour of $\phi$ and $\theta$ in the
cluster frame for the nominal dataset (solid line) as well as for the dataset
created from the fitted HadML model (filled colors). Figure 2: The Particle
Data Group Identification (PDG ID) ParticleDataGroup:2022pth  of hadrons
generated by the nominal and alternative H7 datasets as well as for datasets
created from the fitted HadML models.

Since HadML is conditioned on the flavor of the constituent quarks, we can
also investigate the relationship between the cluster composition and the
resulting hadron types. We expect that if one of the quarks is strange, then
the hadrons should be biased towards strange hadrons (e.g. kaons). This is
what we see in Fig. 3, which compares the inclusive hadron flavor distribution
with the spectrum after requiring that at least one of the incoming quarks is
strange. There are large changes between the inclusive and conditional
distributions, which are well-reproduced by HadML. The neural network is also
able to learn that when both quarks are strange, then both outgoing hadrons
must be strange.

Figure 3: Left (Right): The PDG ID of hadrons generated inclusively and
requiring that at least one (both) of the quarks composing the cluster are
strange for H7 and for the HadML model.

##  5 Conclusions

This paper marks an important milestone in the development of surrogate models
for hadronization: the inclusion of hadron flavor. Hadronization is not
understood from first principles so it is a natural candidate for the flexible
modeling afforded by deep generative models. Previous works on machine
learning-based hadronization had focused on the case of only pions and we
extend the GAN-based HadML approach to include other hadron types∥∥∥While this
work was being finalized, Ref. Birk:2023efj  became the first paper to combine
continuous and discrete outputs for generative modeling in HEP. They used a
diffusion model with only a few discrete labels (particle types), both of
which differ from (and are not directly applicable to) our setup. However, it
would be interesting to explore possible connections between approaches in the
future.. This required us to combine continuous (e.g. angles/momenta) with
discrete (particle types) in our generator. We accomplished this goal using
the Gumbel-Softmax jang2017categorical  distribution for hadron types, to
enable differentiability.

The insights of this paper could be combined with our previous paper
Chan:2023ume  to fit the HadML model with flavor to data in the lab frame.
Additional work is also required to integrate all hadron types and to go
beyond two-body decays of hadrons. Ultimately, we hope to create a model
flexible enough to accommodate the cluster model, the string model, and
nature.

## Software and Datasets

The nominal and alternative H7 samples used for training can be found on
Zenodo at https://zenodo.org/records/10246934 chan_2023_10246934 . Software
for reproducing the plots can be found on Github at https://github.com/hep-
lbdl/hadml/releases/tag/2.0.0 chan_2023_10275487 .

## Acknowledgments

We thank Aishik Ghosh for many useful discussions. The work of AS is funded by
grant no. 2019/34/E/ST2/00457 of the National Science Centre, Poland. A.K.
acknowledges support by the Priority Research Area Digiworld under the program
Excellence Initiative – Research University at the Jagiellonian University in
Cracow. JC, BN and XJ are supported by the U.S. Department of Energy (DOE),
Office of Science under contract number DE-AC02-05CH11231. Support for JC and
XJ was also provided through the Scientific Discovery through Advanced
Computing (SciDAC) program funded by U.S. Department of Energy, Office of
Science, Advanced Scientific Computing Research and High Energy Physics.

## References

  * (1) B. R. Webber, _A QCD Model for Jet Fragmentation Including Soft Gluon Interference_ , _Nucl. Phys. B_ 238 (1984) 492–528.
  * (2) G. Corcella, I. G. Knowles, G. Marchesini, S. Moretti, K. Odagiri, P. Richardson et al., _HERWIG 6: An Event generator for hadron emission reactions with interfering gluons (including supersymmetric processes)_ , _JHEP_ 01 (2001) 010, [hep-ph/0011363].
  * (3) M. Bahr et al., _Herwig++ Physics and Manual_ , _Eur. Phys. J._ C58 (2008) 639–707, [0803.0883].
  * (4) J. Bellm et al., _Herwig 7.0/Herwig++ 3.0 release note_ , _Eur. Phys. J._ C76 (2016) 196, [1512.01178].
  * (5) J. Bellm et al., _Herwig 7.2 release note_ , _Eur. Phys. J. C_ 80 (2020) 452, [1912.06509].
  * (6) T. Gleisberg, S. Hoeche, F. Krauss, M. Schonherr, S. Schumann, F. Siegert et al., _Event generation with SHERPA 1.1_ , _JHEP_ 02 (2009) 007, [0811.4622].
  * (7) Sherpa collaboration, E. Bothmann et al., _Event Generation with Sherpa 2.2_ , _SciPost Phys._ 7 (2019) 034, [1905.09127].
  * (8) B. Andersson, G. Gustafson, G. Ingelman and T. Sjostrand, _Parton Fragmentation and String Dynamics_ , _Phys. Rept._ 97 (1983) 31–145.
  * (9) T. Sjostrand, _Jet Fragmentation of Nearby Partons_ , _Nucl. Phys. B_ 248 (1984) 469–502.
  * (10) T. Sjöstrand, S. Mrenna and P. Z. Skands, _A Brief Introduction to PYTHIA 8.1_ , _Comput. Phys. Commun._ 178 (2008) 852–867, [0710.3820].
  * (11) T. Sjöstrand, S. Mrenna and P. Z. Skands, _PYTHIA 6.4 Physics and Manual_ , _JHEP_ 05 (2006) 026, [hep-ph/0603175].
  * (12) S. Badger et al., _Machine learning and LHC event generation_ , _SciPost Phys._ 14 (2023) 079, [2203.07460].
  * (13) NNPDF collaboration, R. D. Ball et al., _The path to proton structure at 1% accuracy_ , _Eur. Phys. J. C_ 82 (2022) 428, [2109.02653].
  * (14) P. Ilten, T. Menzo, A. Youssef and J. Zupan, _Modeling hadronization using machine learning_ , 2203.04983.
  * (15) A. Ghosh, X. Ju, B. Nachman and A. Siodmok, _Towards a deep learning model for hadronization_ , _Phys. Rev. D_ 106 (2022) 096020, [2203.12660].
  * (16) J. Chan, X. Ju, A. Kania, B. Nachman, V. Sangli and A. Siodmok, _Fitting a deep generative hadronization model_ , _JHEP_ 09 (2023) 084, [2305.17169].
  * (17) C. Bierlich, P. Ilten, T. Menzo, S. Mrenna, M. Szewc, M. K. Wilkinson et al., _Towards a data-driven model of hadronization using normalizing flows_ , 2311.09296.
  * (18) I. J. Goodfellow, J. Pouget-Abadie, M. Mirza, B. Xu, D. Warde-Farley, S. Ozair et al., _Generative adversarial nets_ , in _Proceedings of the 27th International Conference on Neural Information Processing Systems - Volume 2_ , NIPS’14, (Cambridge, MA, USA), pp. 2672–2680, MIT Press, 2014, http://dl.acm.org/citation.cfm?id=2969033.2969125.
  * (19) A. Creswell, T. White, V. Dumoulin, K. Arulkumaran, B. Sengupta and A. A. Bharath, _Generative adversarial networks: An overview_ , _IEEE Signal Processing Magazine_ 35 (Jan, 2018) 53.
  * (20) D. Rezende and S. Mohamed, _Variational inference with normalizing flows_ , _Proceedings of the 32nd International Conference on Machine Learning_ 37 (Jul, 2015) 1530–1538, [1505.05770].
  * (21) I. Kobyzev, S. Prince and M. Brubaker, _Normalizing Flows: An Introduction and Review of Current Methods_ , _IEEE Transactions on Pattern Analysis and Machine Intelligence_ 43 (2021) 1, [1908.09257].
  * (22) M. Arjovsky, S. Chintala and L. Bottou, _Wasserstein generative adversarial networks_ , in _Proceedings of the 34th International Conference on Machine Learning_ (D. Precup and Y. W. Teh, eds.), vol. 70 of _Proceedings of Machine Learning Research_ , pp. 214–223, PMLR, 06–11 Aug, 2017, https://proceedings.mlr.press/v70/arjovsky17a.html.
  * (23) L. Mescheder, A. Geiger and S. Nowozin, _Which training methods for GANs do actually converge?_ , in _Proceedings of the 35th International Conference on Machine Learning_ (J. Dy and A. Krause, eds.), vol. 80 of _Proceedings of Machine Learning Research_ , pp. 3481–3490, PMLR, 10–15 Jul, 2018, https://proceedings.mlr.press/v80/mescheder18a.html.
  * (24) B. Xu, N. Wang, T. Chen and M. Li, _Empirical evaluation of rectified activations in convolutional network_ , 2015.
  * (25) E. Jang, S. Gu and B. Poole, _Categorical reparameterization with gumbel-softmax_ , in _International Conference on Learning Representations_ , 2017, https://openreview.net/forum?id=rkE3y85ee.
  * (26) A. Paszke, S. Gross, F. Massa, A. Lerer, J. Bradbury, G. Chanan et al., _Pytorch: An imperative style, high-performance deep learning library_ , in _Advances in Neural Information Processing Systems 32_ (H. Wallach, H. Larochelle, A. Beygelzimer, F. d'Alché-Buc, E. Fox and R. Garnett, eds.), pp. 8024–8035.  Curran Associates, Inc., 2019.
  * (27) D. Kingma and J. Ba, _Adam: A method for stochastic optimization_ , 1412.6980.
  * (28) L. Biewald, _Experiment tracking with weights and biases_ , 2020.
  * (29) Particle Data Group collaboration, R. L. Workman et al., _Review of Particle Physics_ , _PTEP_ 2022 (2022) 083C01.
  * (30) J. Birk, E. Buhmann, C. Ewen, G. Kasieczka and D. Shih, _Flow Matching Beyond Kinematics: Generating Jets with Particle-ID and Trajectory Displacement Information_ , 2312.00123.
  * (31) J. Chan, X. Ju, A. Kania, B. Nachman, V. Sangli and A. Siodmok, _Herwig dataset for hadml particle gan training_ , Dec., 2023.  10.5281/zenodo.10246934.
  * (32) J. Chan, X. Ju, A. Kania, B. Nachman, V. Sangli and A. Siodmok, _Code for hadml particle gan training_ , Dec., 2023.  10.5281/zenodo.10275487.


of Computer Science,
San Jose State University,
San Jose, California

The impact of social media on the modern world is difficult to overstate. Virtually all
companies and public figures have social media accounts on popular platforms such
as Twitter and Facebook. In China, the micro-blogging service provider,
Sina Weibo, is the most popular such service. To influence public opinion,
Weibo trolls—the so called Water Army—can be hired to post deceptive comments.
In this paper, we focus on troll detection via sentiment analysis and other user activity
data on the Sina Weibo platform.
We implement techniques for Chinese sentence segmentation, word embedding,
and sentiment score calculation.
In recent years, troll detection and sentiment analysis have been studied, but we are
not aware of previous research that considers troll detection based on sentiment analysis.
We employ the resulting techniques to
develop and test a sentiment analysis
approach for troll detection, based on a variety of machine learning strategies. Experimental
results are generated and analyzed. A Chrome extension is presented that implements
our proposed technique, which enables real-time troll detection when a user browses
Sina Weibo.

§ INTRODUCTION

Social media plays a significant role in the ongoing development of the Internet,
as people tend to acquire more information from social media than other platforms.
Deceptive comments created by trolls present a
challenging problem in social media applications. Trolls can be hired to publish
misleading comments in an effort to affect public opinion related to events or people,
or even to negatively influence the economy of a country.

Sina Weibo is a widely used micro-blogging social media platform in China. A majority of
Weibo posts are written in Chinese and, like Twitter, most posts published on Weibo
are short—until recently, there was a 140 character limit.
With the number of daily active users in excess of 200 million (as of 2019),
Weibo is one of the largest social media platforms in China.

Weibo is based on weak
relationships, in the sense that a user can share content
that is visible to all of the user base.
Therefore, many celebrities, businesses, and Internet influencers all over the
world register as Weibo users in an effort to expand their exposure to the Chinese public.
Weibo has become a platform where government and businesses can
communicate more efficiently with the general public.

The Chinese Water Army refers to a group of people who can be hired to post deceptive
comments on Weibo. Such troll activity is difficult to detect, due in part to the unsegmented
characteristic of the Chinese sentences. In some cases, Chinese sentences
can be segmented in different ways to yield different meanings.

Recent research has shown that hidden Markov models (HMM) are effective for
sentiment analysis of English text <cit.>. Chinese word segmentation
can also be accomplished using HMMs <cit.>. In
this research, we use HMMs, Word2Vec and other learning techniques to perform word segmentation
and sentiment analysis on Sina Weibo “tweets” for the purpose of
detecting potential troll activity. We use Word2Vec and HMMs for Chinese
text segmentation, we employ HMMs and  Bayes for sentiment analysis,
and we use XGBoost and support vector machines (SVM) for
troll detection.

We have generated a large training dataset by crawling the Sina Weibo and
Tencent Weibo platforms. Using an HMM-based Chinese sentence segmentation
model comparable to that in <cit.>, we pre-process each post into a list of words.
Then, following the approach in <cit.>, we construct a Word2Vec
similarity scoring matrix based on the word list that we have generated.
A baseline of sentiment is determined from the corpus that we have collected.

For sentiment analysis, we use a Word2Vec based technique to calculate
sentiment scores.  We use extracted features from Weibo comments
as observations to train HMM models for each emotion, and we use the trained models
to determine the emotions of each comment. We use an XGBoost model to aggregate
sentiment analysis results with user activity data to build the troll detection model.
As a point of comparison, we experiment with an approach based on support vector machines.

Finally, we present a Chrome extension that we have developed. This Chrome extension
implements our troll detection model, and it
enables us to detect potential troll activity on Weibo in real-time.

The remainder of this paper is organized as follows. In Section <ref>
we discuss relevant background topics.
Section <ref> contains an overview of selected
previous work. In Section <ref>, we consider
data sources and data collection methods.
In Section <ref>, we provide implementation details
and includes experimental results.
Lastly, in Section <ref> we  give a summary of our work,
including a brief discussion of possible directions for future development.

§ BACKGROUND

In this section, we discuss several relevant background topics.
First, to motivate this research, we discuss trolls in the context
of social media. Then we introduce machine learning models
that are used in this research.
We conclude this section with a brief discussion of the
evaluation metric that we employ.

§.§ Trolls

Troll users publish misleading, offensive or trivial following-up content in online
communities. The content of a troll posting generally falls into one of several categories.
It may consist of an apparently foolish contradiction of common knowledge,
a deliberately offensive insult to the readers of a newsgroup or mailing list,
or a broad request for trivial follow-up postings. The result of such posting is
frequently a flood of angry responses. In some cases, the follow-up messages posted
in response to a troll can constitute a large fraction of the contents of a
newsgroup or mailing list on a particular topic over an extended period of time.
These messages may be transmitted around the world to vast numbers of computers,
wasting network resources and costing resources.
Troll threads frustrate people who are trying to carry on substantive
discussions <cit.>.

Organized troll activity on the Sina Weibo platform was first detected in 2013.
This initial group of troll users consisted of about 20,000 individuals
in 50 ICQ chat groups associated with a person nicknamed “Daxia.”
Subsequently, troll activity became an online business on the Weibo platform.
Trolls can be hired by businesses to publish negative comments against their
competitors or to generate anonymous good reviews or positive comments.
Prior to 2015, much of the troll activity on Weibo was designed to adversely
affect the reputation of businesses.
After 2015, stricter controls were set on speech on the Internet in China,
and Sina Weibo developed a more sophisticated infrastructure to filter such troll comments.
Currently, most of the troll activity on Weibo turned is designed
to promote celebrities and companies.

Troll users on the Weibo platform can be categorized by their source of content.
Traditionally, trolls use automated fake accounts to post repeated messages
in an effort to dominate the comments. An example of such activity is shown
in Figure <ref>. However, the Weibo
platform has recently improved their infrastructure to block these repeated messages
from users, based on proxy detection, combined with message filters for repeated comments.

Weibo comments dominated by troll activity <cit.>

Recently, troll users have become more sophisticated. Some organized Weibo trolls
are supervised by a management
group who controls what, when, and where they reply on the Weibo platform.
Specific details of the comments that each troll account publishes are made by individual
troll users rather than being copied from the management group. The management
group only gives out the overall emotional trend that the comments should convey.
Thus, content made by troll users are repetitive but not monotonously so.
This fact makes troll detection on Weibo challenging, since troll comments
are composed and published by real human users. Furthermore, in recent years,
trolls are mostly hired by companies and celebrities to make positive
comments towards themselves.

§.§ Machine Learning Techniques

Content-based troll detection usually utilizes natural language processing (NLP)
using machine learning to analyze and categorize text.
This is accomplished by constructing language processing models on
comments and posts so as to label comments with a high polarity of emotion
or repetitiveness. By applying sentiment analysis methods, we can filter
comments with either high or low sentiment scores representing extreme positive
or negative sentiment. This is accomplished by calculating word relevance,
and by analyzing correlations using word embedding techniques,
such as Word2Vec. We can then mark potential troll comments or pass along
user information behind such comments to the next stage of a troll detection model.
A key point of this research is to use sentiment analysis in
troll detection.

Classifying specific comments as troll activity is challenging. Therefore,
utilizing user behavioral information to discern deceptive activity
is a popular trend in troll detection. Like most social media platforms,
Weibo has numerous user relationship data, such as the number of followers,
number that a user is following, user rank, and number of original Weibo tweets.
Also, trolls commonly make attacks in a small time window following a
specific tweet <cit.>. We can utilize this fact in combination with
other user relationship information in a troll detection system. The goal
of including such data in our troll detection approach is to reduce
the false negatives that affect strictly content-based detection methods.

Next, we introduce the various machine learning techniques used in this
research. Specifically, we discuss hidden Markov models (HMM), Word2Vec,
XGBoost, and support vector machines (SVM) in some detail.

§.§.§ Hidden Markov Models

Hidden Markov models (HMMs) are well-known for their use in
pattern prediction and for deriving hidden states from observations.
An HMM (of order one) is a stochastic model representing states where each future state
depends only on the current state, and not on states further in the past. By training
an HMM on an observation sequence, we can obtain the probability of the transitions
between each hidden state and probability distributions for the observations, based
on those hidden states. A generic HMM is illustrated in Figure <ref>.

Hidden Markov model

In Figure <ref>, the matrix $A$ drives the Markov process
for the hidden states, while the matrix $B$ probabilistically relates
the hidden states to the observations $\O_i$.
The HMM notation is summarized in Table <ref>.

HMM notation
Notation     Description
$T$     Length of the observation sequence

$N$     Number of states in the model

$M$     Number of observation symbols

$Q$     Distinct states of the Markov process, $q_0,q_1,\ldots,q_{N-1}$

$V$     Possible observations, assumed to be $0,1,\ldots,M-1$

$A$     State transition probabilities

$B$     Observation probability matrix

$\pi$     Initial state distribution

$\O$     Observation sequence, $\O_0,\O_1,\ldots,\O_{T-1}$

Applications of HMMs are extremely diverse, but for our purposes, two
relevant uses are English text analysis and
speech recognition <cit.>. Other applications of
HMMs range from classic cryptanalysis <cit.> to malware
detection <cit.>.
In this research, we use HMMs for both Chinese word
segmentation and for emotion classification.

§.§.§ Word2Vec

Word2Vec has recently gained considerable popularity in
natural language processing (NLP) <cit.>.
This word embedding technique is based on a shallow neural network, with the weights
of the trained model serving as embedding vectors—the trained model itself serves no
other purpose. These embedding vectors capture significant relationships
between words in the training set. Word2Vec can also
be used beyond the NLP context to model relationships between
more general features or observations.

When training a Word2Vec model, we must specify the desired
vector length, which we denote as $N$. Another key parameter
is the window length $W$, which represents the width of a sliding
window that is used to extract training samples from the data.

Certain algebraic properties hold for Word2Vec
embeddings. For example, suppose that we train a state-of-the-art
Word2Vec model on English text. Further, suppose that we let

w_0=\mbox{``king''}, w_1=\mbox{``man''}, w_2=\mbox{``woman''}, w_3=\mbox{``queen''} ,

and we define $V(w_i)$ to be the Word2Vec embedding of word $w_i$.
Then according to <cit.>, the vector $V(w_3)$
is closest to

V(w_0) - V(w_1) + V(w_2)

where “closeness” is in terms of cosine similarity.
Results such as this indicate that in the NLP context,
Word2Vec embeddings capture meaningful
aspects of the semantics of the language.

In this research, we train Word2Vec models Chinese text.
These models are then used for sentiment analysis
of Weibo tweets.

§.§.§ XGBoost

Boosting is a general technique for constructing
a stronger classifier from a large collection
of relatively weak classifiers <cit.>.
XGBoost typically uses decision trees as the base classifiers.
To generate our models, we use the XGBoost package in Python. With this
implementation, it is easy to analyze the significance of each individual feature
relative to the overall model, and thus eliminate ineffective features.

§.§.§ SVM

In <cit.>,
support vector machine (SVM) is described
as “a rare example of a methodology where geometric intuition,
elegant mathematics, theoretical guarantees, and practical algorithms meet.”
The essential ideas behind SVMs are the following.

Separating hyperplane— We seek a hyperplane that will separate two
labeled classes.

Maximize the margin— We want to find hyperplane
that maximizes the “margin” between two classes, where
margin is defined as the minimum distance.

Work in higher dimensional space— By shifting the problem to a higher dimensional
space, there is a better chance that we can find a separation hyperplane, or
separating hyperplane with a larger margin.

Kernel trick— Perhaps surprisingly, we are able to work in a higher dimensional space
without paying any significant penalty with respect to computational complexity.
This is a powerful “trick” and is the key reason why SVM is one of the most
popular machine learning techniques available.

In this research, SVM serves as a comparison to XGBoost for troll detection.
We find that XGBoost performs better on one of our datasets, while SVM
is superior on another dataset.

§.§ Evaluation Metric

We use accuracy as the primary measure of success for all of our classification experiments.
The accuracy is computed as

\mbox{accuracy} = \frac{\mbox{TP}+\mbox{TN}}{\mbox{TP}+\mbox{TN}+\mbox{FP}+\mbox{FN}} ,

where TP is number of true positive cases, TN is true negatives, FP is false positives,
and FN is the number of false negatives. Accuracy can be seen to simply be
the ratio of correct classifications to the total number of classifications.

Finally, we note that cross validation is used in all of our experiments.
Cross validation is a popular technique that serves to smooth any bias in
the data, while also maximizing the number of datapoints.
Specifically, we employ 5-fold cross validation.

§ RELATED WORK

Related work in sentiment analysis includes <cit.>,
where a combination of emotional orientation and logistical regression is used to
analyze Amazon.com reviews. By filtering the training dataset by text length,
vocabulary complexity, correlation with the product, sentiment similarity, and transition words,
the proposed model achieved 91.2% accuracy.
For the problem of fake Weibo tweet detection—as opposed to the troll detection
we consider in this research—an XGBoost model based
on user activity achieved 93% accuracy in <cit.>.

From our review of the literature, it appears that only <cit.>
applies sentiment analysis to the troll detection problem.
The work in <cit.> applies domain adaptation techniques to a
recursive neural tensor network (RNTN) sentiment analysis model to detect trolls
that post repetitive, destructive, or deceptive comments.
This previous work achieves 78% accuracy.
The results in <cit.> serve as a baseline for our research.

Sentiment analysis is widely used for mining subjective information in
online posts. In <cit.>, Kim, et al., use hidden Markov models
with syntactic and sentiment information for sentiment analysis of Twitter data.
This differs from classic approaches that use $n$-grams and polarity lexicons,
as they group words based on similar syntactic and sentiment groups (SIG),
then build HMMs, where the SIGs define the hidden states. Zhao and Ohsawa <cit.>
propose a two-dimensional HMM to analyze Amazon reviews in Japanese.
For our purposes, this work illustrates an important method for converting
segmented Japanese text into word vectors using Word2Vec.
Feng and Durdyev <cit.> implemented three types of
classification models (SVM, XGBoost, LSTM) for the aspect-level sentiment analysis
of restaurant customer reviews in Chinese.
According to the research in  <cit.>,
LSTM yields better F-1 scores and accuracy, as compared to SVM and XGBoost.
Further related research can be found in Liu, et al.<cit.>,
which uses a self-adaptive HMM.

Troll detection based on user characteristic data, is considered in
Zhang, et al. <cit.>. In this paper, Weibo troll detection is
based on a Bayesian model and genetic algorithm. The proposed technique
includes novel features (as compared to previous work) such as the ratio of followers,
average posts, and Weibo credibility, and achieves an accuracy of about 90%.

Liu, Wang and Long <cit.> use XGBoost to detect fake
Weibo posts based on features such as a user's number of posts, description,
gender, followers, and reposts. The authors attain an accuracy of more than 95%.
Both <cit.> and <cit.> use data beyond Weibo post
text itself, and achieve good results. This previous work serves as inspiration for some of
the features considered in this paper.

The special interest group for Chinese language processing (SIGHAN)
of the Association for Computational Linguistics
organizes competitions for Chinese word segmentation.
In the first SIGHAN bake-off event in 2003, Zhang, et al. <cit.>
proposed a word segmentation approach using hierarchical HMMs
to form a Chinese lexical analyzer, ICTCLAS. In 2005,
Masayuki, et al. <cit.> presented three word segmentation
models, including a character tagging classifier based on
support vector machines (SVM)  that also used maximum expropriation Markov models
and conditional random fields. These models were based on previously proposed
methods, with a different combination of out-of-vocabulary (OOV) extraction
techniques being used.

In general, for Chinese word segmentation,
character-based models perform better than word-based models.
Wang, Zong, and Su <cit.> highlighted that
OOV techniques for word extraction performs poor
for in-vocabulary (IV) words. They proposed a generative model that
performs well on both OOV and IV words, and achieved good results
on the popular SIGHAN datasets. Chen, Chang, and Pei <cit.>
report the use of Gibbs sampling in combination with both word-based hierarchical
process models and character-based HMMs. Their solution achieved better
performance (in terms of $F_1$ score) than the state-of-the-art models at that time.

§ DATASETS

We acquired data and generated additional data for the various parts
of this research. We have Chinese segmentation data,
sentiment analysis data, data consisting of Weibo comments,
and user data corresponding to the Weibo comments data.
This data is split into three datasets, namely,
a Chinese segmentation dataset,
a sentiment analysis dataset,
and a troll detection dataset.
Next, we discuss each of these three datasets.

§.§ Chinese Segmentation Dataset

For Chinese sentence segmentation, we acquired the dataset used in
the SIGHAN 2005 Competition for Chinese sentence processing <cit.>.
This dataset includes training, testing, and validation data. The training data
consists of approximately 860,000 segmented Chinese sentences. Most of these
sentences are from newspapers and published books. The test set includes
about 22,000 unsegmented sentences from similar sources, while the validation
set contains the segmentation of all of the sentences in the test set.
Table <ref> gives additional statistics for this dataset.

Chinese segmentation dataset (SIGHAN 2nd Bakeoff 2005)

Source     Training     Testing
Academia Sincia     708,953     14,432

Peking University     19,056     1,944

City University of Hong Kong     53,019     1,492

Microsoft Research Asia     86,924     3,985

We consider the character-based generative model proposed in <cit.>.
In this model, the features from the training data consist of the positions of each character
in each segmented word. The beginning character in each segment is
marked as $B$, any middle character or characters are marked as $M$, and the ending
character is marked as $E$. On the other hand, all one-character words are marked as $S$.

For example, consider the sample Chinese sentence in Figure <ref>,
which includes the correct segmentation for this sentence.
Table <ref> gives the states corresponding to the sentence
in Figure <ref>.

Sample Chinese sentence segmentation

State sequence for Chinese sentence
马     克     硕     士     毕     业     于     加     州     理     工     学     院     呀
B     E     B     E     B     M     E     B     E     B     E     B     E     S

§.§ Sentiment Analysis Dataset

For sentiment analysis, we use the sentiment training dataset from
the Python SnowNLP package <cit.>. This particular dataset
includes 16,548
sentences with positive sentiment and 18,574 with negative sentiment.
The source for this dataset is Chinese online shopping, movie, and book reviews.
However, this data might not accurately represents tweets and comments
appearing in Weibo.

Since there is no public datasets for Weibo,
we crawled about 5 million Sina Weibo posts to obtain additional data
for our sentiment model. This data includes terms and slang that are

commonly seen on Weibo. From this data, we created a collection of 2,325,644
sentences with positive sentiment and 960,899 sentences with negative sentiment.

From all of our Weibo crawled data, we manually extracted 500 tweets for each of
the six emotions of interest, namely, happiness, surprise, fear, anger, disgust,
and sadness <cit.>. This data will be used to train
an HMM for each emotion.

We process each comment using the Pandas package in Python to remove stop words,
numbers, nonsense emoji, and single-word comments. A language detection method
was implemented to detect non-Chinese comments and translate English comments
into Chinese using the Translator package in Google Translate. We eliminate all
comments that are in languages other than Chinese and English, which results in
a negligible loss of data. In addition, we removed pure re-posts and tagging
that is not relevant to our analysis.

For positive and negative sentiment analysis, we used the Word2Vec embedding
method. The resulting embedding vectors enable us to calculate a word
sentiment score, after segmenting a Weibo comment into a list of word.
For sentiment analysis (based on six basic emotions), we use
the features introduced in <cit.>, which are then used to
train HMMs for sentiment classification. These features are
mutual information,  $\chi^2$ distance, and
term frequency inverse document frequency,
which are defined as follows.

MI— Mutual information (MI) is based on
correlations between two terms. In this research, MI is used to determine the
relevance between words and emotions. The formula for MI representing
the correlation between emotion $e$ and text $t$ is given by

\mbox{MI}(t, e)=\log\frac{P(t\,|\,e)}{P(e)} .

CHI— We use a $\chi^2$ distance measure (CHI) to quantify
the dependence between emotion $e$ and text $t$. The higher the CHI value,
the more dependent the text $t$ is on the emotion $e$. We calculate CHI as

\mbox{CHI}(t, e)=\frac{N(AD - BC)^{2}}{(A + B)(C + D)(A + C)(B + D)} ,

where $A$ is the prevalence of word $t$ in comments with emotion $e$,
$B$ is the prevalence of word $t$ in comments with emotions other than $e$,
$C$ is the absence of word $t$ in comments with emotion $e$,
$D$ is the absence of word $t$ in comments with emotions
other than $e$, and $N$ is the total number of comments.

TF-IDF—  Term frequency inverse document frequency (TF-IDF) was originally
developed to extract key words from text, for purposes such as indexing.
We use TF-IDF to determine key words
with respect to the various emotions under consideration.
We compute the TF-IDF as

\mbox{TF-IDF}(t, e) = \frac{N_{e,t}}{\displaystyle\sum_{k} N_{k,t}} \log{\left(\frac{N}{n_{e}} + 0.01\right)} ,

where $N_{e,t}$ is the number of times word $t$ appears in a comment with
emotion $e$, $N$ is the total number of comments, and $n_{e}$ is the
number of comments in which the emotion $e$ appears.

§.§ Troll Detection Dataset

After some initial experiments, we realized that there are limitations
to the features specified in <cit.> and <cit.>. Therefore,
we introduced more user information related features that we obtained by
mining Weibo comment data. When crawling the Weibo data, we use the
JavaScript object notation (JSON) packet
returned from representational state transfer (REST) calls to the
Weibo mobile site <cit.>,
which includes user-related information.
Typical operations under the REST API include GET, POST, UPDATE,
and DELETE. We extract the user
information listed in Table <ref>. We also include a small dataset
of 673 normal users and 75 trolls from a Kaggle data source <cit.>.

List of user related information from comment data

Field Name     Dataset     Description
UID     Unique User ID for User Account in Weibo

Username     Displayed User Nickname

Follower     User's follower count

Following     User's following count

Original_post     User's original composed tweet count

User_rank     User's rated rank by user activity in Weibo

Verified     Whether user is verified celebrity or business

Description     User's own description in headline

Like_count     Like count of this comment

Floor_number     Location where the comment is at

Comment     Comment content

All user information and corresponding comments are grouped by original
tweet ID and stored in CSV format. One CSV file contains all of the
comments regarding one tweet, and each entry represents all of the information
listed in Table <ref>. We selected eight tweets with a total of 31,980
comments from Sina Weibo accounts belonging primarily to business owners
and celebrities. The detailed tweet information and statistics
for this dataset are listed in Table <ref>.

Statistics of troll detection tweets and comments crawled from Weibo

Tweet ID     User details     Number
1     44275283     LeEco CEO YT Jia declared bankrupt     812

2     44317480     Actress Yiyan Jiang volunteered teaching in rural     829

3     44564209     Yong actress Zi Yang suspected done plastic surgery     335

4     44718878     Reporting fraud in singer Hong Han Foundation receiving donation

5     44651702     Singer Hong Han Foundation donation to Wu Han Coronavirus battle

6     44650056     Criticism of multiple celebrities' donation to Coronavirus battle     814

7     43961306     Suspected breakup of Han Lu and Xiaotong Guan (Actor/ress)     8371

8     43961306     Han Lu and Xiaotong Guan (Actor/ress) showoff their same sweatshirt

We manually labeled the data for rows $1$, $2$, $3$, and $6$
in Table <ref> as troll or non-troll
by examining the content of each comment.

Combining these results with fake account data from <cit.>,
we have about 3500 comment entries for our initial training and testing data
for the troll detection model. This manual labeling is extremely tedious.
To accelerate this process, we created a bot based on Selenium <cit.>
to help open each user's Weibo page based on the UID that we provide from the dataset.

To extract features from the data listed in Table <ref>,
we use Python Pandas <cit.>
and Numpy <cit.>. Some of the available features proved to be
of little use, and these were dropped, as discussed below.
In order to have better features for our models,
we also perform some feature engineering. For example,
we note whether users provide a self-description or not.

Features such as follower count, following count, and the number of
original composed tweets clearly have a high significance in our analysis.
However, we found that building models with quantitative numbers from these categories
biases the model, due to the large differences across users.
Weibo users typically only follow a fairly small number of accounts,
while troll users typically follow a large number of accounts.
Therefore, we dropped the follower and following count in the raw dataset and
instead compute the ratio of following to follower and use this as a feature. Similarly,
we introduce a feature consisting of the ratio of original posts to followers to help identify
troll users, who often make a large number of posts without a
commensurate increase in their follower count—we use this engineered feature
in place of the composed post feature from the raw data.

When crawling Weibo, we noticed that some users frequently comment on the same tweet
rather than replying to other comments under a tweet. Therefore, we select users who have
more than one comment under a tweet and we count the comments made
for each such user. Then we computed the median of these comment counts.
Following this approach, a “frequent comment” feature is generated based
on users who made more comments than the median number.

We have a total of 19 features that we use in our XGBoost model.
One of the engineered features related to the sentiment score is denoted as
. This feature is the score for a comment minus
the sentiment score of the original tweet.
Table <ref> lists the complete set of features that we obtain
by combining sentiment analysis result and user information data in Table <ref>.

Features considered for troll detection model
Feature     Description     Source
F0          Follower count     Crawled Weibo dataset

F1          Following count     Crawled Weibo dataset

F2          Number of original tweets     Crawled Weibo dataset

F3          Rank by user activity in Weibo     Crawled Weibo dataset

F4          User certified or not     Crawled Weibo dataset

F5          Like count for a comment     Crawled Weibo dataset

F6          Comment location     Crawled Weibo dataset

F7          Self description (1 or 0)     Engineered feature

F8          Frequent comments     Engineered feature

F9             divided by      Engineered feature

F10           divided by
Engineered feature

F11          Comment sentiment score (0 to 1)     Engineered feature

F12           minus sentiment of original
Engineered feature

F13          Happiness score (0 to 1)     Engineered feature

F14          Sadness score (0 to 1)     Engineered feature

F15          Anger score (0 to 1)     Engineered feature

F16          Disgust score (0 to 1)     Engineered feature

F17          Fear score (0 to 1)     Engineered feature

F18          Surprise score (0 to 1)     Engineered feature

We would like to
maximize our troll detection accuracy while minimizing the number of
features needed. To achieve this, we perform feature analysis in order to
rank the significance of features, so that we can drop features.
This feature reduction process is discussed below
in Section <ref>.

§ IMPLEMENTATION AND RESULTS

In this section, we give our results. First, we discuss the
Weibo crawler that we have implemented. Then we consider our Chinese
word segmentation results, followed by the our emotion
classification technique, both of which are based on hidden Markov models.
Then we consider our Word2Vec based sentiment score.
and our XGBoost and SVM based troll detection results.
We conclude this section with a discussion of a Chrome
extension that implements this troll detection system.

§.§ Weibo Crawler

As mentioned above, in order to have sufficient
training and testing data, we developed a crawler
to obtain such data directly from the Weibo platform.
Our crawler extracts posts, comments, and user information.

To extract posts, the crawler certain considers a number of tweets under
specific Weibo accounts. Note that Weibo tweets are similar to Twitter tweets,
in that users can retweet others users' posts to their own Weibo account.
The crawler disregards retweets and only keeps original posts.

Comment crawling is used to obtain additional information related to posts.
Most comments contain repetitive messages and include username and hash-tags.
We remove this extraneous data with the Python Panda Dataframe function
before pipelining the comments into the word segmentation stage. Also, it is very
common to see bilingual comments in Weibo, where most of the text
is Chinese, but some English is included. Therefore, we incorporate
a language detection module extended from the Google language library,
which uses  Bayes to filter and translate English to Chinese.

Our comment crawler works on Weibo mobile <cit.> data,
where the tweets and comments page are slightly simplified.
The crawler makes HTTP requests such as

\mbox{\footnotesize\texttt{https://m.weibo.cn/comments/hotflow?id=TWEETID\&mid=TWEETID\&max\_id=}}

which yields JSON data from the Weibo platform containing comments related to
the specified tweet.[One obstacle we encountered
was a change in the Weibo mobile site at the
beginning of 2020. To avoid being blocked when crawling a large number of
comments, we were forced to modify the crawler to use
the “max_ID” property for the current comment page.]
We parse the resulting comment data contained in the JSON packet
to extract all of the raw data, including user information and comment content
using the BeautifulSoup package in Python <cit.>.
After all of the entries have been collected, they are saved into
a CSV file, organized by tweet. Feature extraction and model
training are based on these CSV files.

§.§ HMM for Chinese Segmentation

As illustrated in Table <ref>, above,
when segmenting a Chinese
sentence, we consider four states, namely, B for begin, M for middle, E for end,
and S for single. Thus, we train an HMM with four hidden states.
The observation sequence consists of Chinese characters in the training dataset,
and the hidden states correspond to B, M, E, and S.
It follows that the hidden state transition matrix of the
HMM is $4\times4$ and of the form

\begin{equation}\label{eq:HMMstateMatrix}
\begin{bmatrix}
\mbox{B}\to \mbox{B} & \mbox{B}\to \mbox{E} & \mbox{B}\to \mbox{M} & \mbox{B}\to \mbox{S}\\
\mbox{E}\to \mbox{B} & \mbox{E}\to \mbox{E} & \mbox{E}\to \mbox{M} & \mbox{E}\to \mbox{S}\\
\mbox{M}\to \mbox{B} & \mbox{M}\to \mbox{E} & \mbox{M}\to \mbox{M} & \mbox{M}\to \mbox{S}\\
\mbox{S}\to \mbox{B} & \mbox{S}\to \mbox{E} & \mbox{S}\to \mbox{M} & \mbox{S}\to \mbox{S}
\end{bmatrix}\mbox{.}
\end{equation}

We implemented this HMM-based Chinese text segmentation,
which is similar to that in <cit.>.
When training, the first character of each segmented word is marked
as a beginning state (B). Then characters are marked as middle states (M),
until the last character is read, which is marked as an end state (E),
with any single-character words marked as such (S).
The emission probability,
the state transition probability,
and the initial state probability
are then used to update the state transition probability matrix
in eq:HMMstateMatrix.
Subsequently, we use the trained HMM
to segment Weibo posts and comments
line by line.

§.§ HMM for Emotion Classification

For each word in a tweet or comment, we can calculate a three-dimensional
vector based on its MI, CHI, and TF-IDF scores,
as discussed in Section <ref>, above.
After calculating the feature vectors for each emotion, we obtain
a mean value of each feature over all tweets labeled by each specific emotion.
This mean value is used as an observation. The transition feature
between states $S_{k-1}$ and $S_{k}$ is computed as

P(S_{k} = s_{p}\,|\, S_{k-1} = s_{q}) =
\left\{\hspace*{-0.035in}
\begin{array}{cl}
1 & \mbox{if } p=q+1\\
0 & \mbox{otherwise}
\end{array}
\right. ,

where the HMM states $S_k$ correspond to the features
MI, CHI, and TF-IDF. This
determines how close a feature vector in the test tweet is to
those in the training set, with respect to the various emotions.
The emission probability

P(y_{k}\,|\,S_{k}^{e_{i}}) = J(y_{k}\,|\,S_{k}^{e_{i}}) = \frac{M_{11}}{M_{11}+M_{10}+M_{01}}

can be calculated by Jaccard similarity <cit.>, which
measures the correlation between the feature vector $y_{k}$ and
the state $S_{k}$, where $M_{11}$ is the total number of tweets containing
feature vector $y_{k}$ and state $S_{k}$ with respect to emotion $e_{i}$,
$M_{10}$ is the number of tweets containing only state $S_{k}$
with respect to emotion $e_{i}$, and $M_{01}$
is the number of tweets containing only feature vector $y_{k}$ with respect to emotion $e_{i}$.

Table <ref> gives an example of
the relationship between three consecutive words $w_0$, $w_1$, and $w_2$
in a particular test case.

Features for words $w_0$, $w_1$, and $w_2$ with respect to each emotion

Word     Emotion
1c|MI     1c|CHI

Happiness     0.0012     0.0247     0.0009

Anger     0.0012     0.0247     0.0070

Sadness     0.0015     0.0100     0.0450

Surprise     0.0080     $-0.0050$     0.0220

Disgust     0.0020     0.0470     0.0117

Fear     0.2200     0.0700     0.0009

Happiness     0.0167     0.0064     0.1045

Anger     $-0.0012$     0.0247     0.0009

Sadness     0.0200     $-0.1416$     0.0009

Surprise     0.0012     $-0.0247$     $-0.0009$

Disgust     $-0.0012$     0.0247     0.0009

Fear     0.0012     0.0247     $-0.0009$

Happiness     0.0012     0.0247     0.0009

Anger     0.0012     0.0247     0.0070

Sadness     0.0015     0.0100     0.0450

Surprise     0.3693     0.0820     $-0.0119$

Disgust     0.0526     0.0247     0.0008

Fear     0.0012     0.0247     0.0007

We train an HMM for each of the six emotions. Then, we score a sample against
each model, and assign an emotion to the tweet based on the largest probability.

§.§ Sentiment Score Calculation

We first construct
a Word2Vec model
based on the 35,124 online shopping reviews
contained in the sentiment analysis
dataset discussed in Section <ref>.
Note that this Word2Vec model
is based on segmented Chinese text.
We use the GenSim
package in Python <cit.> to train this Word2Vec model.

Next, the resulting Word2Vec embeddings are used
to assign a sentiment score

to segmented Chinese words,
based on 3,286,543 tweets that we crawled from Weibo.
Thess sentiment scores are determined using  Bayes.

Specifically, we use  Bayes to compute

P(c_{1}\,|\,w_{1},\ldots,w_{n}) = \frac{P(w_{1},\ldots,w_{n}\,|\,c_{1}) P(c_{1})}{
P(w_{1},\ldots,w_{n}\,|\,c_{1}) P(c_{1}) + P(w_{1},\ldots,w_{n}\,|\,c_{2}) P(c_{2})} ,

where $c_{1}$ represents the event that a word is positive
and $c_{2}$ represents the event that a word is negative.
Our sentiment score is computed as the product of $P(c_{1}\,|\,w_{1},\ldots,w_{n})$
and the word similarity score computed using the Word2Vec model.

The resulting score can be viewed as the probability of a word
in a tweet being positive, where 0 represents an extremely negative word,
while 1 represents an extremely positive word.
Figure <ref> illustrates
a sample sentiment score distribution for one of our training datasets.
Note that this particular bar graph is based on the 812 comments
corresponding to Weibo tweet ID 44275293, as listed in Table <ref>.
Figure <ref> shows the sentiment score frequency
count distribution for all 812 comments with brackets of width 0.02
over the range of 0 to 1.

Sentiment score distribution for comments in Table <ref>, Row 1

§.§ Troll Detection with XGBoost and SVM

Our troll detection model is based on XGBoost.
We train our XGBoost models
using Python under the Jupyter Notebook environment.
For these XGBoosting troll detection models, we drop
non-quantitative features, which leaves us with the features listed
in Table <ref>. Training an XGBoost model
on all of these features, we achieve about 80% accuracy.

Troll detection statistics crawled from Weibo

Feature     Description
F0          Follower count

F1          Following count

F2          Number of original tweets

F3           divided by

F4           divided by

F5          User activity rank in Weibo

F6          User certified or not

F7          User's self description (1 or 0)

F8          User comments frequently or not

F9          Like count for comment

F10          Location of comment

F11          Sentiment score of the comment (0 to 1)

F12           minus sentiment of original

Ranking the features in this full-feature XGBoost model, we obtain the results in
Figure <ref>. Note that F12 in Figure <ref>
has a weight of 0, which implies that F12 (the  feature)
contributed nothing to the classification.

Initial XGBoost features ranking

Next, we consider recursive feature elimination (RFE),
where we drop the lowest ranked feature, then retrain the model.
Our RFE results are given in Figure <ref>.
We observe that the model improves when we drop the two
lowest ranked features, namely, F12 and F8, but beyond that,
the model will lose accuracy if we drop additional features.
Hence, our optimal XGBoost model uses all of the features in
Table <ref>,
except F8 and F12. With this model,
we achieve an accuracy of about 82%.

XGBoost model accuracy vs numbers of features

The features used and their relative importance rank are given in
Figure <ref>. Note that these are the features in
the XGBoost model.

XGBoost features and rankings

For comparison with our XGBoost classifier, we also experiment with
an SVM classifier. We utilize the Python scikit-learn package <cit.>
to train our SVM classifier.
We compare the results of these SVM classification
experiments to the XGBoost experiments,
based over two different datasets and various sets
of features. Next, we summarize these results.

As discussed above, using XGBoost as our classification method
and RFE, we achieve an accuracy of about 82%.
With some additional feature engineering,
we were able to increase this troll detection accuracy
to 83.64% on our Weibo crawled dataset,
using only the three features
labeled as F9, F10, F11 in Figure <ref>.

In addition, using our SVM classifier, we achieve 87.27% accuracy
on the same dataset, based on the same three features.

As another experiment, we compare our XGBoost and SVM

models using the SnowNLP sentiment dataset for the sentiment score calculation.
By using this training dataset for sentiment analysis, and with

the addition of features F3

and F6,

the accuracy for XGBoost is 89%.
However, with this same dataset and feature set,
the SVM model achieves an accuracy of only 81.82%.
These accuracy are summarized in the form of a bar graph in Figure <ref>.

Comparison of XGBoost and SVM

Our experimental results show that we can achieve an accuracy as high as 89%,
which far exceeds the 78% accuracy obtained in the
comparable previous work in <cit.>, and matches the accuracy
in the previous work <cit.>.
A significant advantage of our approach is that it only requires a small number of
easily obtained features, as compared to any previous research.
This makes our troll detection technique highly efficient, and thus suitable for
real-time troll detection, as validated by the Chrome extension
discussed in Section <ref>, above.

§.§ Chrome Extension for Troll Detection

Since our troll detection mechanism is written in Python,
for real-time troll detection on the Sina Weibo mobile website,
we created a Chrome extension using HTML and JavaScript.
In this extension,
we pass the JSON packet with Weibo comment information to the
back-end, which is built on the Django framework <cit.>.
This back-end implements our troll detection model, as discussed above.
The overall workflow for the plug-in is summarized as follows.

* Run the crawler script against all the comments currently displayed
in the browser under one tweet and send the packet to a server-side portal
(currently running as localhost).

* On the server-side, sort the essential user information and comment text
from the returned JSON packet, as generated by the crawler.

* On the server-side, run our sentiment analysis classifier
against the comment text and acquire the text sentiment scores.

* On the server-side, aggregate the sentiment scores and other user information,
feed these into our troll detection model, and return the troll detection result to the client-side plug-in.

* Modify the CSS style sheet for any detected troll comments
by adding an orange background behind the text.

A screenshot showing this plug-in in action is given in Figure <ref>.
Note that in this implementation, tweets and comments that have been flagged as
potential troll activity are blurred.

Chrome extension employing troll detection model

§ CONCLUSION AND FUTURE WORK

The widespread use of social media enables information
transfer to occur much faster than ever before. However, troll activities detract from
the utility of social media. Trolls have a variety of motivations, ranging from
deception to profits, and it is not likely that these motivating factors
will diminish in the future. Therefore, intelligent defenses against trolls
are essential.

In this research, we utilized a variety of machine learning techniques to
analyze comment content and user information on the Sina Weibo platform.
By conducting sentiment analysis and by including user data aggregation,
we were able to efficiently identify troll comments on Sina Weibo with
higher accuracy, as compared to previous work.
We developed a Chrome extension that served to highlight the
practicality of our approach.

For future work, more user data and other features can be considered.
In addition, deep learning techniques that utilize sequential information, such as
long short term memory (LSTM) networks, could prove
useful. The Chrome extension that we have developed could be extended to
support the Weibo desktop platform.