Freddie Gray protests in Baltimore in 2015
© ReutersThe Freddie Gray protests in Baltimore in 2015, which were studied by the researchers
Twitter seems a battleground at all times, but it is a very specific type of message that appears before words online turn to actions on the street, say US researchers who developed an algorithm for predicting public violence.

"Our findings suggest that people are more likely to condone violent protest of an issue when they both see it at as a moral issue and believe others share this position, a pattern we refer to as moral convergence," Morteza Dehghani, lead author of the study, which appeared in Nature, told Digital Trends.

The team from the University of Southern California picked the 2015 Black Lives Matter riots in Baltimore that followed the death of Freddie Gray while in police custody. With 18 million messages posted on Twitter at the time referencing the riots, and near-hourly swings in the level of hostilities, there was plenty of scope for empirical research.

To detail the findings of the researchers, the main factor for rioting - and in this case clashing with police, formal protectors of the law - was a situation in which the protesters felt that they were "in the right"and represented the "good guys," which justified them unleashing violence, particularly at moments when they thought hundreds or thousands of others shared their view, something social media encourages by its nature.

Moral convergence turned out to be a sensitive weathervane.

"By tracking moralized tweets posted during the 2015 Baltimore protests, we were able to observe that not only did their volume increase on days with violent protests, but also that their volume predicted hourly arrest rates, which we used as a proxy for violence, during the protests," said Dehghani.

Methodologically, the authors created an AI algorithm that predicted a link between the tweets and the street action, which then used machine learning to become more complex and accurate at identifying the tension spikes - hours in advance of actual clashes.

The researchers then performed 15 "controlled behavioral experiments" that showed that their AI algorithm was correct.

The study will be of great interest to the authorities, who can use the same mechanism to anticipate demonstrations, and appease or counter the protesters, before they themselves even realize that they will soon be taking to the streets.