(by Alessandro Bellina, Gabriele Di Bona, and Emanuele Brugnoli)
This repository analyzes Twitter data to detect language bubbles in social networks. The scripts build the retweet network of users on Twitter and then partition them into communities using hSBM and Louvain algorithms. The content of the tweets is then analyzed to compute lexical metrics for each user and community. Finally, a sampling analysis is performed to obtain the final results. In addition, code for testing the lexical metrics and for computing the null models is provided.
Our analysis is based on Italian tweets from politicians and news outlets, spanning from 2018 to 2022. In the tweets_id folder, we report the IDs of all the tweets used in the analysis, organized by year.
To replicate the analysis, one should reconstruct the dataset of tweets starting from these tweet IDs. It is also necessary to create two files: retweets.csv (each row is a retweet), and twitter_users.csv (each row is a user), corresponding to the same tweets whose IDs are reported in the folder.
create_topics.ipynb extracts tweets for each specific topic, starting from the general dataset described above.
retweet_analysis.ipynb creates the bipartite retweet network, projects it, computes the clustering partition with Louvain, and computes the inverse distance matrix on the retweet network.
lexical_metrics.ipynb lemmatizes and removes stopwords from tweets, removes the kernel lexicon, computes the validated projection, the Jensen-Shannon distance matrix, and the lexical metrics (entropy, vocabulary size, completeness).
hsbm_clustering.ipynb computes the community partitioning via the hSBM algorithm.
sampling_analysis.ipynb performs the final subsampling analysis and generates the files for the figures.
figures.ipynb and fig_network.ipynb generate the final figures shown in the paper.
The null_model folder contains all scripts for performing the null model analysis.
The test_metrics folder provides code for testing the lexical metrics on texts of varying complexity (from Gutenberg).
If you use any of the material provided here, please cite our work using the following BibTeX entry:
@article{TODO,
title={Language bubbles in online social networks},
author={Bellina, Alessandro and Lo Sardo, Ruggiero and Brugnoli, Emanuele and Saracco, Fabio and Gravino, Pietro and Loreto, Vittorio and Di Bona, Gabriele},
journal={TODO},
year={2025},
doi={TODO}
}