1from sentence_transformers import SentenceTransformer
2
3# Download from the 🤗 Hub
4model = SentenceTransformer("ahmedHamdi/narrative-similarity-fr-en-instructor-xl")
5# Run inference
6sentences = [
7 'Represent the plot: A samurai somewhat out of favor since his wife died of a terrible illness, Seibei raises his two young daughters with very limited means and cares as best he can for his elderly mother, who is no longer entirely lucid. Disregarded by everyone in his class, Seibei remains misunderstood: how could a samurai possibly be content with such a dreary and difficult life?',
8 "Represent the plot: At the start of the film, the main character, Iguchi Seibei, becomes a widower when his wife succumbs to tuberculosis. His wife receives a grand funeral, more than Seibei, a low-ranking samurai, can afford. Seibei works in the grain warehouse, keeping inventory for the clan. His samurai colleagues mock him behind his back with the nickname Tasogare (Twilight): when evening approaches, Seibei rushes home to look after his elderly mother, who has dementia, and two young daughters, Kayano and Ito, instead of bonding with his supervisor and other samurai colleagues over customary nights of dinner, geisha entertainment, and sake drinking. Even though he is a samurai, Seibei neglects his appearance, failing to bathe or shave his head, and being shabbily dressed. The well-being of his young daughters and medicine for his mother take priority over new clothes or the monthly bath fee, and his daughters say they are both happy, even without a mother. Things change when Seibei's childhood friend Tomoe (sister of Iinuma Michinojo, one of his better, kinder samurai friends and much higher ranked in the clan) returns to town. Tomoe is atypical in that she was a tom-boy as a child and as an adult questions points of etiquette, such as obeying her elder brother's wife and not attending peasant festivals. Recently divorced from an abusive alcoholic husband (Koda, a samurai captain), Tomoe finds comfort and solace with Seibei's daughters. Tomoe's ex-husband Koda barges into the household of Michinojo in the middle of night in a drunken demand for Tomoe and challenges Michinojo to a duel which Seibei, believing Michinojo could not win, accepts on Michinojo's behalf, although Seibei knows his clan forbids duels and the penalty is usually death for the winner as the loser is already dead. Michinojo arrives before Seibei and is facing Koda. Seibei interrupts and decides to use only a wooden stick whilst Koda brandishes a steel katana. Koda, after being disarmed and asked if that can be the end of it, picks up his sword so Seibei knocks him unconscious, sparing both their lives. A few days later, Captain of the Guard Yogo passes by Seibei while Seibei is working in the stores and quietly announces he is friends with Koda who has asked him for help in seeking vengeance on Seibei. Recognising that Seibei has some skill and learning that Seibei has learnt a particular style of fighting, Yogo hopes they can duel someday. Seibei's workmates learn of the duel and wonder if they should stop calling him by his nickname. When Iinuma Michinojo asks Seibei to marry his sister, saying she has turned down many offers and he will not force her, Seibei feels that Iinuma is teasing him for his strong feelings for Tomoe, like when he, Iinuma, and Tomoe were children. Iinuma knows Tomoe's feeling for Seibei, and Seibei is a kind man who would treat Tomoe better than Koda. With much deep regret, Seibei declines Iinuma's offer of his sister's hand in marriage, citing his inferior social status and how he did not want to see Tomoe share the burden of poverty despite Michinojo's protest that Tomoe is a grown woman who knows what she is in for. Seibei stoically regrets how his departed wife suffered in his care who, like Tomoe, came from a wealthier family. Iinuma talks no more of it. Tomoe stops visiting Kayano and Ito. In the final act, the ranking official of Seibei's clan, having heard of his prowess with a sword, orders Seibei to kill Yogo, who has been disowned and who stubbornly refuses to resign his post by committing seppuku. The young lord of the clan had died from measles and there was a succession struggle behind the scenes over who will be the new lord. Yogo ended up on the losing side of this conflict, hence his ordered suicide. Yogo has already killed a formidable samurai that was sent to kill him. Seibei is promised a rise in rank and pay if he accepts the dangerous mission. Seibei is very reluctant to fight Yogo at first, requesting one month to prepare for it. He says that, because of great hardship in his life, he has lost all resolve to fight with ferocity and disregard for his own life, because of the experience of watching his two girls grow. As they continue to insist, he requests two days to get himself up to the task. The new clan leader is furious over this answer and orders him expelled from the clan. Seibei is finally forced to agree to attempt the mission. Upon parting that evening, Seibei's supervisor (who was present during the meeting) promises him that he will make sure the girls will be taken care of if the worst comes to pass. The following morning, Seibei attempts to get ready, but there is no one to help him with the rituals of samurai before battle. With no one to turn to, he asks Tomoe for her assistance. Before he leaves, he tells Tomoe that he was wrong to decline the offer of marriage. He says that if he lives, he would like to ask for her hand in marriage now that there is promise of a promotion. She regretfully tells Seibei she has accepted another proposal. Seibei, feeling like a fool, tells Tomoe to forget about the silly conversation. Tomoe says that she will not be waiting at his household for him to return but that she hopes from her heart that he will return safely. Seibei says he understands completely. He thanks Tomoe for her generosity for assisting him in this final ritual. At Yogo's house, Seibei finds his target drinking alcohol in a dark, fly-infested room. Yogo recognizes Seibei and invites him to sit and drink. He then asks Seibei to allow him to run away. He explains he was only faithfully serving his master and describes how his wife and daughter also died of tuberculosis due to hardship and spending seven years as a rōnin. Only thanks to his master's generosity could he afford a proper funeral. Yogo tells Seibei that he expects Seibei was promised a reward for this errand and that he too performed errands for his superior, taking the word of his superior as the word of the clan. Seibei commiserates and reveals further parallels in the two men's stories, such as that his wife's family demanded she have an expensive funeral and so he sold his katana to pay for it. He reveals that his long scabbard contains a fake bamboo sword. This angers Yogo who believes Seibei is mocking him: the short kodachi can be carried even by common people who are not samurai. Seibei explains he has been trained with the short sword, which he still carries, but Yogo is not placated. Seibei's kodachi fighting style is matched up against Yogo's ittō-ryū (single long sword) swordsmanship in an intense close quarters duel. Despite allowing Yogo to slash him several times and offering him chances to flee, Yogo presses the attack and Seibei kills Yogo when his longer sword gets caught in the rafters. Despite his wounds, Seibei limps home. Kayano and Ito rush to him in the courtyard, happy to see him. Tomoe is still there, waiting in the house. They have an emotional reunion. In a brief epilogue set many years later, Seibei's younger daughter, Ito, now elderly, visits the grave of Seibei and Tomoe. Narrating, she explains they married but that their happiness was not to last: He died three years later in the Boshin War, Japan's last civil war. Tomoe took care of Seibei's daughters until they were both married. Ito often heard that Tasogare Seibei was a very unfortunate character, a most pathetic samurai with no luck at all. Ito disagrees: Her father never had any ambition to become anything special; he loved his two daughters, and was loved by the beautiful Tomoe.",
9 "Represent the plot: Hanna Heller is a fifteen-year-old girl who lives with her father, Erik, in rural northern Finland. Since the age of two, Hanna has been trained by him, an ex-CIA operative from Germany, to be a skilled assassin. He teaches her hand-to-hand combat and drills her in target shooting. Erik knows a secret that cannot become public and Marissa Wiegler, a senior CIA officer, seeks to eliminate him. Erik has trained Hanna with the intent to kill Marissa. One night, she tells him she is ready to face their enemies. Erik digs up a radio beacon that will alert the CIA to their presence. Although he warns Hanna that a confrontation with Marissa will be fatal for either her or Marissa, he leaves the final decision to her and she activates the beacon. Erik leaves, instructing her to meet him in Berlin. Hanna is seized by special forces and taken to an underground CIA complex where a suspicious Marissa sends a decoy to interrogate Hanna when she asks for her by name. While talking to the double, Hanna starts to cry and embraces her tightly, which makes her captors uneasy. They send guards to sedate her. As they enter the cell, Hanna kills the double along with some guards and escapes, discovering that she is in Morocco. Hanna meets Sebastian and Rachel, who are on a camper-van holiday with their children, Sophie and Miles, and stows away in the vehicle on a ferry to Spain, seeking to reach Berlin. The family is kind to her, and she and Sophie become friends: Hanna even tells her about the Berlin rendezvous and they kiss. Marissa hires Isaacs, a sadistic former agent, to capture Hanna while other agents are searching for Erik. She kills Hanna's maternal grandmother after failing to learn anything useful from her. Isaacs and two skinheads have discovered from the Moroccan hotelier with whom Hanna escaped and trail them. Cornering her and the family sometime down the road, Isaacs attacks but Hanna manages to escape after a vicious fight. Marissa interrogates the family and discovers from Miles that Hanna is heading to Berlin. The family is never seen again. Meanwhile, in Berlin, Erik fights off an attempted assassination and tries but fails to kill Marissa. Arriving at the rendezvous in an abandoned Berlin amusement park, Hanna meets Knepfler, an eccentric magician and friend of Erik's who lives there. Before Erik arrives, Marissa and Isaacs appear. Hanna escapes, but overhears comments that suggest Erik is not her biological father. Hanna then goes to her grandmother's empty apartment where she finds Erik, who admits he is not her biological father but loves her as his own. He explains that he once recruited pregnant women into a CIA program where their children's DNA was enhanced to create super-soldiers. After the project was shut down, its subjects – all except Hanna – were eliminated. Marissa and Isaacs arrive; Erik acts as a distraction to allow Hanna to escape. He kills Isaacs, but is shot dead by Marissa, who then returns to Knepfler's house in the abandoned amusement park and finds Hanna, who has just discovered Knepfler hanging dead upside-down, having been tortured to death by Isaacs. Hanna flees taking one of the arrows used to kill Knepfler. After Hanna flees, she is cornered by Marissa. In a final confrontation, Hanna turns her back to Marissa who shoots at her; but Hanna wounds Marissa by shooting an arrow at her. A now-staggering Marissa, pursued by Hanna, trips, leaving her badly injured. Hanna picks up Marissa's gun and uses it to kill her with two shots — a method she had previously used while hunting a deer at the film's beginning.",
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.7678, -0.0355],
19# [ 0.7678, 1.0000, -0.1170],
20# [-0.0355, -0.1170, 1.0000]])