{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "2b931208", "metadata": {}, "outputs": [], "source": [ "from langchain_community.document_loaders import TextLoader\n", "from langchain_text_splitters import CharacterTextSplitter\n", "from langchain_chroma import Chroma" ] }, { "cell_type": "code", "execution_count": 9, "id": "1adaad97", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
isbn13isbn10titleauthorscategoriesthumbnaildescriptionpublished_yearaverage_ratingnum_pagesratings_countagg_of_booktitle_and_subtitletagged_description
097800020058830002005883GileadMarilynne RobinsonFictionhttp://books.google.com/books/content?id=KQZCP...A NOVEL THAT READERS and critics have been eag...2004.03.85247.0361.021.0Gilead9780002005883 A NOVEL THAT READERS and critics...
197800022619820002261987Spider's WebCharles Osborne;Agatha ChristieDetective and mystery storieshttp://books.google.com/books/content?id=gA5GP...A new 'Christie for Christmas' -- a full-lengt...2000.03.83241.05164.025.0Spider's Web: A Novel9780002261982 A new 'Christie for Christmas' -...
297800061787360006178731Rage of angelsSidney SheldonFictionhttp://books.google.com/books/content?id=FKo2T...A memorable, mesmerizing heroine Jennifer -- b...1993.03.93512.029532.032.0Rage of angels9780006178736 A memorable, mesmerizing heroine...
397800062808970006280897The Four LovesClive Staples LewisChristian lifehttp://books.google.com/books/content?id=XhQ5X...Lewis' work on the nature of love divides love...2002.04.15170.033684.023.0The Four Loves9780006280897 Lewis' work on the nature of lov...
497800062809340006280935The Problem of PainClive Staples LewisChristian lifehttp://books.google.com/books/content?id=Kk-uV...\"In The Problem of Pain, C.S. Lewis, one of th...2002.04.09176.037569.023.0The Problem of Pain9780006280934 \"In The Problem of Pain, C.S. Le...
.............................................
519297881722352228172235224Mistaken IdentityNayantara SahgalIndic fiction (English)http://books.google.com/books/content?id=q-tKP...On A Train Journey Home To North India After L...2003.02.93324.00.022.0Mistaken Identity9788172235222 On A Train Journey Home To North...
519397881730310148173031010Journey to the EastHermann HesseAdventure storieshttp://books.google.com/books/content?id=rq6JP...This book tells the tale of a man who goes on ...2002.03.70175.024.023.0Journey to the East9788173031014 This book tells the tale of a ma...
51949788179921623817992162XThe Monk Who Sold His Ferrari: A Fable About F...Robin SharmaHealth & Fitnesshttp://books.google.com/books/content?id=c_7mf...Wisdom to Create a Life of Passion, Purpose, a...2003.03.82198.01568.022.0The Monk Who Sold His Ferrari: A Fable About F...9788179921623 Wisdom to Create a Life of Passi...
519597881853005358185300534I Am thatSri Nisargadatta Maharaj;Sudhakar S. DikshitPhilosophyhttp://books.google.com/books/content?id=Fv_JP...This collection of the timeless teachings of o...1999.04.51531.0104.026.0I Am that: Talks with Sri Nisargadatta Maharaj9788185300535 This collection of the timeless ...
519697890277120599027712050The Berlin PhenomenologyGeorg Wilhelm Friedrich HegelHistoryhttp://books.google.com/books/content?id=Vy7Sk...Since the three volume edition ofHegel's Philo...1981.00.00210.00.044.0The Berlin Phenomenology9789027712059 Since the three volume edition o...
\n", "

5197 rows × 14 columns

\n", "
" ], "text/plain": [ " isbn13 isbn10 \\\n", "0 9780002005883 0002005883 \n", "1 9780002261982 0002261987 \n", "2 9780006178736 0006178731 \n", "3 9780006280897 0006280897 \n", "4 9780006280934 0006280935 \n", "... ... ... \n", "5192 9788172235222 8172235224 \n", "5193 9788173031014 8173031010 \n", "5194 9788179921623 817992162X \n", "5195 9788185300535 8185300534 \n", "5196 9789027712059 9027712050 \n", "\n", " title \\\n", "0 Gilead \n", "1 Spider's Web \n", "2 Rage of angels \n", "3 The Four Loves \n", "4 The Problem of Pain \n", "... ... \n", "5192 Mistaken Identity \n", "5193 Journey to the East \n", "5194 The Monk Who Sold His Ferrari: A Fable About F... \n", "5195 I Am that \n", "5196 The Berlin Phenomenology \n", "\n", " authors \\\n", "0 Marilynne Robinson \n", "1 Charles Osborne;Agatha Christie \n", "2 Sidney Sheldon \n", "3 Clive Staples Lewis \n", "4 Clive Staples Lewis \n", "... ... \n", "5192 Nayantara Sahgal \n", "5193 Hermann Hesse \n", "5194 Robin Sharma \n", "5195 Sri Nisargadatta Maharaj;Sudhakar S. Dikshit \n", "5196 Georg Wilhelm Friedrich Hegel \n", "\n", " categories \\\n", "0 Fiction \n", "1 Detective and mystery stories \n", "2 Fiction \n", "3 Christian life \n", "4 Christian life \n", "... ... \n", "5192 Indic fiction (English) \n", "5193 Adventure stories \n", "5194 Health & Fitness \n", "5195 Philosophy \n", "5196 History \n", "\n", " thumbnail \\\n", "0 http://books.google.com/books/content?id=KQZCP... \n", "1 http://books.google.com/books/content?id=gA5GP... \n", "2 http://books.google.com/books/content?id=FKo2T... \n", "3 http://books.google.com/books/content?id=XhQ5X... \n", "4 http://books.google.com/books/content?id=Kk-uV... \n", "... ... \n", "5192 http://books.google.com/books/content?id=q-tKP... \n", "5193 http://books.google.com/books/content?id=rq6JP... \n", "5194 http://books.google.com/books/content?id=c_7mf... \n", "5195 http://books.google.com/books/content?id=Fv_JP... \n", "5196 http://books.google.com/books/content?id=Vy7Sk... \n", "\n", " description published_year \\\n", "0 A NOVEL THAT READERS and critics have been eag... 2004.0 \n", "1 A new 'Christie for Christmas' -- a full-lengt... 2000.0 \n", "2 A memorable, mesmerizing heroine Jennifer -- b... 1993.0 \n", "3 Lewis' work on the nature of love divides love... 2002.0 \n", "4 \"In The Problem of Pain, C.S. Lewis, one of th... 2002.0 \n", "... ... ... \n", "5192 On A Train Journey Home To North India After L... 2003.0 \n", "5193 This book tells the tale of a man who goes on ... 2002.0 \n", "5194 Wisdom to Create a Life of Passion, Purpose, a... 2003.0 \n", "5195 This collection of the timeless teachings of o... 1999.0 \n", "5196 Since the three volume edition ofHegel's Philo... 1981.0 \n", "\n", " average_rating num_pages ratings_count agg_of_book \\\n", "0 3.85 247.0 361.0 21.0 \n", "1 3.83 241.0 5164.0 25.0 \n", "2 3.93 512.0 29532.0 32.0 \n", "3 4.15 170.0 33684.0 23.0 \n", "4 4.09 176.0 37569.0 23.0 \n", "... ... ... ... ... \n", "5192 2.93 324.0 0.0 22.0 \n", "5193 3.70 175.0 24.0 23.0 \n", "5194 3.82 198.0 1568.0 22.0 \n", "5195 4.51 531.0 104.0 26.0 \n", "5196 0.00 210.0 0.0 44.0 \n", "\n", " title_and_subtitle \\\n", "0 Gilead \n", "1 Spider's Web: A Novel \n", "2 Rage of angels \n", "3 The Four Loves \n", "4 The Problem of Pain \n", "... ... \n", "5192 Mistaken Identity \n", "5193 Journey to the East \n", "5194 The Monk Who Sold His Ferrari: A Fable About F... \n", "5195 I Am that: Talks with Sri Nisargadatta Maharaj \n", "5196 The Berlin Phenomenology \n", "\n", " tagged_description \n", "0 9780002005883 A NOVEL THAT READERS and critics... \n", "1 9780002261982 A new 'Christie for Christmas' -... \n", "2 9780006178736 A memorable, mesmerizing heroine... \n", "3 9780006280897 Lewis' work on the nature of lov... \n", "4 9780006280934 \"In The Problem of Pain, C.S. Le... \n", "... ... \n", "5192 9788172235222 On A Train Journey Home To North... \n", "5193 9788173031014 This book tells the tale of a ma... \n", "5194 9788179921623 Wisdom to Create a Life of Passi... \n", "5195 9788185300535 This collection of the timeless ... \n", "5196 9789027712059 Since the three volume edition o... \n", "\n", "[5197 rows x 14 columns]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "books = pd.read_csv(\"books_cleaned.csv\")\n", "books" ] }, { "cell_type": "code", "execution_count": 9, "id": "4144c4c6", "metadata": {}, "outputs": [], "source": [ "books[\"tagged_description\"].to_csv(\"tagged_description.txt\",\n", " sep = \"\\n\",\n", " index = False,\n", " header = False)" ] }, { "cell_type": "code", "execution_count": null, "id": "80bd0392", "metadata": {}, "outputs": [], "source": [ "raw_documents = TextLoader(\"tagged_description.txt\", encoding='utf-8').load()\n", "text_splitter = CharacterTextSplitter(chunk_size=0, chunk_overlap=0, separator=\"\\n\")\n", "documents = text_splitter.split_documents(raw_documents)" ] }, { "cell_type": "code", "execution_count": 12, "id": "ddbb69ec", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Document(metadata={'source': 'tagged_description.txt'}, page_content='9780002005883 A NOVEL THAT READERS and critics have been eagerly anticipating for over a decade, Gilead is an astonishingly imagined story of remarkable lives. John Ames is a preacher, the son of a preacher and the grandson (both maternal and paternal) of preachers. It’s 1956 in Gilead, Iowa, towards the end of the Reverend Ames’s life, and he is absorbed in recording his family’s story, a legacy for the young son he will never see grow up. Haunted by his grandfather’s presence, John tells of the rift between his grandfather and his father: the elder, an angry visionary who fought for the abolitionist cause, and his son, an ardent pacifist. He is troubled, too, by his prodigal namesake, Jack (John Ames) Boughton, his best friend’s lost son who returns to Gilead searching for forgiveness and redemption. Told in John Ames’s joyous, rambling voice that finds beauty, humour and truth in the smallest of life’s details, Gilead is a song of celebration and acceptance of the best and the worst the world has to offer. At its heart is a tale of the sacred bonds between fathers and sons, pitch-perfect in style and story, set to dazzle critics and readers alike.')" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "documents[0]" ] }, { "cell_type": "code", "execution_count": null, "id": "1bc1e564", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\Users\\0105725U\\Documents\\Personal\\Book-recommender\\books_env\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n", "c:\\Users\\0105725U\\Documents\\Personal\\Book-recommender\\books_env\\Lib\\site-packages\\huggingface_hub\\file_download.py:143: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\\Users\\0105725U\\.cache\\huggingface\\hub\\models--sentence-transformers--paraphrase-MiniLM-L3-v2. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.\n", "To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development\n", " warnings.warn(message)\n", "Xet Storage is enabled for this repo, but the 'hf_xet' package is not installed. Falling back to regular HTTP download. For better performance, install the package with: `pip install huggingface_hub[hf_xet]` or `pip install hf_xet`\n" ] } ], "source": [ "from langchain_community.embeddings import HuggingFaceEmbeddings\n", "from langchain.vectorstores import Chroma\n", "\n", "embedding_model = HuggingFaceEmbeddings(model_name=\"sentence-transformers/paraphrase-MiniLM-L3-v2\")\n", "\n", "db_books = Chroma.from_documents(\n", " documents,\n", " embedding=embedding_model\n", ")\n" ] }, { "cell_type": "code", "execution_count": 8, "id": "8ed611b6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[Document(metadata={'source': 'tagged_description.txt'}, page_content=\"9780941807555 THE LITTLE BIG BOOK FOR GOD'S CHILDREN is a wonderful resource for parents looking to introduce their children to the wisdom and beauty of Christian faith. Illustrated with early twentieth-century art from artists such as Jessie Wilcox Smith, Ellen H. Clapsaddle, and Maud and Miska Petersham, this Little Big Book presents selected bible stories, parables, and verses; poems and prayers; excerpts and fables; songs and hymns; and activities - all collected in one delightful volume. A celebration of God's enduring message of love, GOD'S CHILDREN is sure to provide an endless wellspring of inspiration and hope.\"),\n", " Document(metadata={'source': 'tagged_description.txt'}, page_content='9788122200850 This book is the story of a young girl obsessed by a childhood prophecy of disaster. The author builds up an atmosphere of tension and oppression, in the middle of an Indian summer.'),\n", " Document(metadata={'source': 'tagged_description.txt'}, page_content='9780374422080 This Newbery Honor Book tells the story of 11 -year-old Primrose, who lives in a small fishing village in British Columbia. She recounts her experiences and all she learns about human nature and the unpredictability of life after her parents are lost at sea.'),\n", " Document(metadata={'source': 'tagged_description.txt'}, page_content=\"9780802431486 Drawn from years of counseling and the author's own parenting experiences, this valuable resource, filled with Scripture passages and accompanying practical applications, provides principles for raising and nurturing children in these uncertain and rapidly changing times. Original.\"),\n", " Document(metadata={'source': 'tagged_description.txt'}, page_content='9780374299194 The author describes growing up in a family of all boys in Webster Groves, Missouri, reflecting on such topics as the dynamics of a Christian youth fellowship, his role as the school prankster, his marriage, and the life lessons he has learned from birds.'),\n", " Document(metadata={'source': 'tagged_description.txt'}, page_content='9780671631987 With more than half a million copies in print, Teach Your Child to Read in 100 Easy Lessons is the definitive guide to giving your child the reading skills needed now for a better chance at tomorrow, while bringing you and your child closer together. Is your child halfway through first grade and still unable to read? Is your preschooler bored with coloring and ready for reading? Do you want to help your child read, but are afraid you’ll do something wrong? Teach Your Child to Read in 100 Easy Lessons is a complete, step-by-step program that shows patents simply and clearly how to teach their children to read. Twenty minutes a day is all you need, and within 100 teaching days your child will be reading on a solid second-grade reading level. It’s a sensible, easy-to-follow, and enjoyable way to help your child gain the essential skills of reading. Everything you need is here—no paste, no scissors, no flash cards, no complicated directions—just you and your child learning together. One hundred lessons, fully illustrated and color-coded for clarity, give your child the basic and more advanced skills needed to become a good reader.'),\n", " Document(metadata={'source': 'tagged_description.txt'}, page_content='9780143037392 Explains the importance of reading aloud to children, offers guidance on how to set up a read-aloud atmosphere in the home or classroom, and recommends titles to select.'),\n", " Document(metadata={'source': 'tagged_description.txt'}, page_content=\"9780064406925 The Little House books tell the story of a little pioneer girl and her family as they traveled by covered wagon across the Midwest. Laura Ingalls Wilder's classic books, illustrated with Garth Williams' timeless artwork, have been cherished by millions of readers ever since they were first published over sixty years ago. This My First Little House Book introduces Almanzo Wilder, the young boy from Farmer Boy who would one day marry Laura Ingalls. In Winter on the Farm, Almanzo goes through his afternoon barn chores, and then sits down to eat a hearty farm supper with his family. In this first book about Almanzo, young readers are able to share in the warmth and joy of another Little House family and celebrate new Little House adventures. Winter on the Farm is the first in an ongoing series about Laura’s beloved farmer boy.\"),\n", " Document(metadata={'source': 'tagged_description.txt'}, page_content='\"9780064462341 The pioneer spirit lives on... Readers around the world know and love Laura, the little girl born in the Big Woods of Wisconsin and raised in covered wagons and on wide open prairies. Now Little House fans can learn more about \"\"Half-pint\"\" in this, the first picture book biography book of Laura Ingalls Wilder. With a simple, glowing text by noted historian and Little House scholar William Anderson, and glorious paintings by Dan Andreasen, Pioneer Girl is a very special portrait of a writer whose classic books and poineer adventures have made her one of the most popular literary figures in America. This picture-book biography of Laura Ingalls Wilder tells the remarkable story of the pioneer girl who would one day immortalize her adventures in the beloved Little House books. Written in simple, glowing text by noted Little House scholar William Anderson, and illustrated with glorious paintings by artist Dan Andreasen, this wonderful first biography captures the very essence of the little girl called ‘Half-pint,\\' whose classic books and pioneer adventures have made her one of the most popular literary figures in America. This picture-book biography of Laura Ingalls Wilder tells the remarkable story of the pioneer girl who would one day immortalize her adventures in the beloved Little House books. Written in simple, glowing text by noted Little House scholar William Anderson, and illustrated with glorious paintings by artist Dan Andreasen, this wonderful first biography captures the very essence of the little girl called ‘Half-pint,’ whose classic books and pioneer adventures have made her one of the most popular literary figures in America.\"'),\n", " Document(metadata={'source': 'tagged_description.txt'}, page_content='9780743243780 The author describes his coming of age as a teacher, storyteller, and writer, a personal journey during which he spent fifteen years finding his voice in the classroom, and came to terms with the undervalued importance of teaching.')]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query = \"A book to teach children about nature\"\n", "docs = db_books.similarity_search(query, k = 10)\n", "docs" ] }, { "cell_type": "code", "execution_count": null, "id": "47e4c48c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
isbn13isbn10titleauthorscategoriesthumbnaildescriptionpublished_yearaverage_ratingnum_pagesratings_countagg_of_booktitle_and_subtitletagged_description
42649780941807555094180755XThe Little Big Book for God's ChildrenLena Tabori;Alice WongReligionhttp://books.google.com/books/content?id=s2PfT...THE LITTLE BIG BOOK FOR GOD'S CHILDREN is a wo...2001.04.88352.08.024.0The Little Big Book for God's Children9780941807555 THE LITTLE BIG BOOK FOR GOD'S CH...
\n", "
" ], "text/plain": [ " isbn13 isbn10 title \\\n", "4264 9780941807555 094180755X The Little Big Book for God's Children \n", "\n", " authors categories \\\n", "4264 Lena Tabori;Alice Wong Religion \n", "\n", " thumbnail \\\n", "4264 http://books.google.com/books/content?id=s2PfT... \n", "\n", " description published_year \\\n", "4264 THE LITTLE BIG BOOK FOR GOD'S CHILDREN is a wo... 2001.0 \n", "\n", " average_rating num_pages ratings_count agg_of_book \\\n", "4264 4.88 352.0 8.0 24.0 \n", "\n", " title_and_subtitle \\\n", "4264 The Little Big Book for God's Children \n", "\n", " tagged_description \n", "4264 9780941807555 THE LITTLE BIG BOOK FOR GOD'S CH... " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "books[books[\"isbn13\"] == int(docs[0].page_content.split()[0].strip())]" ] }, { "cell_type": "code", "execution_count": 11, "id": "43ed7a8c", "metadata": {}, "outputs": [], "source": [ "def retrieve_semantic_recommendation(\n", " query:str,\n", " top_k: int = 10,\n", ") -> pd.DataFrame :\n", " recs = db_books.similarity_search(query, k = 50)\n", "\n", " books_list = []\n", "\n", " for i in range (0, len(recs)):\n", " books_list += [int(recs[i].page_content.strip('\"\"').split()[0])]\n", "\n", " return books[books[\"isbn13\"].isin(books_list)].head(top_k)" ] }, { "cell_type": "code", "execution_count": 12, "id": "89dfb386", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
isbn13isbn10titleauthorscategoriesthumbnaildescriptionpublished_yearaverage_ratingnum_pagesratings_countagg_of_booktitle_and_subtitletagged_description
3197800071050450007105045Tree and LeafJohn Ronald Reuel TolkienLiterary Collectionshttp://books.google.com/books/content?id=aPb_A...\"The two works 'On fairy-stories' and 'Leaf by...2001.04.09176.02245.024.0Tree and Leaf: The Homecoming of Beorhtnoth : ...9780007105045 \"The two works 'On fairy-stories...
26797800608826000060882603The Annotated Charlotte's WebE. B. WhiteJuvenile Nonfictionhttp://books.google.com/books/content?id=vaYYH...Charlotte's Web, one of America's best-loved c...2006.04.16320.041.019.0The Annotated Charlotte's Web9780060882600 Charlotte's Web, one of America'...
32497800609590360060959037Prodigal SummerBarbara KingsolverFictionhttp://books.google.com/books/content?id=06IwG...Barbara Kingsolver's fifth novel is a hymn to ...2001.04.00444.085440.024.0Prodigal Summer: A Novel9780060959036 Barbara Kingsolver's fifth novel...
3979780062512796006251279XThe PilgrimagePaulo Coelho;Alan R. ClarkeFictionhttp://books.google.com/books/content?id=atdJc...Previously published as The Diary of a Magus, ...1995.03.65272.0878.030.0The Pilgrimage9780062512796 Previously published as The Diar...
4169780064406925006440692XWinter on the FarmLaura Ingalls WilderJuvenile Fictionhttp://books.google.com/books/content?id=IvlKH...The Little House books tell the story of a lit...1997.04.1332.0400.028.0Winter on the Farm9780064406925 The Little House books tell the ...
42997800644349800064434982The Deer in the WoodLaura Ingalls WilderJuvenile Fictionhttp://books.google.com/books/content?id=V7YDW...Even the youngest child can enjoy a special ad...1999.04.1732.0302.026.0The Deer in the Wood9780064434980 Even the youngest child can enjo...
43497800644620440064462048My Little House Crafts BookCarolyn Strom CollinsJuvenile Nonfictionhttp://books.google.com/books/content?id=lTzrs...Make the same pioneer crafts that Laura did! I...1998.04.0564.056.027.0My Little House Crafts Book: 18 Projects from ...9780064462044 Make the same pioneer crafts tha...
4359780064462341006446234XPioneer GirlWilliam AndersonJuvenile Nonfictionhttp://books.google.com/books/content?id=Sj4UD...The pioneer spirit lives on... Readers around ...2000.04.1532.0414.025.0Pioneer Girl: The Story of Laura Ingalls Wilder9780064462341 The pioneer spirit lives on... R...
44097800662385000066238501The Chronicles of Narnia (adult)C. S. LewisFictionhttp://books.google.com/books/content?id=3VGkK...Journeys to the end of the world, fantastic cr...2001.04.26767.0425445.024.0The Chronicles of Narnia (adult)9780066238500 Journeys to the end of the world...
4429780067575208006757520XThe Sense of WonderRachel CarsonNaturehttp://books.google.com/books/content?id=Zee5S...First published more than three decades ago, t...1998.04.39112.01160.027.0The Sense of Wonder9780067575208 First published more than three ...
\n", "
" ], "text/plain": [ " isbn13 isbn10 title \\\n", "31 9780007105045 0007105045 Tree and Leaf \n", "267 9780060882600 0060882603 The Annotated Charlotte's Web \n", "324 9780060959036 0060959037 Prodigal Summer \n", "397 9780062512796 006251279X The Pilgrimage \n", "416 9780064406925 006440692X Winter on the Farm \n", "429 9780064434980 0064434982 The Deer in the Wood \n", "434 9780064462044 0064462048 My Little House Crafts Book \n", "435 9780064462341 006446234X Pioneer Girl \n", "440 9780066238500 0066238501 The Chronicles of Narnia (adult) \n", "442 9780067575208 006757520X The Sense of Wonder \n", "\n", " authors categories \\\n", "31 John Ronald Reuel Tolkien Literary Collections \n", "267 E. B. White Juvenile Nonfiction \n", "324 Barbara Kingsolver Fiction \n", "397 Paulo Coelho;Alan R. Clarke Fiction \n", "416 Laura Ingalls Wilder Juvenile Fiction \n", "429 Laura Ingalls Wilder Juvenile Fiction \n", "434 Carolyn Strom Collins Juvenile Nonfiction \n", "435 William Anderson Juvenile Nonfiction \n", "440 C. S. Lewis Fiction \n", "442 Rachel Carson Nature \n", "\n", " thumbnail \\\n", "31 http://books.google.com/books/content?id=aPb_A... \n", "267 http://books.google.com/books/content?id=vaYYH... \n", "324 http://books.google.com/books/content?id=06IwG... \n", "397 http://books.google.com/books/content?id=atdJc... \n", "416 http://books.google.com/books/content?id=IvlKH... \n", "429 http://books.google.com/books/content?id=V7YDW... \n", "434 http://books.google.com/books/content?id=lTzrs... \n", "435 http://books.google.com/books/content?id=Sj4UD... \n", "440 http://books.google.com/books/content?id=3VGkK... \n", "442 http://books.google.com/books/content?id=Zee5S... \n", "\n", " description published_year \\\n", "31 \"The two works 'On fairy-stories' and 'Leaf by... 2001.0 \n", "267 Charlotte's Web, one of America's best-loved c... 2006.0 \n", "324 Barbara Kingsolver's fifth novel is a hymn to ... 2001.0 \n", "397 Previously published as The Diary of a Magus, ... 1995.0 \n", "416 The Little House books tell the story of a lit... 1997.0 \n", "429 Even the youngest child can enjoy a special ad... 1999.0 \n", "434 Make the same pioneer crafts that Laura did! I... 1998.0 \n", "435 The pioneer spirit lives on... Readers around ... 2000.0 \n", "440 Journeys to the end of the world, fantastic cr... 2001.0 \n", "442 First published more than three decades ago, t... 1998.0 \n", "\n", " average_rating num_pages ratings_count agg_of_book \\\n", "31 4.09 176.0 2245.0 24.0 \n", "267 4.16 320.0 41.0 19.0 \n", "324 4.00 444.0 85440.0 24.0 \n", "397 3.65 272.0 878.0 30.0 \n", "416 4.13 32.0 400.0 28.0 \n", "429 4.17 32.0 302.0 26.0 \n", "434 4.05 64.0 56.0 27.0 \n", "435 4.15 32.0 414.0 25.0 \n", "440 4.26 767.0 425445.0 24.0 \n", "442 4.39 112.0 1160.0 27.0 \n", "\n", " title_and_subtitle \\\n", "31 Tree and Leaf: The Homecoming of Beorhtnoth : ... \n", "267 The Annotated Charlotte's Web \n", "324 Prodigal Summer: A Novel \n", "397 The Pilgrimage \n", "416 Winter on the Farm \n", "429 The Deer in the Wood \n", "434 My Little House Crafts Book: 18 Projects from ... \n", "435 Pioneer Girl: The Story of Laura Ingalls Wilder \n", "440 The Chronicles of Narnia (adult) \n", "442 The Sense of Wonder \n", "\n", " tagged_description \n", "31 9780007105045 \"The two works 'On fairy-stories... \n", "267 9780060882600 Charlotte's Web, one of America'... \n", "324 9780060959036 Barbara Kingsolver's fifth novel... \n", "397 9780062512796 Previously published as The Diar... \n", "416 9780064406925 The Little House books tell the ... \n", "429 9780064434980 Even the youngest child can enjo... \n", "434 9780064462044 Make the same pioneer crafts tha... \n", "435 9780064462341 The pioneer spirit lives on... R... \n", "440 9780066238500 Journeys to the end of the world... \n", "442 9780067575208 First published more than three ... " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "retrieve_semantic_recommendation(\"A book to teach children about nature\")" ] }, { "cell_type": "code", "execution_count": null, "id": "f655cdbb", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "books_env", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.1" } }, "nbformat": 4, "nbformat_minor": 5 }