1from sentence_transformers import CrossEncoder
2
3# Download from the 🤗 Hub
4model = CrossEncoder("RinKana/ms-marco-MiniLM-L12-v2-cross-lingual-reranker")
5# Get scores for pairs of inputs
6pairs = [
7 ["How old was DiCaprio when he starred in Cameron's movie?", 'Hanks climbed back to the top again with his portrayal of a washed-up baseball legend turned manager in A League of Their Own (1992). Hanks has stated that his acting in earlier roles was not great, but that he subsequently improved. In an interview with Vanity Fair, Hanks noted his "modern era of moviemaking ... because enough self-discovery has gone on ... My work has become less pretentiously fake and over the top". This "modern era" began in 1993 for Hanks, first with Sleepless in Seattle and then with Philadelphia. The former was a blockbuster success about a widower who finds true love over the radio airwaves. Richard Schickel of TIME called his performance "charming," and most critics agreed that Hanks\' portrayal ensured him a place among the premier romantic-comedy stars of his generation.In Philadelphia, he played a gay lawyer with AIDS who sues his firm for discrimination. Hanks lost 35 pounds and thinned his hair in order to appear sickly for the role. In a review for People, Leah Rozen stated, "Above all, credit for Philadelphia\'s success belongs to Hanks, who makes sure that he plays a character, not a saint. He is flat-out terrific, giving a deeply felt, carefully nuanced performance that deserves an Oscar." Hanks won the 1993 Academy Award for Best Actor for his role in Philadelphia. During his acceptance speech, he revealed that his high school drama teacher Rawley Farnsworth and former classmate John Gilkerson, two people with whom he was close, were gay.Hanks followed Philadelphia with the 1994 hit Forrest Gump which grossed a worldwide total of over $600 million at the box office. Hanks remarked: "When I read the script for Gump, I saw it as one of those kind of grand, hopeful movies that the audience can go to and feel ... some hope for their lot and their position in life ... I got that from the movies a hundred million times when I was a kid. I still do." Hanks won his second Best Actor Academy Award for his role in Forrest Gump, becoming only the second actor to have accomplished the feat of winning consecutive Best Actor Oscars. (Spencer Tracy was the first, winning in 1937–38. Hanks and Tracy were the same age at the time they received their Academy Awards: 37 for the first and 38 for the second.)Hanks\' next role—astronaut and commander Jim Lovell, in the 1995 film Apollo 13—reunited him with Ron Howard. Critics generally applauded the film and the performances of the entire cast, which included actors Kevin Bacon, Bill Paxton, Gary Sinise, Ed Harris, and Kathleen Quinlan. The movie also earned nine Academy Award nominations, winning two. Later that year, Hanks starred in Disney/Pixar\'s CGI-animated hit film Toy Story, as the voice of Sheriff Woody.'],
8 ['What is the total number of African lions in zoos?', 'Lemurs have drawn much attention to Madagascar and its endangered species. In this capacity, they act as flagship species, the most notable of which is the ring-tailed lemur, which is considered an icon of the country. The presence of lemurs in national parks helps drive ecotourism, which especially helps local communities living in the vicinity of the national parks, since it offers employment opportunities and the community receives half of the park entrance fees. In the case of Ranomafana National Park, job opportunities and other revenue from long-term research can rival that of ecotourism.Starting in 1927, the Malagasy government has declared all lemurs as "protected" by establishing protected areas that are now classified under three categories: National Parks (Parcs Nationaux), Strict Nature Reserves (Réserves Naturelles Intégrales), and Special Reserves (Réserves Spéciales). There are currently 18 national parks, 5 strict nature reserves, and 22 special reserves, as well as several other small private reserves, such as Berenty Reserve and Sainte Luce Private Reserve, both near Fort Dauphin. All protected areas, excluding the private reserves, comprise approximately 3% of the land surface of Madagascar and are managed by Madagascar National Parks, formerly known as l\'Association Nationale pour la Gestion des Aires Protégées (ANGAP), as well as other non-governmental organizations (NGOs), including Conservation International (CI), the Wildlife Conservation Society (WCS), and the World Wide Fund for Nature (WWF). Most lemur species are covered by this network of protected areas, and a few species can be found in multiple parks or reserves.Conservation is also facilitated by the Madagascar Fauna Group (MFG), an association of nearly 40 zoos and related organizations, including the Duke Lemur Center, the Durrell Wildlife Conservation Trust, and the Saint Louis Zoological Park. This international NGO supports Madagascar\'s Parc Ivoloina, helps protect Betampona Reserve and other protected areas, and promotes field research, breeding programs, conservation planning, and education in zoos. One of their major projects involved the release of captive black-and-white ruffed lemurs, designed to help restock the dwindling population within Betampona Reserve.'],
9 ['How many times the volume of Sao Tinian is greater than Earth?', "Titan is the sixth gravitationally rounded moon from Saturn. Frequently described as a planet-like moon, Titan is 50% larger than Earth's moon and 80% more massive. It is the second-largest moon in the Solar System after Jupiter's moon Ganymede, and is larger than the planet Mercury, but only 40% as massive. Discovered in 1655 by the Dutch astronomer Christiaan Huygens, Titan was the first known moon of Saturn, and the sixth known planetary satellite (after Earth's moon and the four Galilean moons of Jupiter). Titan orbits Saturn at 20 Saturn radii. From Titan's surface, Saturn subtends an arc of 5.09 degrees and would appear 11.4 times larger in the sky than the Moon from Earth."],
10 ['Which school did Kirk graduate from?', 'Pitt was born in Shawnee, Oklahoma, to William Alvin Pitt, the proprietor of a trucking company, and Jane Etta (née Hillhouse), a school counsellor. The family soon moved to Springfield, Missouri, where he lived together with his younger siblings, Douglas Mitchell (born 1966) and Julie Neal (born 1969). Born into a conservative household, he was raised as Southern Baptist but has since stated that he does not "have a great relationship with religion" and that he "oscillate[s] between agnosticism and atheism". Pitt has described Springfield as "Mark Twain country, Jesse James country", having grown up with "a lot of hills, a lot of lakes".Pitt attended Kickapoo High School, where he was a member of the golf, swimming and tennis teams. He participated in the school\'s Key and Forensics clubs, in school debates, and in musicals. Following his graduation from high school, Pitt enrolled in the University of Missouri in 1982, majoring in journalism with a focus on advertising. As graduation approached, Pitt did not feel ready to settle down. He loved films—"a portal into different worlds for me"—and, since films were not made in Missouri, he decided to go to where they were made. Two weeks short of completing the coursework for a degree, Pitt left the university and moved to Los Angeles, where he took acting lessons and worked odd jobs. He has named his early acting heroes as Gary Oldman, Sean Penn and Mickey Rourke.'],
11 ['Recycling is a vital component of which industry?', "Certain countries trade in unprocessed recyclates. Some have complained that the ultimate fate of recyclates sold to another country is unknown and they may end up in landfills instead of being reprocessed. According to one report, in America, 50–80 percent of computers destined for recycling are actually not recycled. There are reports of illegal-waste imports to China being dismantled and recycled solely for monetary gain, without consideration for workers' health or environmental damage. Although the Chinese government has banned these practices, it has not been able to eradicate them. In 2008, the prices of recyclable waste plummeted before rebounding in 2009. Cardboard averaged about £53/tonne from 2004 to 2008, dropped to £19/tonne, and then went up to £59/tonne in May 2009. PET plastic averaged about £156/tonne, dropped to £75/tonne and then moved up to £195/tonne in May 2009.Certain regions have difficulty using or exporting as much of a material as they recycle. This problem is most prevalent with glass: both Britain and the U.S. import large quantities of wine bottled in green glass. Though much of this glass is sent to be recycled, outside the American Midwest there is not enough wine production to use all of the reprocessed material. The extra must be downcycled into building materials or re-inserted into the regular waste stream.Similarly, the northwestern United States has difficulty finding markets for recycled newspaper, given the large number of pulp mills in the region as well as the proximity to Asian markets. In other areas of the U.S., however, demand for used newsprint has seen wide fluctuation.In some U.S. states, a program called RecycleBank pays people to recycle, receiving money from local municipalities for the reduction in landfill space which must be purchased. It uses a single stream process in which all material is automatically sorted."],
12]
13scores = model.predict(pairs)
14print(scores)
15# [-6.2138 -5.2125 -4.131 -4.3559 -4.7555]
16
17# Or rank different texts based on similarity to a single text
18ranks = model.rank(
19 "How old was DiCaprio when he starred in Cameron's movie?",
20 [
21 'Hanks climbed back to the top again with his portrayal of a washed-up baseball legend turned manager in A League of Their Own (1992). Hanks has stated that his acting in earlier roles was not great, but that he subsequently improved. In an interview with Vanity Fair, Hanks noted his "modern era of moviemaking ... because enough self-discovery has gone on ... My work has become less pretentiously fake and over the top". This "modern era" began in 1993 for Hanks, first with Sleepless in Seattle and then with Philadelphia. The former was a blockbuster success about a widower who finds true love over the radio airwaves. Richard Schickel of TIME called his performance "charming," and most critics agreed that Hanks\' portrayal ensured him a place among the premier romantic-comedy stars of his generation.In Philadelphia, he played a gay lawyer with AIDS who sues his firm for discrimination. Hanks lost 35 pounds and thinned his hair in order to appear sickly for the role. In a review for People, Leah Rozen stated, "Above all, credit for Philadelphia\'s success belongs to Hanks, who makes sure that he plays a character, not a saint. He is flat-out terrific, giving a deeply felt, carefully nuanced performance that deserves an Oscar." Hanks won the 1993 Academy Award for Best Actor for his role in Philadelphia. During his acceptance speech, he revealed that his high school drama teacher Rawley Farnsworth and former classmate John Gilkerson, two people with whom he was close, were gay.Hanks followed Philadelphia with the 1994 hit Forrest Gump which grossed a worldwide total of over $600 million at the box office. Hanks remarked: "When I read the script for Gump, I saw it as one of those kind of grand, hopeful movies that the audience can go to and feel ... some hope for their lot and their position in life ... I got that from the movies a hundred million times when I was a kid. I still do." Hanks won his second Best Actor Academy Award for his role in Forrest Gump, becoming only the second actor to have accomplished the feat of winning consecutive Best Actor Oscars. (Spencer Tracy was the first, winning in 1937–38. Hanks and Tracy were the same age at the time they received their Academy Awards: 37 for the first and 38 for the second.)Hanks\' next role—astronaut and commander Jim Lovell, in the 1995 film Apollo 13—reunited him with Ron Howard. Critics generally applauded the film and the performances of the entire cast, which included actors Kevin Bacon, Bill Paxton, Gary Sinise, Ed Harris, and Kathleen Quinlan. The movie also earned nine Academy Award nominations, winning two. Later that year, Hanks starred in Disney/Pixar\'s CGI-animated hit film Toy Story, as the voice of Sheriff Woody.',
22 'Lemurs have drawn much attention to Madagascar and its endangered species. In this capacity, they act as flagship species, the most notable of which is the ring-tailed lemur, which is considered an icon of the country. The presence of lemurs in national parks helps drive ecotourism, which especially helps local communities living in the vicinity of the national parks, since it offers employment opportunities and the community receives half of the park entrance fees. In the case of Ranomafana National Park, job opportunities and other revenue from long-term research can rival that of ecotourism.Starting in 1927, the Malagasy government has declared all lemurs as "protected" by establishing protected areas that are now classified under three categories: National Parks (Parcs Nationaux), Strict Nature Reserves (Réserves Naturelles Intégrales), and Special Reserves (Réserves Spéciales). There are currently 18 national parks, 5 strict nature reserves, and 22 special reserves, as well as several other small private reserves, such as Berenty Reserve and Sainte Luce Private Reserve, both near Fort Dauphin. All protected areas, excluding the private reserves, comprise approximately 3% of the land surface of Madagascar and are managed by Madagascar National Parks, formerly known as l\'Association Nationale pour la Gestion des Aires Protégées (ANGAP), as well as other non-governmental organizations (NGOs), including Conservation International (CI), the Wildlife Conservation Society (WCS), and the World Wide Fund for Nature (WWF). Most lemur species are covered by this network of protected areas, and a few species can be found in multiple parks or reserves.Conservation is also facilitated by the Madagascar Fauna Group (MFG), an association of nearly 40 zoos and related organizations, including the Duke Lemur Center, the Durrell Wildlife Conservation Trust, and the Saint Louis Zoological Park. This international NGO supports Madagascar\'s Parc Ivoloina, helps protect Betampona Reserve and other protected areas, and promotes field research, breeding programs, conservation planning, and education in zoos. One of their major projects involved the release of captive black-and-white ruffed lemurs, designed to help restock the dwindling population within Betampona Reserve.',
23 "Titan is the sixth gravitationally rounded moon from Saturn. Frequently described as a planet-like moon, Titan is 50% larger than Earth's moon and 80% more massive. It is the second-largest moon in the Solar System after Jupiter's moon Ganymede, and is larger than the planet Mercury, but only 40% as massive. Discovered in 1655 by the Dutch astronomer Christiaan Huygens, Titan was the first known moon of Saturn, and the sixth known planetary satellite (after Earth's moon and the four Galilean moons of Jupiter). Titan orbits Saturn at 20 Saturn radii. From Titan's surface, Saturn subtends an arc of 5.09 degrees and would appear 11.4 times larger in the sky than the Moon from Earth.",
24 'Pitt was born in Shawnee, Oklahoma, to William Alvin Pitt, the proprietor of a trucking company, and Jane Etta (née Hillhouse), a school counsellor. The family soon moved to Springfield, Missouri, where he lived together with his younger siblings, Douglas Mitchell (born 1966) and Julie Neal (born 1969). Born into a conservative household, he was raised as Southern Baptist but has since stated that he does not "have a great relationship with religion" and that he "oscillate[s] between agnosticism and atheism". Pitt has described Springfield as "Mark Twain country, Jesse James country", having grown up with "a lot of hills, a lot of lakes".Pitt attended Kickapoo High School, where he was a member of the golf, swimming and tennis teams. He participated in the school\'s Key and Forensics clubs, in school debates, and in musicals. Following his graduation from high school, Pitt enrolled in the University of Missouri in 1982, majoring in journalism with a focus on advertising. As graduation approached, Pitt did not feel ready to settle down. He loved films—"a portal into different worlds for me"—and, since films were not made in Missouri, he decided to go to where they were made. Two weeks short of completing the coursework for a degree, Pitt left the university and moved to Los Angeles, where he took acting lessons and worked odd jobs. He has named his early acting heroes as Gary Oldman, Sean Penn and Mickey Rourke.',
25 "Certain countries trade in unprocessed recyclates. Some have complained that the ultimate fate of recyclates sold to another country is unknown and they may end up in landfills instead of being reprocessed. According to one report, in America, 50–80 percent of computers destined for recycling are actually not recycled. There are reports of illegal-waste imports to China being dismantled and recycled solely for monetary gain, without consideration for workers' health or environmental damage. Although the Chinese government has banned these practices, it has not been able to eradicate them. In 2008, the prices of recyclable waste plummeted before rebounding in 2009. Cardboard averaged about £53/tonne from 2004 to 2008, dropped to £19/tonne, and then went up to £59/tonne in May 2009. PET plastic averaged about £156/tonne, dropped to £75/tonne and then moved up to £195/tonne in May 2009.Certain regions have difficulty using or exporting as much of a material as they recycle. This problem is most prevalent with glass: both Britain and the U.S. import large quantities of wine bottled in green glass. Though much of this glass is sent to be recycled, outside the American Midwest there is not enough wine production to use all of the reprocessed material. The extra must be downcycled into building materials or re-inserted into the regular waste stream.Similarly, the northwestern United States has difficulty finding markets for recycled newspaper, given the large number of pulp mills in the region as well as the proximity to Asian markets. In other areas of the U.S., however, demand for used newsprint has seen wide fluctuation.In some U.S. states, a program called RecycleBank pays people to recycle, receiving money from local municipalities for the reduction in landfill space which must be purchased. It uses a single stream process in which all material is automatically sorted.",
26 ]
27)
28# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]