1from sentence_transformers import SentenceTransformer
2
3# Download from the 🤗 Hub
4model = SentenceTransformer("ahmedHamdi/narrative-similarity-es-en-gemma")
5# Run inference
6sentences = [
7 "Leslie is a manipulative, troubled alcoholic from West Texas who won $190,000 in a local lottery, only to squander the winnings on liquor and drugs. Six years later, Leslie is homeless and lives a nomadic life, drifting between motels and the streets. After being kicked out of a residential motel, she reunites with her estranged 20-year-old son, James, who allows her to live with him on the condition that she doesn't drink. Leslie soon steals money from James's roommate, Darren, and James discovers liquor bottles under his bed, prompting him to call his grandmother and Leslie's friend, Nancy, for help. Nancy and her boyfriend, Dutch, reluctantly allow Leslie to stay with them, but throw her out the night she visits the local bar and is spotted by Pete, one of her friends. Leslie sleeps outside next to a motel, where Sweeney, one of the owners, finds her at dawn. He orders her to leave, and she runs away, leaving her suitcase behind. Pete meets her outside a convenience store that night and buys her food, but Leslie again runs away when he makes sexual advances toward her. Leslie returns to the motel to retrieve her suitcase, and the benevolent Sweeney impulsively offers her a job cleaning rooms in exchange for a small salary and room and board. Royal, who helps manage the motel with Sweeney, is cold toward Leslie, whom he has known since childhood. Leslie is frequently late for her duties and continues to spend her earnings on alcohol, often going to bars. One night, a drunken Leslie heads to the house where she raised James, shocking the family who now lives there. The owners call Sweeney, who returns Leslie to the inn. Disappointed by Leslie's lack of commitment, Sweeney intends to fire her, but he relents when she assures him that she intends to change her ways. With nowhere else to go, Leslie tries to focus on her work and stay sober while suffering through alcohol withdrawal. Leslie and Sweeney develop a friendship, bonding over their shared history of addiction. Leslie accompanies Sweeney to a carnival, where he meets his daughter and granddaughter. At the carnival, Leslie confronts Nancy, who criticizes her in front of Sweeney for abandoning James when he was a child and insults her in front of everyone. Later that day, Leslie quits her job at the motel. She calls James at a laundromat, leaving him a message saying she loves him, then visits a bar, where she talks to a young man. She orders a beer but decides not to drink it. Meanwhile, Sweeney looks for Leslie and arrives at the bar, but she is gone. Leslie squats in an abandoned ice cream parlor across the street from the motel and watches Sweeney return. In the morning, she wakes Sweeney and tells him she wants to renovate the ice cream parlor. Ten months later, Leslie is sober and, with Sweeney and Royal's help, has renovated the ice cream parlor, turning it into a restaurant. On opening day, Leslie has no customers. Nancy arrives that evening at closing time, and Leslie accuses her of sabotaging the opening by telling the locals not to come. Instead of confronting Leslie in anger, Nancy apologizes for not being emotionally present throughout Leslie's life. Nancy also surprises Leslie by revealing that she has brought James with her. Royal and Sweeney prepare a meal for them, and the two embrace.",
8 "Leslie is a troubled and manipulative alcoholic from West Texas who won $190,000 in a local lottery, only to squander the winnings on liquor and drugs. Six years later, Leslie is destitute, living a peripatetic life in motels and on the streets. After being kicked out of a residential motel, she reunites with her estranged 19-year-old son James, who allows her to live with him under the provision that she not drink. Leslie soon steals money from James's roommate Darren, and James discovers liquor bottles under her bed, leading him to call his grandmother and Leslie's friend Nancy for help. Nancy and her boyfriend Dutch reluctantly allow Leslie to stay with them, but lock her out in the middle of the night when she visits the local bar and is spotted by Pete, one of their friends. Leslie sleeps outside next to a motel, where she is found at dawn by Sweeney, one of the proprietors. He orders her to leave, and she flees, leaving her suitcase behind. She is met outside a convenience store that night by Pete, who buys her food, but Leslie again flees when he attempts to make sexual advances toward her. Leslie returns to the motel in search of her suitcase, and Sweeney pretends to confuse her for somebody who had called for a job, and offers her the opportunity of cleaning rooms in exchange for a small wage and boarding. Royal, who owns and helps run the motel with Sweeney, is cold toward Leslie, whom he has known since childhood. Leslie is frequently unpunctual to her duties, and she continues to spend her earnings on alcohol, often going to bars. Late one night, Leslie drunkenly wanders to the home where she raised James, startling the family who now lives there. The homeowners phone Sweeney, who returns Leslie to the roadhouse. Disappointed by Leslie's lack of commitment, Sweeney intends to fire her, but he relents when she assures him she intends to change her ways. With nowhere left to turn, Leslie attempts to focus on her job and maintain sobriety as she suffers through alcohol withdrawal. Leslie and Sweeney develop a friendship, bonding over their mutual history of addiction. Leslie accompanies Sweeney to a fair, where she meets his daughter and granddaughter. Leslie gets into a confrontation with Nancy at the fair, who lambasts her in front of Sweeney for having abandoned James when he was a child. Later that day, she argues with Sweeney after he insists on watching a VHS tape containing the TV news piece on her lottery win. On the tape, the teenage James mentions that Leslie has always wanted to open a diner and the younger Leslie, clearly drunk, scoffs. She quits her job at the motel. She phones James from a laundromat, leaving a message telling him she loves him. She then visits her usual bar, where she is hit on by a handsome but roguish younger man. She orders a beer and a shot, but decides not to drink either. Meanwhile, Sweeney searches for Leslie and arrives at the bar, but she has left. He punches and tussles with Pete after he and Nancy insult Leslie. Leslie squats in an abandoned ice cream shop across the street from the motel and watches as Sweeney returns. In the morning, she awakens Sweeney and tells him she wants to renovate the ice cream shop and open a diner. He reluctantly agrees to help and they kiss for the first time. Ten months later, Leslie is sober, and with Sweeney and Royal's help, she has fixed up the building and turned it into a diner. On opening day, Leslie receives no customers. Nancy arrives that evening at closing time, and Leslie accuses her of sabotaging the business's opening by telling the locals not to go. Instead of responding with rage, Nancy apologizes to Leslie for not being emotionally present throughout Leslie's life, while also stating that she won't ever forgive Leslie for abandoning her son due to her addiction. Nancy also surprises Leslie by revealing she has brought James with her. Royal and Sweeney prepare a meal for them, and the two embrace.",
9 "After his university graduation ceremony, David (Anastasios Soulis) publicly and awkwardly proposes to his girlfriend, Nadja (Nanna Blondell), which she happily accepts. A year and a half later, however, they are stressed due to work and school and fight frequently in their apartment in Stockholm. The stress is compounded when Nadja learns that she is pregnant, which she is unhappy about as she is studying to be a doctor and she is not sure if she and David should be parents. She decides to keep it a secret from David. Nadja opens up to an older neighbor, Tomas (Thomas Hanzon), and he assures her that she and David will be great parents; he insists that parenthood is life's greatest gift and implies he has lost a child of his own. The next morning, David surprises Nadja with a camping trip to see the northern lights, and the two reconcile and take the trip with their dog, Boris. While stopping for gas, David encounters two locals, brothers Jarmo and Rolle, and is made uncomfortable by their rough mannerisms and their truck bed full of dead game. As he has difficulties taking his car out of park, he accidentally bumps into the brothers' truck, leaving scratches. David chooses to drive off instead of saying something, which annoys Nadja. When they reach their destination at an inn, the woman at the front desk treats them strangely and silently refuses to serve them, leaving her brother Einar to imply that she's not used to seeing an interracial couple. He learns of their itinerary and offers to host them at his cabin in the wilderness. Nadja becomes nervous seeing Jarmo and Rolle in the establishment, and when they leave, they discover that someone has keyed their car and vandalized their bumper sticker with a racial epithet. Angered by this, Nadja spots their pickup truck later on the drive and scratches it with a screwdriver, narrowly avoiding retaliation when the brothers catch her in the act. The couple camps beneath the northern lights, and Nadja reveals she is pregnant, which makes David nervous and unsure. Their conversation is interrupted when they spot a red dot on the wall of their tent. They first assume that it is a laser pointer prank, but quickly realize that is a laser sight from a rifle and guess that the brothers are attacking them in revenge for the car damage. Boris escapes into the wilderness while they try to hide, and they hear gunshots and the sound of Boris whining. After they are shot at, they flee into the forest and hear their pursuers chase after them. After spending the night hiding in a small shelter, they return to the bloodied campsite and find all their belongings missing, and Boris's decapitated head in the tent. While searching for any remaining possessions, David is injured when his arm gets caught in a hunting trap. Finding nothing to help them, they set off to find help. However, they are soon shot at again, and David, increasingly losing blood, hallucinates a boy in a winter coat staring at them. David is shot in the shoulder while Nadja escapes unhurt, and the two search for each other as a snowstorm sets in. Nadja realizes that she has run atop a frozen lake, and as David searches for her, he falls in and is narrowly rescued by her. The couple finally makes it to an emergency cabin, where they phone rescuers and are told they will have to wait until the storm passes for help. The next morning, they hear a vehicle approach the cabin and realize it is an armed (but unaware) Jarmo, who works as a mountain rescuer. Escaping through a back window, they flee into the woods and seek shelter in what is revealed to be the den of a hibernating bear. Jarmo discovers them, but before he can shoot, Nadja shoots him with a flare found at the cabin. David's condition deteriorates as they progress, and he hallucinates the boy again and begins mumbling about guilt. Spotting Einar's cabin in the distance, Nadja runs ahead to get help for David, but encounters Rolle on the way. Rolle seems confused by her appearance, but before he can act, David knocks him unconscious with a rock, and the two make it to Einar's cabin. Einar appears to call for help, but Nadja realizes that he is contacting someone else, and Einar suddenly becomes aggressive and locks them in a room discovered to be covered in stealth photographs taken of the couple. Finally, Tomas arrives with a rifle, and the truth is revealed: the day of the couple's engagement, Nadja attempted to perform oral sex on David as they drove home, and a distracted David struck and killed a pedestrian -- the boy he had hallucinated earlier, who was also Tomas's son and Einar's nephew. David chose to drive off instead of calling the police as Nadja wanted, which left her wracked with guilt. On that day, Tomas had been playing with a drone with his son, which had caused him to run into the road; however, the drone also captured the couple's license plate, and a grieving Tomas tracked them down and moved into a nearby apartment to surveil them. Tomas is intent on inflicting revenge on the couple for callously driving away and had been behind the earlier murder attempts. He now decides to become more sadistic and tries to get David to use a power drill to torture and kill Nadja's child, and he shoots David in the knee when he does not comply. Tomas prepares to kill them both but is interrupted by the arrival of a furious Jarmo, who has tracked down the couple. In the confusion, Tomas shoots and fatally wounds Jarmo, who accidentally does the same to Einar, and Nadja and David escape while Jarmo and Tomas struggle for a rifle. Nadja and David attempt to flee, but David cannot escape with his injuries. He tells Nadja to run, and when she stumbles upon the unconscious Rolle, she decides to take his rifle and save David. However, when she returns, she hesitates while trying to shoot him and is shot in the head and killed instantly by Mona, Tomas's wife and Einar's sister encountered earlier at the inn. A traumatized David begs to be killed as well, but Thomas refuses, telling him that he can now understand how he felt after his own son had died. Mona and Tomas depart as David is left sobbing in the snow.",
10]
11embeddings = model.encode(sentences)
12print(embeddings.shape)
13# [3, 768]
14
15# Get the similarity scores for the embeddings
16similarities = model.similarity(embeddings, embeddings)
17print(similarities)
18# tensor([[ 1.0000, 0.9614, -0.0053],
19# [ 0.9614, 1.0000, -0.0544],
20# [-0.0053, -0.0544, 1.0000]])