Open in Colab

LangChain#

LangChainは、言語モデルを利用したフレームワークです。次の原則をもとに設計されています。

  • 言語モデルをほかのデータソースに接続

  • 言語モデルと環境の相互作用

Wikipediaの要約#

サンプルとして、ここではWikipediaのあらすじを要約します。

事前にwikipediaをインストールします。

pip install wikipedia

環境変数 OPENAI_API_KEY を設定します。

WikipediaLoader を使って、 葬送のフリーレン データを取得します。

from IPython.display import Markdown
from langchain import OpenAI
from langchain.chains.summarize import load_summarize_chain
from langchain.docstore.document import Document
from langchain.document_loaders import WikipediaLoader
from langchain.prompts import PromptTemplate

docs = WikipediaLoader(query="Frieren", load_max_docs=1).load()
print(docs[0].metadata)
{'title': 'Frieren', 'summary': 'Frieren: Beyond Journey\'s End (Japanese: 葬送のフリーレン, Hepburn: Sōsō no Furīren, "Frieren, the Final Farewell to the Dead") is a Japanese manga series written by Kanehito Yamada and illustrated by Tsukasa Abe. It has been serialized in Shogakukan\'s shōnen manga magazine Weekly Shōnen Sunday since April 2020, with its chapters collected in ten tankōbon volumes as of March 2023. The series is licensed for English release in North America by Viz Media. An anime television series adaptation produced by Madhouse is set to premiere in Q4 2023.\nBy March 2023, the manga had over 8 million copies in circulation. In 2021, Frieren: Beyond Journey\'s End won the 14th Manga Taishō and the New Creator Prize of the 25th annual Tezuka Osamu Cultural Prize.'}
print(docs[0].page_content)
Frieren: Beyond Journey's End (Japanese: 葬送のフリーレン, Hepburn: Sōsō no Furīren, "Frieren, the Final Farewell to the Dead") is a Japanese manga series written by Kanehito Yamada and illustrated by Tsukasa Abe. It has been serialized in Shogakukan's shōnen manga magazine Weekly Shōnen Sunday since April 2020, with its chapters collected in ten tankōbon volumes as of March 2023. The series is licensed for English release in North America by Viz Media. An anime television series adaptation produced by Madhouse is set to premiere in Q4 2023.
By March 2023, the manga had over 8 million copies in circulation. In 2021, Frieren: Beyond Journey's End won the 14th Manga Taishō and the New Creator Prize of the 25th annual Tezuka Osamu Cultural Prize.


== Plot ==
The story follows elven mage Frieren, a former member of the party of adventurers who defeated the Demon King and restored harmony to the world after a ten-years-quest. In the past, the heroic group included Frieren, human hero Himmel, dwarven warrior Eisen and human priest Heiter. Before they part, they observe the Era Meteors together, a meteor shower that occurs once in fifty years. Frieren agrees to see them again and offer them a better view the next time the celestial event occurs. Frieren then departs and travels the world in pursuit of magical knowledge.
Frieren returns to the capital fifty years later; however, humanity has changed, and her former companions have distinctly aged. After one last adventure to see the meteor shower, Himmel dies of old age. During the funeral, Frieren expressed guilt for not attempting to learn more about him. Frieren then pays a visit to her other former comrades. She accepts an offer to teach and care for Fern, an orphaned child adopted by Heiter. She also receives an invitation to travel far north, to the resting place of souls, and see Himmel again to bid the hero a fitting farewell and express her feelings. To fulfill those requests, Frieren embarks on a journey together with Fern while still pursuing her passion for learning magic.
Frieren's elven nature grants her an extremely long lifespan, causing her to view periods of years or decades as ephemeral (this perception of time makes her consider the ten-year adventure with Himmel's party a fleeting experience). The story thus takes place across a long time, with periodic flashbacks accompanied by the physical and mental development of characters apart from Frieren herself.


== Characters ==
Frieren (フリーレン, Furīren)
Voiced by: Atsumi Tanezaki
An elven mage who was a group member that defeated the Demon King. Although she appears to be really young, she was born into a long-lived race of elves and has lived for over a thousand years. Because her sense of time is so dissimilar to that of humans, she has no qualms about working for months, if not years, at a time. After the death of Himmel, a member of her disbanded party, Frieren regretted not knowing him better during their ten-year adventure. As a result, she embarked on another journey to learn more about humanity. She has also traveled with a human wizard apprentice, Fern, since she took her on as an apprentice at Heiter's suggestion.
Over a thousand years ago, Frieren was rescued by the great wizard Flamme during a demon attack on her hometown. This harrowing experience instilled in Frieren a deep-seated abhorrence for demons, fueling her ambition to rid the world of their presence. After the Demon King's demise, Frieren dedicated herself to researching demon-slaying magic while continuing to kill them whenever she could until the demon race was no longer as threatening as it once was. As the wizard who has buried the most demons in recorded history, she has earned the moniker "Frieren the Slayer", and is feared by the demon race. Despite her accomplishments, Frieren has faced her share of defeats and struggles with certain shortcomings. As an elf, she is often perceived as being insensitive to human emotions. Her occasional clumsiness in social interactions leads others to mistakenly label her as aloof, but in reality, Frieren possesses a kind and caring nature.
Fern (フェルン, Ferun)
Frieren's only apprentice. She is a war orphan from a southern country who had lost her parents and was about to commit suicide by jumping off a ravine in despair when Heiter came to her rescue. She began training in magic as a child under Heiter's tutelage in order to become more self-sufficient. She met Frieren, who visited Heiter when she was nine years old. Fern requested that Frieren teach her magic so that she could become a full-fledged mage. After Heiter's death, she embarks on a journey as Frieren's apprentice at the age of 15. Later, she became a first-class mage after passing the examination while still in adolescence. As a privilege of being a first-class mage, Fern may ask Serie practically any magic. Likewise, the newly appointed first-class wizard merely asked for a spell to remove dirt from any garments, much to Serie's dismay.
Himmel (ヒンメル, Hinmeru)
A human member of the original hero party, who died. He was the hero of the group and a self-proclaimed handsome man. After seeing a meteor shower together, he and Frieren promised to meet again. He died shortly after the two reunited fifty years later.
Heiter (ハイター, Haitā)
The other deceased human member of the hero party, the alcohol-loving priest of the group. He found, adopted, and raised Fern after the party dissolved.
Eisen (アイゼン, Aizen)
Another living member of the original hero party besides Frieren. Eisen is a dwarf who, although not as long-lived as elves, still has a significantly longer lifespan than humans. However, Eisen was past his prime despite his extended life and growing old, even by dwarf standards. As a result, he declined Frieren's invitation to embark on a new adventure, choosing to spend his remaining days in peace.
Stark (シュタルク, Shutaruku)
A young warrior who was raised by Eisen and served as a replacement for him on Frieren's new adventure. Since Eisen declined the invitation due to his old age, Stark stepped up to become the frontline fighter in battles, a role that Frieren and Fern, being magicians, are not suited for. Despite his timidity, Stark proves to be a strong and capable warrior fiercely loyal to his companions.
Sein (ザイン, Zain)
A village monk who joins Frieren's party on her journey after they meet. Despite being a talented monk, Sein has several vices, including a love for liquor, cigarettes, gambling, and older women. He travels with Frieren's group for a time but eventually leaves them temporarily to search for his best friend, who embarked on a solo adventure a long time ago.
Flamme (フランメ, Furanme)
A legendary human wizard and the originator of humanity's magic. She was considered a mythological figure, and her existence is often questioned. Many of the grimoires attributed to her are believed to be fake, but in reality, she truly existed around a millennium before the story's beginning. She was the mentor of Frieren and the apprentice of the great wizard, Serie.
In the past, an elf village was invaded on the orders of the Demon King, and Flamme protected the lone survivor, Frieren. In the blink of an eye, she could eliminate pursuers stronger than the Demon King's army's general. She taught Frieren an effective fighting method that included concealing her magical strength to catch opponents off guard and eliminate them with little effort, instructing her to spend the rest of her life doing so. Flamme's favorite spell was one that created a "beautiful flower garden." After Flamme died of old age, Frieren, her apprentice, used this magic to decorate Flamme's grave to fulfill her mentor's last wish.
Serie (ゼーリエ, Zērie)
An elven woman who has lived since ancient times. She is an influential wizard and Flamme's instructor. About 1,000 years before the story begins, she met Frieren for the first time, whom Flamme had brought. Dubbed a living grimoire, Serie is believed to possess nearly all of human history's magic and is considered by many to be the closest wizard to the Almighty Goddess.
Two decades before Himmel's passing, Serie established the distinguished Continental Magic Association, an organization responsible for governing and teaching magic across the realm. First-class mages can seek Serie's invaluable guidance and may request any spell they desire. Serie is a dedicated mentor at her core, fervently nurturing and steering the future generation of remarkable wizards. Nevertheless, her affinity for warmongering strains her relationship with the peace-seeking Flamme and Frieren. Serie believes their potential is wasted as they fixate on defeating demons and advocating for a peaceful era.


== Media ==


=== Manga ===
Frieren: Beyond Journey's End is written by Kanehito Yamada and illustrated by Tsukasa Abe. The series began in Shogakukan's shōnen manga magazine Weekly Shōnen Sunday on April 28, 2020. In January 2023, it was announced that manga would go on hiatus; it resumed in March of the same year. Shogakukan has collected its chapters into individual tankōbon volumes. The first volume was published on August 18, 2020. As of March 16, 2023, ten volumes have been released.In February 2021, Viz Media announced that they licensed the series for English release in North America, and the first volume was published on November 9, 2021. On May 9, 2023, Viz Media launched their Viz Manga digital manga service, with the series' chapters receiving simultaneous English publication in North America as they are released in Japan.


==== Volume list ====


=== Anime ===
In September 2022, it was announced on the cover of the 9th volume of the manga that the series will receive an anime adaptation. It was later revealed to be a television series that is produced by Madhouse and directed by Keiichirō Saitō, with scripts supervised by Tomohiro Suzuki, character designs handled by Reiko Nagasawa, and music composed by Evan Call. The series set to premiere in Q4 2023.


== Reception ==


=== Manga ===
By March 2021, the manga had over 2 million copies in circulation; over 5.6 million copies in circulation by February 2022; over 6 million copies in circulation by June 2022; over 7.2 million copies in circulation by September 2022; and over 8 million copies in circulation by March 2023. The manga ranked second on Takarajimasha's Kono Manga ga Sugoi! list of best manga of 2021 for male readers; and ranked sixth on the 2022 list. The series ranked second on the "Nationwide Bookstore Employees' Recommended Comics of 2021" by the Honya Club website. The series ranked 17th on the 2021 "Book of the Year" list by Da Vinci magazine; it ranked tenth on the 2022 list.In 2023, it was ranked in the top ten graphic novels by the American Library Association's Graphic Novels and Comics Round Table's "Best Graphic Novels for Adults" list.


==== Critical reception ====
Rebecca Silverman of Anime News Network gave the first volume an A−. Silverman praised the concept of Frieren outliving her companions and being forced to live with an understanding of the human world and her own emotions, calling it an "interesting take on the fantasy genre". Silverman, however, commented that the art is not "quite up to the emotional tasks of the story". Richard Eisenbeis from the same website prised the second voulme of the series, saying that it "delivers both emotional tales and deep thematic explorations of human nature". He also described the fourth and fifth volumes of the manga as "an action climax that delivers not only a grand battle but also character-development and world-building. Smaller one-off tales that hit you right in your emotional core".Wolfen Moondaughter of Sequential Tart gave the first volume a 9 out of 10. Moondaughter highlighted the slice of life nature of the story, despite its premise which involves a "D&D-style adventuring party", also praising the interaction between the characters and the art work, concluding: "If you want a break from fight scenes, and want something more serene and contemplative, this book should serve you well! It's also a lovely story of honouring the memory of lost loved ones, and dealing with grief." Sheena McNeil of the same website gave the first volume a 7. McNeil called the concept of "what happens to the party when the quest is over?" interesting, praising as well Frieren's struggling with "becoming less detached" and seeing her experiencing the "lovely poignant moments, bittersweet ones, and happy ones". McNeil also compared the series' pace and feel to Haibane Renmei. The Fandom Post named it the sixth best manga of 2021. They wrote: "Time waits for no man and that line may be overused but that line strikes a chord in this manga. There is always more to discover and Frieren has to learn that lesson as time marches on. It’s a sweet but harsh reminder to enjoy the moment for all its worth."


==== Awards and nominations ====


== Notes ==


== References ==


== Further reading ==
Taniguchi, Ryuichi (September 18, 2020). 『葬送のフリーレン』魔王を倒した後の世界、不老長寿の魔法使いが抱いた思いとは?. Real Sound (in Japanese). Blueprint Co., Ltd. Archived from the original on October 3, 2020.
「葬送のフリーレン」特集 有野晋哉(よゐこ)、浦井健治、江口雄也(BLUE ENCOUNT)、小出祐介(Base Ball Bear)、近藤くみこ(ニッチェ)、須賀健太、鈴木達央、豊崎愛生が読後の思い綴る. Natalie (in Japanese). Natasha, Inc. October 16, 2020.
Eisenbeis, Richard (January 23, 2022). "Frieren: Beyond Journey's End GN 2 - Review". Anime News Network.
Eisenbeis, Richard (January 31, 2022). "Frieren: Beyond Journey's End is the Best Manga I Have Ever Read". Anime News Network.
Eisenbeis, Richard (May 27, 2022). "Frieren: Beyond Journey's End GN 3-4 - Review". Anime News Network.


== External links ==
Frieren: Beyond Journey's End official manga website at Web Sunday (in Japanese)
Frieren: Beyond Journey's End official anime website (in Japanese)
Frieren: Beyond Journey's End (manga) at Anime News Network's encyclopedia

あらすじ(plot)の部分を取り出します。

content_list = docs[0].page_content.split("\n")
plot_start = content_list.index("== Plot ==")
charactoers_start = content_list.index("== Characters ==")
plot_text = "\n".join(content_list[plot_start + 1:charactoers_start - 1])
print(plot_text)
The story follows elven mage Frieren, a former member of the party of adventurers who defeated the Demon King and restored harmony to the world after a ten-years-quest. In the past, the heroic group included Frieren, human hero Himmel, dwarven warrior Eisen and human priest Heiter. Before they part, they observe the Era Meteors together, a meteor shower that occurs once in fifty years. Frieren agrees to see them again and offer them a better view the next time the celestial event occurs. Frieren then departs and travels the world in pursuit of magical knowledge.
Frieren returns to the capital fifty years later; however, humanity has changed, and her former companions have distinctly aged. After one last adventure to see the meteor shower, Himmel dies of old age. During the funeral, Frieren expressed guilt for not attempting to learn more about him. Frieren then pays a visit to her other former comrades. She accepts an offer to teach and care for Fern, an orphaned child adopted by Heiter. She also receives an invitation to travel far north, to the resting place of souls, and see Himmel again to bid the hero a fitting farewell and express her feelings. To fulfill those requests, Frieren embarks on a journey together with Fern while still pursuing her passion for learning magic.
Frieren's elven nature grants her an extremely long lifespan, causing her to view periods of years or decades as ephemeral (this perception of time makes her consider the ten-year adventure with Himmel's party a fleeting experience). The story thus takes place across a long time, with periodic flashbacks accompanied by the physical and mental development of characters apart from Frieren herself.

テキストを要約します

from langchain.chains import LLMChain

llm = OpenAI(temperature=0, max_tokens=512)
prompt_template_text = """Write a concise summary of the following:


{text}


CONCISE SUMMARY IN JAPANESE:"""
prompt_template = PromptTemplate(template=prompt_template_text, input_variables=["text"])
chain = LLMChain(llm=llm, prompt=prompt_template)
Markdown(chain.run(plot_text))

Frierenは、魔王を倒し、世界に平和を取り戻した冒険者の一員であったエルフの魔術師である。彼女は、人間の英雄Himmel、ドワーフの戦士Eisen、人間の僧侶Heiterという仲間と共に、50年に一度のエラメテオを観測する前に別れを告げた。50年後、Frierenは元の仲間を再会し、Heiterが養子として迎えた子供Fernを教えることを受け入れる。さらに、Himmelを偉大な別れに迎えるため、魂の休息地へと旅立つことを決意する。Frierenは、エルフの特性により非常に長い寿命を持つため、10年間の冒険を瞬間的な経験として捉えている。この物語は、Frieren以外のキャラクターの物理的および精神的な発展を伴うフラッシュバックを織り交ぜながら、長い時間をかけて展開される。