BAGHDAD (AP) — Farida Khalaf somehow kept her composure as she returned to her devastated home village in northern Iraq for the first time in four years — until she entered the schoolhouse.

That was where the Islamic State militants had separated her and other Yazidi women from their male relatives, selling the women into sexual slavery and sending the men to their deaths. Today, the walls are covered with the portraits of those who were killed.

She fell to her knees and sobbed uncontrollably.

Inside a school in the Iraqi village of Kocho, Farida Khalaf cries as she looks at photographs of fellow Yazidis who were killed by Islamic State militants. (Yazda via AP)

Khalaf was just 18 years old when she was captured and sold into slavery, and endured four months of rape, torture and beatings until she managed to escape. She later wrote about her experiences in "The Girl Who Beat Isis: My Story," published in 2016.

The Associated Press does not generally identify the victims of sexual assault, but Khalaf has gone public with her story.

On Tuesday she returned to her village of Kocho for the first time since she was captured, passing rows of homes and buildings destroyed in the battle to retake the village in 2015.

"It was very difficult for me to think that I would come back to Kocho again," Khalaf said later, as she stood inside an empty classroom looking at the photos of the dead.

Farida Khalaf stands with a group of men looking at a mass grave in her home village of Kocho in northern Iraq. (Yazda via AP)

"I will never forget the day Daesh came and they gathered us in the school and separated us from our families, that will never leave my mind," she said, using the Arabic acronym for the extremist group.

The militants swept into Sinjar, the ancestral homeland of the Yazidis near the Syrian border, in August 2014, after capturing the northern city of Mosul and declaring an Islamic caliphate in large areas of Iraq and neighboring Syria. Tens of thousands of Yazidis escaped to Mount Sinjar, where most were eventually rescued by U.S.-backed Kurdish forces.

Those who stayed behind met the fate of Khalaf and her family.

The Yazidis are an ancient religious minority, falsely branded as devil-worshippers by Sunni Muslim extremists. IS, adopting a radical interpretation of ancient Islamic texts, declared that Yazidi women and even young girls could be taken as slaves.

Farida Khalaf, a young Yazidi woman who escaped the horrors of captivity and abuse by the Islamic State group, walks through her village of Kocho in Iraq. (Yazda via AP)

Khalaf was taken to the schoolhouse and separated from her father and older brother, who were killed. She and her mother were among thousands of women who were bused from Sinjar to the Syrian city of Raqqa, the de facto capital of the caliphate.

In the book, co-written with the German journalist Andrea Hoffmann, she describes how they were bought and sold like cattle. She says the men would kneel and pray before raping her, convinced that it was sanctioned by religion. She fought back — which often triggered her epilepsy — and tried to kill herself.

She eventually escaped when her "owner" left the door to her room unlocked, and her mother escaped five months later. Khalaf spent time in a camp for displaced people in northern Iraq before eventually relocating to Germany, where she lives now.

Ahmed Khudida Burjus, the deputy director of Yazda, a U.S.-based Yazidi rights group, says around 7,000 women and girls were captured and sold into slavery, with nearly half eventually escaping. In Kocho alone, at least 500 men and boys were killed, and 800 women and girls taken away.

The group has documented at least 54 mass graves of Yazidis, but says a lack of resources has delayed the exhumation of the remains, and that there may be more graves yet to be discovered.

Young Yazidi woman, Farida Khalaf, recounts the horrors of months of her captivity and abuse by IS militants as she walks through the school where she was seized and separated from her family 2014. (Yazda via AP)

Over the past three years, Syrian and Iraqi forces have gradually driven IS out of nearly all the territory it once held. But the group still maintains a presence in the Syrian desert and remote areas along the border.

At least 3,000 Yazidi women, girls and children are still unaccounted for. Khalaf says their fate is never far from her mind.

"I was in their captivity and I know how difficult it is to be there, a day feels like a year," she said. "We prayed every day that the day would pass without beating or torture or rape."