Psychologist Michal Kosinski says artificial intelligence can detect your sexuality and politics just by looking at your face. What if he’s right?

Vladimir Putin was not in attendance, but his loyal lieutenants were. On 14 July last year, the Russian prime minister, Dmitry Medvedev, and several members of his cabinet convened in an office building on the outskirts of Moscow. On to the stage stepped a boyish-looking psychologist, Michal Kosinski, who had been flown from the city centre by helicopter to share his research. “There was Lavrov, in the first row,” he recalls several months later, referring to Russia’s foreign minister. “You know, a guy who starts wars and takes over countries.” Kosinski, a 36-year-old assistant professor of organisational behaviour at Stanford University, was flattered that the Russian cabinet would gather to listen to him talk. “Those guys strike me as one of the most competent and well-informed groups,” he tells me. “They did their homework. They read my stuff.”

Kosinski’s “stuff” includes groundbreaking research into technology, mass persuasion and artificial intelligence (AI) – research that inspired the creation of the political consultancy Cambridge Analytica. Five years ago, while a graduate student at Cambridge University, he showed how even benign activity on Facebook could reveal personality traits – a discovery that was later exploited by the data-analytics firm that helped put Donald Trump in the White House.

That would be enough to make Kosinski interesting to the Russian cabinet. But his audience would also have been intrigued by his work on the use of AI to detect psychological traits. Weeks after his trip to Moscow, Kosinski published a controversial paper in which he showed how face-analysing algorithms could distinguish between photographs of gay and straight people. As well as sexuality, he believes this technology could be used to detect emotions, IQ and even a predisposition to commit certain crimes. Kosinski has also used algorithms to distinguish between the faces of Republicans and Democrats, in an unpublished experiment he says was successful – although he admits the results can change “depending on whether I include beards or not”.

Progress makes people uncomfortable. When the first monkeys walked, other monkeys probably said, 'This is outrageous!'

How did this 36-year-old academic, who has yet to write a book, attract the attention of the Russian cabinet? Over our several meetings in California and London, Kosinski styles himself as a taboo-busting thinker, someone who is prepared to delve into difficult territory concerning artificial intelligence and surveillance that other academics won’t. “I can be upset about us losing privacy,” he says. “But it won’t change the fact that we already lost our privacy, and there’s no going back without destroying this civilisation.”

The aim of his research, Kosinski says, is to highlight the dangers. Yet he is strikingly enthusiastic about some of the technologies he claims to be warning us about, talking excitedly about cameras that could detect people who are “lost, anxious, trafficked or potentially dangerous. You could imagine having those diagnostic tools monitoring public spaces for potential threats to themselves or to others,” he tells me. “There are different privacy issues with each of those approaches, but it can literally save lives.”

“Progress always makes people uncomfortable,” Kosinski adds. “Always has. Probably, when the first monkeys stopped hanging from the trees and started walking on the savannah, the monkeys in the trees were like, ‘This is outrageous! It makes us uncomfortable.’ It’s the same with any new technology.”

***

Kosinski has analysed thousands of people’s faces, but never run his own image through his personality-detecting models, so we cannot know what traits are indicated by his pale-grey eyes or the dimple in his chin. I ask him to describe his own personality. He says he’s a conscientious, extroverted and probably emotional person with an IQ that is “perhaps slightly above average.” He adds: “And I’m disagreeable.” What made him that way? “If you trust personality science, it seems that, to a large extent, you’re born this way.”

His friends, on the other hand, describe Kosinski as a brilliant, provocative and irrepressible data scientist who has an insatiable (some say naive) desire to push the boundaries of his research. “Michal is like a small boy with a hammer,” one of his academic friends tells me. “Suddenly everything looks like a nail.”

Born in 1982 in Warsaw, Kosinski inherited his aptitude for coding from his parents, both of whom trained as software engineers. Kosinski and his brother and sister had “a computer at home, potentially much earlier than western people of the same age”. By the late 1990s, as Poland’s post-Soviet economy was opening up, Kosinski was hiring his schoolmates to work for his own IT company. This business helped fund him through university, and in 2008 he enrolled in a PhD programme at Cambridge, where he was affiliated with the Psychometrics Centre, a facility specialising in measuring psychological traits.

It was around that time that he met David Stillwell, another graduate student, who had built a personality quiz and shared it with friends on Facebook. The app quickly went viral, as hundreds and then thousands of people took the survey to discover their scores according to the “Big Five” metrics: openness, conscientiousness, extraversion, agreeableness and neuroticism. When users completed the myPersonality tests, some of which also measured IQ and wellbeing, they were given an option to donate their results to academic research.

Kosinski came on board, using his digital skills to clean, anonymise and sort the data, and then make it available to other academics. By 2012, more than 6 million people had taken the tests – with about 40% donating their data, creating the largest dataset of its kind.

Facebook Twitter Pinterest From Cesare Lombroso’s criminal taxonomy: a ‘habitual thief’…

Facebook Twitter Pinterest …and a murderer. Photographs: Alamy

In May, New Scientist magazine revealed that the dataset’s username and password had been accidentally left on GitHub, a commonly used code-sharing website. For four years, anyone – not just authorised researchers – could have accessed the data. Before the magazine’s investigation, Kosinski had admitted to me that there were risks to their liberal approach. “We anonymised the data, and we made scientists sign a guarantee that they will not use it for any commercial reasons,” he had said. “But you just can’t really guarantee that this will not happen.” Much of the Facebook data, he added, was “de-anonymisable”. In the wake of the New Scientist story, Stillwell closed down the myPersonality project. Kosinski sent me a link to the announcement, complaining: “Twitter warriors and sensation-seeking writers made David shut down the myPersonality project.”

During the time the myPersonalitydata was accessible, about 280 researchers used it to publish more than 100 academic papers. The most talked-about was a 2013 study co-authored by Kosinski, Stillwell and another researcher, that explored the relationship between Facebook “Likes” and the psychological and demographic traits of 58,000 people. Some of the results were intuitive: the best predictors of introversion, for example, were Likes for pages such as “Video Games” and “Voltaire”. Other findings were more perplexing: among the best predictors of high IQ were Likes on the Facebook pages for “Thunderstorms” and “Morgan Freeman’s Voice”. People who Liked pages for “iPod” and “Gorillaz” were likely to be dissatisfied with life.

If an algorithm was fed with sufficient data about Facebook Likes, Kosinski and his colleagues found, it could make more accurate personality-based predictions than assessments made by real-life friends. In other research, Kosinski and others showed how Facebook data could be turned into what they described as “an effective approach to digital mass persuasion”.

Their research came to the attention of the SCL Group, the parent company of Cambridge Analytica. In 2014, SCL tried to enlist Stillwell and Kosinski, offering to buy the myPersonality data and their predictive models. When negotiations broke down, they relied on the help of another academic in Cambridge’s psychology department – Aleksandr Kogan, an assistant professor. Using his own Facebook personality quiz, and paying users (with SCL money) to take the tests, Kogan collected data on 320,000 Americans. Exploiting a loophole that allowed developers to harvest data belonging to the friends of Facebook app users (without their knowledge or consent), Kogan was able to hoover up additional data on as many as 87 million people.

Facebook Twitter Pinterest Cambridge Analytica whistleblower Christopher Wylie who says the company tried to replicate Kosinski’s work for ‘psychological warfare’. Photograph: Getty Images

Christopher Wylie, the whistleblower who lifted the lid on Cambridge Analytica’s operations earlier this year, has described how the company set out to “replicate” the work done by Kosinski and his colleagues, and to turn it into an instrument of “psychological warfare”. “This is not my fault,” Kosinski told reporters from the Swiss publication Das Magazin, which was the first to make the connection between his work and Cambridge Analytica. “I did not build the bomb. I only showed that it exists.”

Cambridge Analytica always denied using Facebook-based psychographic targeting during the Trump campaign, but the scandal over its data harvesting forced the company to close. The saga also proved highly damaging to Facebook, whose headquarters are less than four miles from Kosinski’s base at Stanford’s Business School in Silicon Valley. The first time I enter his office, I ask him about a painting beside his computer, depicting a protester armed with a Facebook logo in a holster instead of a gun. “People think I’m anti-Facebook,” Kosinski says. “But I think that, generally, it is just a wonderful technology”.

Still, he is disappointed in the Facebook CEO, Mark Zuckerberg, who, when he testified before US Congress in April, said he was trying to find out “whether there was something bad going on at Cambridge University”. Facebook, Kosinski says, was well aware of his research. He shows me emails he had with employees in 2011, in which they disclosed they were “using analysis of linguistic data to infer personality traits”. In 2012, the same employees filed a patent, showing how personality characteristics could be gleaned from Facebook messages and status updates.

Kosinski seems unperturbed by the furore over Cambridge Analytica, which he feels has unfairly maligned psychometric micro-targeting in politics. “There are negative aspects to it, but overall this is a great technology and great for democracy,” he says. “If you can target political messages to fit people’s interests, dreams, personality, you make those messages more relevant, which makes voters more engaged – and more engaged voters are great for democracy.” But you can also, I say, use those same techniques to discourage your opponent’s voters from turning out, which is bad for democracy. “Then every politician in the US is doing this,” Kosinski replies, with a shrug. “Whenever you target the voters of your opponent, this is a voter-suppression activity.”

Kosinski’s wider complaint about the Cambridge Analytica fallout, he says, is that it has created “an illusion” that governments can protect data and shore up their citizens’ privacy. “It is a lost war,” he says. “We should focus on organising our society in such a way as to make sure that the post-privacy era is a habitable and nice place to live.”

***

Kosinski says he never set out to prove that AI could predict a person’s sexuality. He describes it as a chance discovery, something he “stumbled upon”. The lightbulb moment came as he was sifting through Facebook profiles for another project and started to notice what he thought were patterns in people’s faces. “It suddenly struck me,” he says, “introverts and extroverts have completely different faces. I was like, ‘Wow, maybe there’s something there.’”

Physiognomy, the practice of determining a person’s character from their face, has a history that stretches back to ancient Greece. But its heyday came in the 19th century, when the Italian anthropologist Cesare Lombroso published his famous taxonomy, which declared that “nearly all criminals” have “jug ears, thick hair, thin beards, pronounced sinuses, protruding chins, and broad cheekbones”. The analysis was rooted in a deeply racist school of thought that held that criminals resembled “savages and apes”, although Lombroso presented his findings with the precision of a forensic scientist. Thieves were notable for their “small wandering eyes”, rapists their “swollen lips and eyelids”, while murderers had a nose that was “often hawklike and always large”.

Lombroso’s remains are still on display in a museum in Turin, besides the skulls of the hundreds of criminals he spent decades examining. Where Lombroso used calipers and craniographs, Kosinski has been using neural networks to find patterns in photos scraped from the internet.

Kosinski received emails from people confused about their sexuality who hoped he'd run their photo through his algorithm

Kosinski’s research dismisses physiognomy as “a mix of superstition and racism disguised as science” – but then argues it created a taboo around “studying or even discussing the links between facial features and character”. There is growing evidence, he insists, that links between faces and psychology exist, even if they are invisible to the human eye; now, with advances in machine learning, such links can be perceived. “We didn’t have algorithms 50 years ago that could spot patterns,” he says. “We only had human judges.”

In a paper published last year, Kosinski and a Stanford computer scientist, Yilun Wang, reported that a machine-learning system was able to distinguish between photos of gay and straight people with a high degree of accuracy. They used 35,326 photographs from dating websites and what Kosinski describes as “off-the-shelf” facial-recognition software.

Presented with two pictures – one of a gay person, the other straight – the algorithm was trained to distinguish the two in 81% of cases involving images of men and 74% of photographs of women. Human judges, by contrast, were able to identify the straight and gay people in 61% and 54% of cases, respectively. When the algorithm was shown five facial images per person in the pair, its accuracy increased to 91% for men, 83% for women. “I was just shocked to discover that it is so easy for an algorithm to distinguish between gay and straight people,” Kosinski tells me. “I didn’t see why that would be possible.”

Facebook Twitter Pinterest ‘I did not build the bomb. I only showed it exists.’ Photograph: Jason Henry/The Guardian

Neither did many other people, and there was an immediate backlash when the research – dubbed “AI gaydar” – was previewed in the Economist magazine. Two of America’s most prominent LGBTQ organisations demanded that Stanford distance itself from what they called its professor’s “dangerous and flawed research”. Kosinski received a deluge of emails, many from people who told him they were confused about their sexuality and hoped he would run their photo through his algorithm. (He declined.) There was also anger that Kosinski had conducted research on a technology that could be used to persecute gay people in countries such as Iran and Saudi Arabia, where homosexuality is punishable by death.

Kosinski says his critics missed the point. “This is the inherent paradox of warning people against potentially dangerous technology,” he says. “I stumbled upon those results, and I was actually close to putting them in a drawer and not publishing – because I had a very good life without this paper being out. But then a colleague asked me if I would be able to look myself in the mirror if, one day, a company or a government deployed a similar technique to hurt people.” It would, he says, have been “morally wrong” to bury his findings.

One vocal critic of that defence is the Princeton professor Alexander Todorov, who has conducted some of the most widely cited research into faces and psychology. He argues that Kosinski’s methods are deeply flawed: the patterns picked up by algorithms comparing thousands of photographs may have little to do with facial characteristics. In a mocking critique posted online, Todorov and two AI researchers at Google argued that Kosinski’s algorithm could have been responding to patterns in people’s makeup, beards or glasses, even the angle they held the camera at. Self-posted photos on dating websites, Todorov points out, project a number of non-facial clues.

Kosinski acknowledges that his machine learning system detects unrelated signals, but is adamant the software also distinguishes between facial structures. His findings are consistent with the prenatal hormone theory of sexual orientation, he says, which argues that the levels of androgens foetuses are exposed to in the womb help determine whether people are straight or gay. The same androgens, Kosinski argues, could also result in “gender-atypical facial morphology”. “Thus,” he writes in his paper, “gay men are predicted to have smaller jaws and chins, slimmer eyebrows, longer noses and larger foreheads... The opposite should be true for lesbians.”

If you basically accept we’re just computers, then computers are not guilty of crime

This is where Kosinski’s work strays into biological determinism. While he does not deny the influence of social and environmental factors on our personalities, he plays them down. At times, what he says seems eerily reminiscent of Lombroso, who was critical of the idea that criminals had “free will”: they should be pitied rather than punished, the Italian argued, because – like monkeys, cats and cuckoos – they were “programmed to do harm”.

“I don’t believe in guilt, because I don’t believe in free will,” Kosinski tells me, explaining that a person’s thoughts and behaviour “are fully biological, because they originate in the biological computer that you have in your head”. On another occasion he tells me, “If you basically accept that we’re just computers, then computers are not guilty of crime. Computers can malfunction. But then you shouldn’t blame them for it.” The professor adds: “Very much like: you don’t, generally, blame dogs for misbehaving.”

Todorov believes Kosinski’s research is “incredibly ethically questionable”, as it could lend a veneer of credibility to governments that might want to use such technologies. He points to a paper that appeared online two years ago, in which Chinese AI researchers claimed they had trained a face-recognition algorithm to predict – with 90% accuracy – whether someone was a convicted criminal. The research, which used Chinese government identity photographs of hundreds of male criminals, was not peer-reviewed, and was torn to shreds by Todorov, who warned that “developments in artificial intelligence and machine learning have enabled scientific racism to enter a new era”.

Kosinski has a different take. “The fact that the results were completely invalid and unfounded, doesn’t mean that what they propose is also wrong,” he says. “I can’t see why you would not be able to predict the propensity to commit a crime from someone’s face. We know, for instance, that testosterone levels are linked to the propensity to commit crime, and they’re also linked with facial features – and this is just one link. There are thousands or millions of others that we are unaware of, that computers could very easily detect.”

Would he ever undertake similar research? Kosinski hesitates, saying that “crime” is an overly blunt label. It would be more sensible, he says, to “look at whether we can detect traits or predispositions that are potentially dangerous to an individual or society – like aggressive behaviour”. He adds: “I think someone has to do it… Because if this is a risky technology, then governments and corporations are clearly already using it.”

***

But when I press Kosinski for examples of how psychology-detecting AI is being used by governments, he repeatedly falls back on an obscure Israeli startup, Faception. The company provides software that scans passports, visas and social-media profiles, before spitting out scores that categorise people according to several personality types. On its website, Faception lists eight such classifiers, including “White-Collar Offender”, “High IQ”, “Paedophile” and “Terrorist”. Kosinski describes the company as “dodgy” – a case study in why researchers who care about privacy should alert the public to the risks of AI. “Check what Faception are doing and what clients they have,” he tells me during an animated debate over the ethics of his research.

I call Faception’s chief executive, Shai Gilboa, who used to work in Israeli military intelligence. He tells me the company has contracts working on “homeland security and public safety” in Asia, the Middle East and Europe. To my surprise, he then tells me about a research collaboration he conducted two years ago. “When you look in the academia market you’re looking for the best researchers, who have very good databases and vast experience,” he says. “So this is the reason we approached Professor Kosinski.”

But when I put this connection to Kosinski, he plays it down: he claims to have met Faception to discuss the ethics of facial-recognition technologies. “They came [to Stanford] because they realised what they are doing has potentially huge negative implications, and huge risks.” Later, he concedes there was more to it. He met them “maybe three times” in Silicon Valley, and was offered equity in the company in exchange for becoming an adviser (he says he declined).

Kosinski denies having collaborated on research, but admits Faception gave him access to its facial-recognition software. He experimented with Facebook photos in the myPersonality dataset, he says, to determine how effective the Faception software was at detecting personality traits. He then suggested Gilboa talk to Stillwell about purchasing the myPersonality data. (Stillwell, Kosinski says, declined.)

He bristles at my suggestion that these conversations seem ethically dubious. “I will do a lot of this,” he says. “A lot of startup people come here and they don’t offer you any money, but they say, ‘Look, we have this project, can you advise us?’” Turning down such a request would have made him “an arrogant prick”.

He gives a similar explanation for his trip to Moscow, which he says was arranged by Sberbank Corporate University as an “educational day” for Russian government officials. The university is a subsidiary of Sberbank, a state-owned bank sanctioned by the EU; its chief executive, Russia’s former minister for economic development, is close to Putin. What was the purpose of the trip? “I didn’t really understand the context,” says Kosinski. “They put me on a helicopter, flew me to a place, I came on the stage. On the helicopter I was given a briefing about who was going to be in the room. Then I gave a talk, and we talked about how AI is changing society. And then they sent me off.”

'Surveillance society': has technology at the US-Mexico border gone too far? Read more

The last time I see Kosinski, we meet in London. He becomes prickly when I press him on Russia, pointing to its dire record on gay rights. Did he talk about using facial-recognition technology to detect sexuality? Yes, he says – but this talk was no different from other presentations in which he discussed the same research. (A couple of days later, Kosinski tells me he has checked his slides; in fact, he says, he didn’t tell the Russians about his “AI gaydar”.)

Who else was in the audience, aside from Medvedev and Lavrov? Kosinski doesn’t know. Is it possible he was talking to a room full of Russian intelligence operatives? “That’s correct,” he says. “But I think that people who work for the surveillance state, more than anyone, deserve to know that what they are doing is creating real risk.” He tells me he is no fan of Russia, and stresses there was no discussion of spying or influencing elections. “As an academic, you have a duty to try to counter bad ideas and spread good ideas,” he says, adding that he would talk to “the most despicable dictator out there”.

I ask Kosinski if anyone has tried to recruit him as an intelligence asset. He hedges. “Do you think that if an intelligence agency approaches you they say: ‘Hi, I’m the CIA’?” he replies. “No, they say, ‘Hi, I’m a startup, and I’m interested in your work – would you be an adviser?’ That definitely happened in the UK. When I was at Cambridge, I had a minder.” He tells me about a British defence expert he suspected worked for the intelligence services who took a keen interest in his research, inviting him to seminars attended by officials in military uniforms.

In one of our final conversations, Kosinski tells me he shouldn’t have talked about his visit to Moscow, because his hosts asked him not to. It would not be “elegant” to mention it in the Guardian, he says, and besides, “it is an irrelevant fact”. I point out that he already left a fairly big clue on Facebook, where he posted an image of himself onboard a helicopter with the caption: “Taking off to give a talk for Prime Minister Medvedev.” He later changed his privacy settings: the photo was no longer public, but for “friends only”.

• Comments on this piece are premoderated to ensure the discussion remains on the topics raised by the article.

Commenting on this piece? If you would like your comment to be considered for inclusion on Weekend magazine’s letters page in print, please email weekend@theguardian.com, including your name and address (not for publication).