SovanlengLY
commited on
Commit
·
391de07
unverified
·
0
Parent(s):
Add files via upload
Browse files- books_cleaned.csv +0 -0
- books_with_categories.csv +0 -0
- books_with_emotions.csv +0 -0
- cover-not-found.jpg +0 -0
- data-exploration.ipynb +0 -0
- gradio-dashboard.py +107 -0
- requirement.txt +13 -0
- requirements.txt +12 -0
- sentiment-analysis.ipynb +1290 -0
- tagged_description.txt +0 -0
- text-classification.ipynb +0 -0
- vector-search.ipynb +954 -0
books_cleaned.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
books_with_categories.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
books_with_emotions.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
cover-not-found.jpg
ADDED
![]() |
data-exploration.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
gradio-dashboard.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
|
5 |
+
from langchain_community.document_loaders import TextLoader
|
6 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
7 |
+
from langchain_text_splitters import CharacterTextSplitter
|
8 |
+
from langchain_chroma import Chroma
|
9 |
+
|
10 |
+
import gradio as gr
|
11 |
+
|
12 |
+
|
13 |
+
load_dotenv()
|
14 |
+
|
15 |
+
books = pd.read_csv("books_with_emotions.csv")
|
16 |
+
books["large_thumbnail"] = books["thumbnail"] + "&fife=w800"
|
17 |
+
books["large_thumbnail"] = np.where(
|
18 |
+
books["large_thumbnail"].isna(),
|
19 |
+
"cover-not-found.jpg",
|
20 |
+
books["large_thumbnail"],
|
21 |
+
)
|
22 |
+
|
23 |
+
raw_documents = TextLoader("tagged_description.txt", encoding = 'utf-8').load()
|
24 |
+
|
25 |
+
text_splitter = CharacterTextSplitter(separator="\n", chunk_size=0, chunk_overlap=0)
|
26 |
+
documents = text_splitter.split_documents(raw_documents)
|
27 |
+
# use opensource embedding model instead of openai
|
28 |
+
embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/paraphrase-MiniLM-L3-v2")
|
29 |
+
db_books = Chroma.from_documents(
|
30 |
+
documents,
|
31 |
+
embedding=embedding_model
|
32 |
+
)
|
33 |
+
|
34 |
+
def retrieve_semantic_recommendations(
|
35 |
+
query: str,
|
36 |
+
category: str = None,
|
37 |
+
tone: str = None,
|
38 |
+
initial_top_k: int = 50,
|
39 |
+
final_top_k: int = 16,
|
40 |
+
) -> pd.DataFrame:
|
41 |
+
|
42 |
+
recs = db_books.similarity_search(query, k=initial_top_k)
|
43 |
+
books_list = [int(rec.page_content.strip('"').split()[0]) for rec in recs]
|
44 |
+
book_recs = books[books["isbn13"].isin(books_list)].head(initial_top_k)
|
45 |
+
|
46 |
+
if category != "All":
|
47 |
+
book_recs = book_recs[book_recs["simple_categories"] == category].head(final_top_k)
|
48 |
+
else:
|
49 |
+
book_recs = book_recs.head(final_top_k)
|
50 |
+
|
51 |
+
if tone == "Happy":
|
52 |
+
book_recs.sort_values(by="joy", ascending=False, inplace=True)
|
53 |
+
elif tone == "Surprising":
|
54 |
+
book_recs.sort_values(by="surprise", ascending=False, inplace=True)
|
55 |
+
elif tone == "Angry":
|
56 |
+
book_recs.sort_values(by="anger", ascending=False, inplace=True)
|
57 |
+
elif tone == "Suspenseful":
|
58 |
+
book_recs.sort_values(by="fear", ascending=False, inplace=True)
|
59 |
+
elif tone == "Sad":
|
60 |
+
book_recs.sort_values(by="sadness", ascending=False, inplace=True)
|
61 |
+
|
62 |
+
return book_recs
|
63 |
+
|
64 |
+
def recommend_books(query:str, category:str,tone:str ):
|
65 |
+
|
66 |
+
recommendations = retrieve_semantic_recommendations(query, category, tone)
|
67 |
+
results = []
|
68 |
+
|
69 |
+
for _, row in recommendations.iterrows():
|
70 |
+
description = row["description"]
|
71 |
+
truncated_desc_split = description.split()
|
72 |
+
truncated_description = " ".join(truncated_desc_split[:30]) + "..."
|
73 |
+
|
74 |
+
authors_split = row["authors"].split(";")
|
75 |
+
if len(authors_split) == 2:
|
76 |
+
authors_str = f"{authors_split[0]} and {authors_split[1]}"
|
77 |
+
elif len(authors_split) > 2:
|
78 |
+
authors_str = f"{', '.join(authors_split[:-1])}, and {authors_split[-1]}"
|
79 |
+
else:
|
80 |
+
authors_str = row["authors"]
|
81 |
+
caption = f"{row['title']} by {authors_str}: {truncated_description}"
|
82 |
+
results.append((row["large_thumbnail"], caption))
|
83 |
+
return results
|
84 |
+
|
85 |
+
categories = ["All"] + sorted(books["simple_categories"].unique())
|
86 |
+
tones = ["All"] + ["Happy", "Surprising", "Angry", "Suspenseful", "Sad"]
|
87 |
+
|
88 |
+
with gr.Blocks(theme = gr.themes.Glass()) as dashboard:
|
89 |
+
gr.Markdown("# Semantic book recommender")
|
90 |
+
|
91 |
+
with gr.Row():
|
92 |
+
user_query = gr.Textbox(label = "Please enter a description of a book:",
|
93 |
+
placeholder = "e.g., A story about forgiveness")
|
94 |
+
category_dropdown = gr.Dropdown(choices = categories, label = "Select a category:", value = "All")
|
95 |
+
tone_dropdown = gr.Dropdown(choices = tones, label = "Select an emotional tone:", value = "All")
|
96 |
+
submit_button = gr.Button("Find recommendations")
|
97 |
+
|
98 |
+
gr.Markdown("## Recommendations")
|
99 |
+
output = gr.Gallery(label = "Recommended books", columns = 8, rows = 2)
|
100 |
+
|
101 |
+
submit_button.click(fn = recommend_books,
|
102 |
+
inputs = [user_query, category_dropdown, tone_dropdown],
|
103 |
+
outputs = output)
|
104 |
+
|
105 |
+
|
106 |
+
if __name__ == "__main__":
|
107 |
+
dashboard.launch()
|
requirement.txt
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
numpy
|
3 |
+
matplotlib
|
4 |
+
seaborn
|
5 |
+
python-dotenv
|
6 |
+
langchain
|
7 |
+
langchain-chroma
|
8 |
+
langchain-openai
|
9 |
+
transformers
|
10 |
+
gradio
|
11 |
+
notebook
|
12 |
+
langchain_community
|
13 |
+
sentence_transformers
|
requirements.txt
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
numpy
|
3 |
+
matplotlib
|
4 |
+
seaborn
|
5 |
+
python-dotenv
|
6 |
+
langchain
|
7 |
+
langchain-chroma
|
8 |
+
transformers
|
9 |
+
gradio
|
10 |
+
notebook
|
11 |
+
langchain_community
|
12 |
+
sentence_transformers
|
sentiment-analysis.ipynb
ADDED
@@ -0,0 +1,1290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
+
"import pandas as pd\n",
|
17 |
+
"\n",
|
18 |
+
"books = pd.read_csv(\"books_with_categories.csv\")"
|
19 |
+
]
|
20 |
+
},
|
21 |
+
{
|
22 |
+
"cell_type": "code",
|
23 |
+
"execution_count": 2,
|
24 |
+
"id": "547ef724",
|
25 |
+
"metadata": {},
|
26 |
+
"outputs": [],
|
27 |
+
"source": [
|
28 |
+
"import torch"
|
29 |
+
]
|
30 |
+
},
|
31 |
+
{
|
32 |
+
"cell_type": "code",
|
33 |
+
"execution_count": null,
|
34 |
+
"id": "0184c98f",
|
35 |
+
"metadata": {},
|
36 |
+
"outputs": [
|
37 |
+
{
|
38 |
+
"name": "stderr",
|
39 |
+
"output_type": "stream",
|
40 |
+
"text": [
|
41 |
+
"Device set to use cuda\n"
|
42 |
+
]
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"data": {
|
46 |
+
"text/plain": [
|
47 |
+
"[[{'label': 'joy', 'score': 0.9771687984466553},\n",
|
48 |
+
" {'label': 'surprise', 'score': 0.008528684265911579},\n",
|
49 |
+
" {'label': 'neutral', 'score': 0.005764602683484554},\n",
|
50 |
+
" {'label': 'anger', 'score': 0.004419787786900997},\n",
|
51 |
+
" {'label': 'sadness', 'score': 0.0020923942793160677},\n",
|
52 |
+
" {'label': 'disgust', 'score': 0.0016119946958497167},\n",
|
53 |
+
" {'label': 'fear', 'score': 0.0004138521908316761}]]"
|
54 |
+
]
|
55 |
+
},
|
56 |
+
"execution_count": 4,
|
57 |
+
"metadata": {},
|
58 |
+
"output_type": "execute_result"
|
59 |
+
}
|
60 |
+
],
|
61 |
+
"source": [
|
62 |
+
"from transformers import pipeline\n",
|
63 |
+
"classifier = pipeline(\"text-classification\", \n",
|
64 |
+
" model=\"j-hartmann/emotion-english-distilroberta-base\",\n",
|
65 |
+
" top_k = None,\n",
|
66 |
+
" device = \"cuda\")\n",
|
67 |
+
"classifier(\"I love this!\")"
|
68 |
+
]
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"cell_type": "code",
|
72 |
+
"execution_count": 6,
|
73 |
+
"id": "ab7b7c6e",
|
74 |
+
"metadata": {},
|
75 |
+
"outputs": [
|
76 |
+
{
|
77 |
+
"data": {
|
78 |
+
"text/plain": [
|
79 |
+
"'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.'"
|
80 |
+
]
|
81 |
+
},
|
82 |
+
"execution_count": 6,
|
83 |
+
"metadata": {},
|
84 |
+
"output_type": "execute_result"
|
85 |
+
}
|
86 |
+
],
|
87 |
+
"source": [
|
88 |
+
"books[\"description\"][0]"
|
89 |
+
]
|
90 |
+
},
|
91 |
+
{
|
92 |
+
"cell_type": "code",
|
93 |
+
"execution_count": 7,
|
94 |
+
"id": "80d70c9c",
|
95 |
+
"metadata": {},
|
96 |
+
"outputs": [
|
97 |
+
{
|
98 |
+
"data": {
|
99 |
+
"text/plain": [
|
100 |
+
"[[{'label': 'fear', 'score': 0.6548407673835754},\n",
|
101 |
+
" {'label': 'neutral', 'score': 0.16985219717025757},\n",
|
102 |
+
" {'label': 'sadness', 'score': 0.11640916764736176},\n",
|
103 |
+
" {'label': 'surprise', 'score': 0.020700708031654358},\n",
|
104 |
+
" {'label': 'disgust', 'score': 0.019100721925497055},\n",
|
105 |
+
" {'label': 'joy', 'score': 0.01516129169613123},\n",
|
106 |
+
" {'label': 'anger', 'score': 0.0039351508021354675}]]"
|
107 |
+
]
|
108 |
+
},
|
109 |
+
"execution_count": 7,
|
110 |
+
"metadata": {},
|
111 |
+
"output_type": "execute_result"
|
112 |
+
}
|
113 |
+
],
|
114 |
+
"source": [
|
115 |
+
"classifier(books[\"description\"][0])"
|
116 |
+
]
|
117 |
+
},
|
118 |
+
{
|
119 |
+
"cell_type": "code",
|
120 |
+
"execution_count": 8,
|
121 |
+
"id": "d8c6e560",
|
122 |
+
"metadata": {},
|
123 |
+
"outputs": [
|
124 |
+
{
|
125 |
+
"data": {
|
126 |
+
"text/plain": [
|
127 |
+
"[[{'label': 'surprise', 'score': 0.7296026349067688},\n",
|
128 |
+
" {'label': 'neutral', 'score': 0.14038565754890442},\n",
|
129 |
+
" {'label': 'fear', 'score': 0.0681622102856636},\n",
|
130 |
+
" {'label': 'joy', 'score': 0.047942474484443665},\n",
|
131 |
+
" {'label': 'anger', 'score': 0.009156355634331703},\n",
|
132 |
+
" {'label': 'disgust', 'score': 0.002628473797813058},\n",
|
133 |
+
" {'label': 'sadness', 'score': 0.002122160280123353}],\n",
|
134 |
+
" [{'label': 'neutral', 'score': 0.4493710994720459},\n",
|
135 |
+
" {'label': 'disgust', 'score': 0.27359139919281006},\n",
|
136 |
+
" {'label': 'joy', 'score': 0.10908272117376328},\n",
|
137 |
+
" {'label': 'sadness', 'score': 0.09362725168466568},\n",
|
138 |
+
" {'label': 'anger', 'score': 0.04047825187444687},\n",
|
139 |
+
" {'label': 'surprise', 'score': 0.026970187202095985},\n",
|
140 |
+
" {'label': 'fear', 'score': 0.006879056338220835}],\n",
|
141 |
+
" [{'label': 'neutral', 'score': 0.6462168097496033},\n",
|
142 |
+
" {'label': 'sadness', 'score': 0.24273255467414856},\n",
|
143 |
+
" {'label': 'disgust', 'score': 0.04342259094119072},\n",
|
144 |
+
" {'label': 'surprise', 'score': 0.028300529345870018},\n",
|
145 |
+
" {'label': 'joy', 'score': 0.014211456291377544},\n",
|
146 |
+
" {'label': 'fear', 'score': 0.01408409047871828},\n",
|
147 |
+
" {'label': 'anger', 'score': 0.011031880043447018}],\n",
|
148 |
+
" [{'label': 'fear', 'score': 0.9281679391860962},\n",
|
149 |
+
" {'label': 'anger', 'score': 0.03219100087881088},\n",
|
150 |
+
" {'label': 'neutral', 'score': 0.012808752246201038},\n",
|
151 |
+
" {'label': 'sadness', 'score': 0.00875688437372446},\n",
|
152 |
+
" {'label': 'surprise', 'score': 0.008597937412559986},\n",
|
153 |
+
" {'label': 'disgust', 'score': 0.008431863971054554},\n",
|
154 |
+
" {'label': 'joy', 'score': 0.0010455828160047531}],\n",
|
155 |
+
" [{'label': 'sadness', 'score': 0.9671575427055359},\n",
|
156 |
+
" {'label': 'neutral', 'score': 0.015104170888662338},\n",
|
157 |
+
" {'label': 'disgust', 'score': 0.006480599287897348},\n",
|
158 |
+
" {'label': 'fear', 'score': 0.0053939977660775185},\n",
|
159 |
+
" {'label': 'surprise', 'score': 0.0022869440726935863},\n",
|
160 |
+
" {'label': 'anger', 'score': 0.0018428928451612592},\n",
|
161 |
+
" {'label': 'joy', 'score': 0.0017338799079880118}],\n",
|
162 |
+
" [{'label': 'joy', 'score': 0.9327967166900635},\n",
|
163 |
+
" {'label': 'disgust', 'score': 0.037718113511800766},\n",
|
164 |
+
" {'label': 'neutral', 'score': 0.015892023220658302},\n",
|
165 |
+
" {'label': 'sadness', 'score': 0.006444575730711222},\n",
|
166 |
+
" {'label': 'anger', 'score': 0.005025049671530724},\n",
|
167 |
+
" {'label': 'surprise', 'score': 0.0015812116907909513},\n",
|
168 |
+
" {'label': 'fear', 'score': 0.0005423118127509952}],\n",
|
169 |
+
" [{'label': 'joy', 'score': 0.6528710126876831},\n",
|
170 |
+
" {'label': 'neutral', 'score': 0.2542743384838104},\n",
|
171 |
+
" {'label': 'surprise', 'score': 0.06808304786682129},\n",
|
172 |
+
" {'label': 'sadness', 'score': 0.00990898534655571},\n",
|
173 |
+
" {'label': 'disgust', 'score': 0.006512206979095936},\n",
|
174 |
+
" {'label': 'anger', 'score': 0.004821315407752991},\n",
|
175 |
+
" {'label': 'fear', 'score': 0.003529016859829426}],\n",
|
176 |
+
" [{'label': 'neutral', 'score': 0.5494765043258667},\n",
|
177 |
+
" {'label': 'sadness', 'score': 0.1116902157664299},\n",
|
178 |
+
" {'label': 'disgust', 'score': 0.10400670766830444},\n",
|
179 |
+
" {'label': 'surprise', 'score': 0.07876554876565933},\n",
|
180 |
+
" {'label': 'anger', 'score': 0.0641336739063263},\n",
|
181 |
+
" {'label': 'fear', 'score': 0.05136284604668617},\n",
|
182 |
+
" {'label': 'joy', 'score': 0.04056443274021149}]]"
|
183 |
+
]
|
184 |
+
},
|
185 |
+
"execution_count": 8,
|
186 |
+
"metadata": {},
|
187 |
+
"output_type": "execute_result"
|
188 |
+
}
|
189 |
+
],
|
190 |
+
"source": [
|
191 |
+
"classifier(books[\"description\"][0].split(\".\"))"
|
192 |
+
]
|
193 |
+
},
|
194 |
+
{
|
195 |
+
"cell_type": "code",
|
196 |
+
"execution_count": 9,
|
197 |
+
"id": "ecd96f5e",
|
198 |
+
"metadata": {},
|
199 |
+
"outputs": [],
|
200 |
+
"source": [
|
201 |
+
"sentences = books[\"description\"][0].split(\".\")\n",
|
202 |
+
"predictions = classifier(sentences)"
|
203 |
+
]
|
204 |
+
},
|
205 |
+
{
|
206 |
+
"cell_type": "code",
|
207 |
+
"execution_count": 10,
|
208 |
+
"id": "395f13c4",
|
209 |
+
"metadata": {},
|
210 |
+
"outputs": [
|
211 |
+
{
|
212 |
+
"data": {
|
213 |
+
"text/plain": [
|
214 |
+
"'A NOVEL THAT READERS and critics have been eagerly anticipating for over a decade, Gilead is an astonishingly imagined story of remarkable lives'"
|
215 |
+
]
|
216 |
+
},
|
217 |
+
"execution_count": 10,
|
218 |
+
"metadata": {},
|
219 |
+
"output_type": "execute_result"
|
220 |
+
}
|
221 |
+
],
|
222 |
+
"source": [
|
223 |
+
"sentences[0]"
|
224 |
+
]
|
225 |
+
},
|
226 |
+
{
|
227 |
+
"cell_type": "code",
|
228 |
+
"execution_count": 11,
|
229 |
+
"id": "0f136f0e",
|
230 |
+
"metadata": {},
|
231 |
+
"outputs": [
|
232 |
+
{
|
233 |
+
"data": {
|
234 |
+
"text/plain": [
|
235 |
+
"[{'label': 'surprise', 'score': 0.7296026349067688},\n",
|
236 |
+
" {'label': 'neutral', 'score': 0.14038565754890442},\n",
|
237 |
+
" {'label': 'fear', 'score': 0.0681622102856636},\n",
|
238 |
+
" {'label': 'joy', 'score': 0.047942474484443665},\n",
|
239 |
+
" {'label': 'anger', 'score': 0.009156355634331703},\n",
|
240 |
+
" {'label': 'disgust', 'score': 0.002628473797813058},\n",
|
241 |
+
" {'label': 'sadness', 'score': 0.002122160280123353}]"
|
242 |
+
]
|
243 |
+
},
|
244 |
+
"execution_count": 11,
|
245 |
+
"metadata": {},
|
246 |
+
"output_type": "execute_result"
|
247 |
+
}
|
248 |
+
],
|
249 |
+
"source": [
|
250 |
+
"predictions[0]"
|
251 |
+
]
|
252 |
+
},
|
253 |
+
{
|
254 |
+
"cell_type": "code",
|
255 |
+
"execution_count": 12,
|
256 |
+
"id": "5468ffde",
|
257 |
+
"metadata": {},
|
258 |
+
"outputs": [
|
259 |
+
{
|
260 |
+
"data": {
|
261 |
+
"text/plain": [
|
262 |
+
"' 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'"
|
263 |
+
]
|
264 |
+
},
|
265 |
+
"execution_count": 12,
|
266 |
+
"metadata": {},
|
267 |
+
"output_type": "execute_result"
|
268 |
+
}
|
269 |
+
],
|
270 |
+
"source": [
|
271 |
+
"sentences[3]"
|
272 |
+
]
|
273 |
+
},
|
274 |
+
{
|
275 |
+
"cell_type": "code",
|
276 |
+
"execution_count": 13,
|
277 |
+
"id": "4cec13a5",
|
278 |
+
"metadata": {},
|
279 |
+
"outputs": [
|
280 |
+
{
|
281 |
+
"data": {
|
282 |
+
"text/plain": [
|
283 |
+
"[{'label': 'fear', 'score': 0.9281679391860962},\n",
|
284 |
+
" {'label': 'anger', 'score': 0.03219100087881088},\n",
|
285 |
+
" {'label': 'neutral', 'score': 0.012808752246201038},\n",
|
286 |
+
" {'label': 'sadness', 'score': 0.00875688437372446},\n",
|
287 |
+
" {'label': 'surprise', 'score': 0.008597937412559986},\n",
|
288 |
+
" {'label': 'disgust', 'score': 0.008431863971054554},\n",
|
289 |
+
" {'label': 'joy', 'score': 0.0010455828160047531}]"
|
290 |
+
]
|
291 |
+
},
|
292 |
+
"execution_count": 13,
|
293 |
+
"metadata": {},
|
294 |
+
"output_type": "execute_result"
|
295 |
+
}
|
296 |
+
],
|
297 |
+
"source": [
|
298 |
+
"predictions[3]"
|
299 |
+
]
|
300 |
+
},
|
301 |
+
{
|
302 |
+
"cell_type": "code",
|
303 |
+
"execution_count": 14,
|
304 |
+
"id": "08252ce7",
|
305 |
+
"metadata": {},
|
306 |
+
"outputs": [
|
307 |
+
{
|
308 |
+
"data": {
|
309 |
+
"text/plain": [
|
310 |
+
"[[{'label': 'surprise', 'score': 0.7296026349067688},\n",
|
311 |
+
" {'label': 'neutral', 'score': 0.14038565754890442},\n",
|
312 |
+
" {'label': 'fear', 'score': 0.0681622102856636},\n",
|
313 |
+
" {'label': 'joy', 'score': 0.047942474484443665},\n",
|
314 |
+
" {'label': 'anger', 'score': 0.009156355634331703},\n",
|
315 |
+
" {'label': 'disgust', 'score': 0.002628473797813058},\n",
|
316 |
+
" {'label': 'sadness', 'score': 0.002122160280123353}],\n",
|
317 |
+
" [{'label': 'neutral', 'score': 0.4493710994720459},\n",
|
318 |
+
" {'label': 'disgust', 'score': 0.27359139919281006},\n",
|
319 |
+
" {'label': 'joy', 'score': 0.10908272117376328},\n",
|
320 |
+
" {'label': 'sadness', 'score': 0.09362725168466568},\n",
|
321 |
+
" {'label': 'anger', 'score': 0.04047825187444687},\n",
|
322 |
+
" {'label': 'surprise', 'score': 0.026970187202095985},\n",
|
323 |
+
" {'label': 'fear', 'score': 0.006879056338220835}],\n",
|
324 |
+
" [{'label': 'neutral', 'score': 0.6462168097496033},\n",
|
325 |
+
" {'label': 'sadness', 'score': 0.24273255467414856},\n",
|
326 |
+
" {'label': 'disgust', 'score': 0.04342259094119072},\n",
|
327 |
+
" {'label': 'surprise', 'score': 0.028300529345870018},\n",
|
328 |
+
" {'label': 'joy', 'score': 0.014211456291377544},\n",
|
329 |
+
" {'label': 'fear', 'score': 0.01408409047871828},\n",
|
330 |
+
" {'label': 'anger', 'score': 0.011031880043447018}],\n",
|
331 |
+
" [{'label': 'fear', 'score': 0.9281679391860962},\n",
|
332 |
+
" {'label': 'anger', 'score': 0.03219100087881088},\n",
|
333 |
+
" {'label': 'neutral', 'score': 0.012808752246201038},\n",
|
334 |
+
" {'label': 'sadness', 'score': 0.00875688437372446},\n",
|
335 |
+
" {'label': 'surprise', 'score': 0.008597937412559986},\n",
|
336 |
+
" {'label': 'disgust', 'score': 0.008431863971054554},\n",
|
337 |
+
" {'label': 'joy', 'score': 0.0010455828160047531}],\n",
|
338 |
+
" [{'label': 'sadness', 'score': 0.9671575427055359},\n",
|
339 |
+
" {'label': 'neutral', 'score': 0.015104170888662338},\n",
|
340 |
+
" {'label': 'disgust', 'score': 0.006480599287897348},\n",
|
341 |
+
" {'label': 'fear', 'score': 0.0053939977660775185},\n",
|
342 |
+
" {'label': 'surprise', 'score': 0.0022869440726935863},\n",
|
343 |
+
" {'label': 'anger', 'score': 0.0018428928451612592},\n",
|
344 |
+
" {'label': 'joy', 'score': 0.0017338799079880118}],\n",
|
345 |
+
" [{'label': 'joy', 'score': 0.9327967166900635},\n",
|
346 |
+
" {'label': 'disgust', 'score': 0.037718113511800766},\n",
|
347 |
+
" {'label': 'neutral', 'score': 0.015892023220658302},\n",
|
348 |
+
" {'label': 'sadness', 'score': 0.006444575730711222},\n",
|
349 |
+
" {'label': 'anger', 'score': 0.005025049671530724},\n",
|
350 |
+
" {'label': 'surprise', 'score': 0.0015812116907909513},\n",
|
351 |
+
" {'label': 'fear', 'score': 0.0005423118127509952}],\n",
|
352 |
+
" [{'label': 'joy', 'score': 0.6528710126876831},\n",
|
353 |
+
" {'label': 'neutral', 'score': 0.2542743384838104},\n",
|
354 |
+
" {'label': 'surprise', 'score': 0.06808304786682129},\n",
|
355 |
+
" {'label': 'sadness', 'score': 0.00990898534655571},\n",
|
356 |
+
" {'label': 'disgust', 'score': 0.006512206979095936},\n",
|
357 |
+
" {'label': 'anger', 'score': 0.004821315407752991},\n",
|
358 |
+
" {'label': 'fear', 'score': 0.003529016859829426}],\n",
|
359 |
+
" [{'label': 'neutral', 'score': 0.5494765043258667},\n",
|
360 |
+
" {'label': 'sadness', 'score': 0.1116902157664299},\n",
|
361 |
+
" {'label': 'disgust', 'score': 0.10400670766830444},\n",
|
362 |
+
" {'label': 'surprise', 'score': 0.07876554876565933},\n",
|
363 |
+
" {'label': 'anger', 'score': 0.0641336739063263},\n",
|
364 |
+
" {'label': 'fear', 'score': 0.05136284604668617},\n",
|
365 |
+
" {'label': 'joy', 'score': 0.04056443274021149}]]"
|
366 |
+
]
|
367 |
+
},
|
368 |
+
"execution_count": 14,
|
369 |
+
"metadata": {},
|
370 |
+
"output_type": "execute_result"
|
371 |
+
}
|
372 |
+
],
|
373 |
+
"source": [
|
374 |
+
"predictions"
|
375 |
+
]
|
376 |
+
},
|
377 |
+
{
|
378 |
+
"cell_type": "code",
|
379 |
+
"execution_count": 15,
|
380 |
+
"id": "e76fc604",
|
381 |
+
"metadata": {},
|
382 |
+
"outputs": [
|
383 |
+
{
|
384 |
+
"data": {
|
385 |
+
"text/plain": [
|
386 |
+
"[{'label': 'anger', 'score': 0.009156355634331703},\n",
|
387 |
+
" {'label': 'disgust', 'score': 0.002628473797813058},\n",
|
388 |
+
" {'label': 'fear', 'score': 0.0681622102856636},\n",
|
389 |
+
" {'label': 'joy', 'score': 0.047942474484443665},\n",
|
390 |
+
" {'label': 'neutral', 'score': 0.14038565754890442},\n",
|
391 |
+
" {'label': 'sadness', 'score': 0.002122160280123353},\n",
|
392 |
+
" {'label': 'surprise', 'score': 0.7296026349067688}]"
|
393 |
+
]
|
394 |
+
},
|
395 |
+
"execution_count": 15,
|
396 |
+
"metadata": {},
|
397 |
+
"output_type": "execute_result"
|
398 |
+
}
|
399 |
+
],
|
400 |
+
"source": [
|
401 |
+
"sorted(predictions[0], key = lambda x:x[\"label\"])"
|
402 |
+
]
|
403 |
+
},
|
404 |
+
{
|
405 |
+
"cell_type": "code",
|
406 |
+
"execution_count": 21,
|
407 |
+
"id": "bb49276c",
|
408 |
+
"metadata": {},
|
409 |
+
"outputs": [],
|
410 |
+
"source": [
|
411 |
+
"import numpy as np\n",
|
412 |
+
"\n",
|
413 |
+
"emotion_labels = [\"anger\", \"disgust\", \"fear\", \"joy\", \"sadness\", \"surprise\", \"neutral\"]\n",
|
414 |
+
"isbn = []\n",
|
415 |
+
"emotion_scores = {label: [] for label in emotion_labels}\n",
|
416 |
+
"\n",
|
417 |
+
"def calculate_max_emotion_score(predictions):\n",
|
418 |
+
" per_emotion_scores = {label:[] for label in emotion_labels}\n",
|
419 |
+
" for prediction in predictions:\n",
|
420 |
+
" sorted_predictions = sorted(prediction, key = lambda x: x[\"label\"])\n",
|
421 |
+
" for index, label in enumerate(emotion_labels):\n",
|
422 |
+
" per_emotion_scores[label].append(sorted_predictions[index][\"score\"])\n",
|
423 |
+
" return {label: np.max(scores) for label, scores in per_emotion_scores.items()}"
|
424 |
+
]
|
425 |
+
},
|
426 |
+
{
|
427 |
+
"cell_type": "code",
|
428 |
+
"execution_count": null,
|
429 |
+
"id": "4e3fc36a",
|
430 |
+
"metadata": {},
|
431 |
+
"outputs": [
|
432 |
+
{
|
433 |
+
"name": "stderr",
|
434 |
+
"output_type": "stream",
|
435 |
+
"text": [
|
436 |
+
"You seem to be using the pipelines sequentially on GPU. In order to maximize efficiency please use a dataset\n"
|
437 |
+
]
|
438 |
+
}
|
439 |
+
],
|
440 |
+
"source": [
|
441 |
+
"for i in range(10):\n",
|
442 |
+
" isbn.append(books[\"isbn13\"][i])\n",
|
443 |
+
" sentences = books[\"description\"][0].split(\".\")\n",
|
444 |
+
" predictions = classifier(sentences)\n",
|
445 |
+
" max_scores = calculate_max_emotion_score(predictions)\n",
|
446 |
+
" for label in emotion_labels:\n",
|
447 |
+
" emotion_scores[label].append(max_scores[label])"
|
448 |
+
]
|
449 |
+
},
|
450 |
+
{
|
451 |
+
"cell_type": "code",
|
452 |
+
"execution_count": 20,
|
453 |
+
"id": "a5ea90b1",
|
454 |
+
"metadata": {},
|
455 |
+
"outputs": [
|
456 |
+
{
|
457 |
+
"data": {
|
458 |
+
"text/plain": [
|
459 |
+
"{'anger': [np.float64(0.0641336739063263),\n",
|
460 |
+
" np.float64(0.0641336739063263),\n",
|
461 |
+
" np.float64(0.0641336739063263),\n",
|
462 |
+
" np.float64(0.0641336739063263),\n",
|
463 |
+
" np.float64(0.0641336739063263),\n",
|
464 |
+
" np.float64(0.0641336739063263),\n",
|
465 |
+
" np.float64(0.0641336739063263),\n",
|
466 |
+
" np.float64(0.0641336739063263),\n",
|
467 |
+
" np.float64(0.0641336739063263),\n",
|
468 |
+
" np.float64(0.0641336739063263)],\n",
|
469 |
+
" 'disgust': [np.float64(0.27359139919281006),\n",
|
470 |
+
" np.float64(0.27359139919281006),\n",
|
471 |
+
" np.float64(0.27359139919281006),\n",
|
472 |
+
" np.float64(0.27359139919281006),\n",
|
473 |
+
" np.float64(0.27359139919281006),\n",
|
474 |
+
" np.float64(0.27359139919281006),\n",
|
475 |
+
" np.float64(0.27359139919281006),\n",
|
476 |
+
" np.float64(0.27359139919281006),\n",
|
477 |
+
" np.float64(0.27359139919281006),\n",
|
478 |
+
" np.float64(0.27359139919281006)],\n",
|
479 |
+
" 'fear': [np.float64(0.9281679391860962),\n",
|
480 |
+
" np.float64(0.9281679391860962),\n",
|
481 |
+
" np.float64(0.9281679391860962),\n",
|
482 |
+
" np.float64(0.9281679391860962),\n",
|
483 |
+
" np.float64(0.9281679391860962),\n",
|
484 |
+
" np.float64(0.9281679391860962),\n",
|
485 |
+
" np.float64(0.9281679391860962),\n",
|
486 |
+
" np.float64(0.9281679391860962),\n",
|
487 |
+
" np.float64(0.9281679391860962),\n",
|
488 |
+
" np.float64(0.9281679391860962)],\n",
|
489 |
+
" 'joy': [np.float64(0.9327967166900635),\n",
|
490 |
+
" np.float64(0.9327967166900635),\n",
|
491 |
+
" np.float64(0.9327967166900635),\n",
|
492 |
+
" np.float64(0.9327967166900635),\n",
|
493 |
+
" np.float64(0.9327967166900635),\n",
|
494 |
+
" np.float64(0.9327967166900635),\n",
|
495 |
+
" np.float64(0.9327967166900635),\n",
|
496 |
+
" np.float64(0.9327967166900635),\n",
|
497 |
+
" np.float64(0.9327967166900635),\n",
|
498 |
+
" np.float64(0.9327967166900635)],\n",
|
499 |
+
" 'sadness': [np.float64(0.6462168097496033),\n",
|
500 |
+
" np.float64(0.6462168097496033),\n",
|
501 |
+
" np.float64(0.6462168097496033),\n",
|
502 |
+
" np.float64(0.6462168097496033),\n",
|
503 |
+
" np.float64(0.6462168097496033),\n",
|
504 |
+
" np.float64(0.6462168097496033),\n",
|
505 |
+
" np.float64(0.6462168097496033),\n",
|
506 |
+
" np.float64(0.6462168097496033),\n",
|
507 |
+
" np.float64(0.6462168097496033),\n",
|
508 |
+
" np.float64(0.6462168097496033)],\n",
|
509 |
+
" 'surprise': [np.float64(0.9671575427055359),\n",
|
510 |
+
" np.float64(0.9671575427055359),\n",
|
511 |
+
" np.float64(0.9671575427055359),\n",
|
512 |
+
" np.float64(0.9671575427055359),\n",
|
513 |
+
" np.float64(0.9671575427055359),\n",
|
514 |
+
" np.float64(0.9671575427055359),\n",
|
515 |
+
" np.float64(0.9671575427055359),\n",
|
516 |
+
" np.float64(0.9671575427055359),\n",
|
517 |
+
" np.float64(0.9671575427055359),\n",
|
518 |
+
" np.float64(0.9671575427055359)],\n",
|
519 |
+
" 'neutral': [np.float64(0.7296026349067688),\n",
|
520 |
+
" np.float64(0.7296026349067688),\n",
|
521 |
+
" np.float64(0.7296026349067688),\n",
|
522 |
+
" np.float64(0.7296026349067688),\n",
|
523 |
+
" np.float64(0.7296026349067688),\n",
|
524 |
+
" np.float64(0.7296026349067688),\n",
|
525 |
+
" np.float64(0.7296026349067688),\n",
|
526 |
+
" np.float64(0.7296026349067688),\n",
|
527 |
+
" np.float64(0.7296026349067688),\n",
|
528 |
+
" np.float64(0.7296026349067688)]}"
|
529 |
+
]
|
530 |
+
},
|
531 |
+
"execution_count": 20,
|
532 |
+
"metadata": {},
|
533 |
+
"output_type": "execute_result"
|
534 |
+
}
|
535 |
+
],
|
536 |
+
"source": [
|
537 |
+
"emotion_scores"
|
538 |
+
]
|
539 |
+
},
|
540 |
+
{
|
541 |
+
"cell_type": "code",
|
542 |
+
"execution_count": 22,
|
543 |
+
"id": "5b2ca76f",
|
544 |
+
"metadata": {},
|
545 |
+
"outputs": [
|
546 |
+
{
|
547 |
+
"name": "stderr",
|
548 |
+
"output_type": "stream",
|
549 |
+
"text": [
|
550 |
+
"100%|██████████| 5197/5197 [01:58<00:00, 43.92it/s]\n"
|
551 |
+
]
|
552 |
+
}
|
553 |
+
],
|
554 |
+
"source": [
|
555 |
+
"\n",
|
556 |
+
"from tqdm import tqdm\n",
|
557 |
+
"\n",
|
558 |
+
"emotion_labels = [\"anger\", \"disgust\", \"fear\", \"joy\", \"sadness\", \"surprise\", \"neutral\"]\n",
|
559 |
+
"isbn = []\n",
|
560 |
+
"emotion_scores = {label: [] for label in emotion_labels}\n",
|
561 |
+
"\n",
|
562 |
+
"for i in tqdm(range(len(books))):\n",
|
563 |
+
" isbn.append(books[\"isbn13\"][i])\n",
|
564 |
+
" sentences = books[\"description\"][i].split(\".\")\n",
|
565 |
+
" predictions = classifier(sentences)\n",
|
566 |
+
" max_scores = calculate_max_emotion_score(predictions)\n",
|
567 |
+
" for label in emotion_labels:\n",
|
568 |
+
" emotion_scores[label].append(max_scores[label])"
|
569 |
+
]
|
570 |
+
},
|
571 |
+
{
|
572 |
+
"cell_type": "code",
|
573 |
+
"execution_count": 23,
|
574 |
+
"id": "f69ecf48",
|
575 |
+
"metadata": {},
|
576 |
+
"outputs": [],
|
577 |
+
"source": [
|
578 |
+
"emotions_df = pd.DataFrame(emotion_scores)\n",
|
579 |
+
"emotions_df[\"isbn13\"] = isbn"
|
580 |
+
]
|
581 |
+
},
|
582 |
+
{
|
583 |
+
"cell_type": "code",
|
584 |
+
"execution_count": 24,
|
585 |
+
"id": "f74c27e0",
|
586 |
+
"metadata": {},
|
587 |
+
"outputs": [
|
588 |
+
{
|
589 |
+
"data": {
|
590 |
+
"text/html": [
|
591 |
+
"<div>\n",
|
592 |
+
"<style scoped>\n",
|
593 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
594 |
+
" vertical-align: middle;\n",
|
595 |
+
" }\n",
|
596 |
+
"\n",
|
597 |
+
" .dataframe tbody tr th {\n",
|
598 |
+
" vertical-align: top;\n",
|
599 |
+
" }\n",
|
600 |
+
"\n",
|
601 |
+
" .dataframe thead th {\n",
|
602 |
+
" text-align: right;\n",
|
603 |
+
" }\n",
|
604 |
+
"</style>\n",
|
605 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
606 |
+
" <thead>\n",
|
607 |
+
" <tr style=\"text-align: right;\">\n",
|
608 |
+
" <th></th>\n",
|
609 |
+
" <th>anger</th>\n",
|
610 |
+
" <th>disgust</th>\n",
|
611 |
+
" <th>fear</th>\n",
|
612 |
+
" <th>joy</th>\n",
|
613 |
+
" <th>sadness</th>\n",
|
614 |
+
" <th>surprise</th>\n",
|
615 |
+
" <th>neutral</th>\n",
|
616 |
+
" <th>isbn13</th>\n",
|
617 |
+
" </tr>\n",
|
618 |
+
" </thead>\n",
|
619 |
+
" <tbody>\n",
|
620 |
+
" <tr>\n",
|
621 |
+
" <th>0</th>\n",
|
622 |
+
" <td>0.064134</td>\n",
|
623 |
+
" <td>0.273591</td>\n",
|
624 |
+
" <td>0.928168</td>\n",
|
625 |
+
" <td>0.932797</td>\n",
|
626 |
+
" <td>0.646217</td>\n",
|
627 |
+
" <td>0.967158</td>\n",
|
628 |
+
" <td>0.729603</td>\n",
|
629 |
+
" <td>9780002005883</td>\n",
|
630 |
+
" </tr>\n",
|
631 |
+
" <tr>\n",
|
632 |
+
" <th>1</th>\n",
|
633 |
+
" <td>0.612619</td>\n",
|
634 |
+
" <td>0.348285</td>\n",
|
635 |
+
" <td>0.942528</td>\n",
|
636 |
+
" <td>0.704421</td>\n",
|
637 |
+
" <td>0.887939</td>\n",
|
638 |
+
" <td>0.111690</td>\n",
|
639 |
+
" <td>0.252545</td>\n",
|
640 |
+
" <td>9780002261982</td>\n",
|
641 |
+
" </tr>\n",
|
642 |
+
" <tr>\n",
|
643 |
+
" <th>2</th>\n",
|
644 |
+
" <td>0.064134</td>\n",
|
645 |
+
" <td>0.104007</td>\n",
|
646 |
+
" <td>0.972321</td>\n",
|
647 |
+
" <td>0.767236</td>\n",
|
648 |
+
" <td>0.549477</td>\n",
|
649 |
+
" <td>0.111690</td>\n",
|
650 |
+
" <td>0.078766</td>\n",
|
651 |
+
" <td>9780006178736</td>\n",
|
652 |
+
" </tr>\n",
|
653 |
+
" <tr>\n",
|
654 |
+
" <th>3</th>\n",
|
655 |
+
" <td>0.351483</td>\n",
|
656 |
+
" <td>0.150722</td>\n",
|
657 |
+
" <td>0.360707</td>\n",
|
658 |
+
" <td>0.251881</td>\n",
|
659 |
+
" <td>0.732685</td>\n",
|
660 |
+
" <td>0.111690</td>\n",
|
661 |
+
" <td>0.078766</td>\n",
|
662 |
+
" <td>9780006280897</td>\n",
|
663 |
+
" </tr>\n",
|
664 |
+
" <tr>\n",
|
665 |
+
" <th>4</th>\n",
|
666 |
+
" <td>0.081412</td>\n",
|
667 |
+
" <td>0.184495</td>\n",
|
668 |
+
" <td>0.095043</td>\n",
|
669 |
+
" <td>0.040564</td>\n",
|
670 |
+
" <td>0.884389</td>\n",
|
671 |
+
" <td>0.475881</td>\n",
|
672 |
+
" <td>0.078766</td>\n",
|
673 |
+
" <td>9780006280934</td>\n",
|
674 |
+
" </tr>\n",
|
675 |
+
" <tr>\n",
|
676 |
+
" <th>...</th>\n",
|
677 |
+
" <td>...</td>\n",
|
678 |
+
" <td>...</td>\n",
|
679 |
+
" <td>...</td>\n",
|
680 |
+
" <td>...</td>\n",
|
681 |
+
" <td>...</td>\n",
|
682 |
+
" <td>...</td>\n",
|
683 |
+
" <td>...</td>\n",
|
684 |
+
" <td>...</td>\n",
|
685 |
+
" </tr>\n",
|
686 |
+
" <tr>\n",
|
687 |
+
" <th>5192</th>\n",
|
688 |
+
" <td>0.148209</td>\n",
|
689 |
+
" <td>0.030643</td>\n",
|
690 |
+
" <td>0.919165</td>\n",
|
691 |
+
" <td>0.255169</td>\n",
|
692 |
+
" <td>0.853721</td>\n",
|
693 |
+
" <td>0.980877</td>\n",
|
694 |
+
" <td>0.030656</td>\n",
|
695 |
+
" <td>9788172235222</td>\n",
|
696 |
+
" </tr>\n",
|
697 |
+
" <tr>\n",
|
698 |
+
" <th>5193</th>\n",
|
699 |
+
" <td>0.064134</td>\n",
|
700 |
+
" <td>0.114383</td>\n",
|
701 |
+
" <td>0.051363</td>\n",
|
702 |
+
" <td>0.400263</td>\n",
|
703 |
+
" <td>0.883199</td>\n",
|
704 |
+
" <td>0.111690</td>\n",
|
705 |
+
" <td>0.227765</td>\n",
|
706 |
+
" <td>9788173031014</td>\n",
|
707 |
+
" </tr>\n",
|
708 |
+
" <tr>\n",
|
709 |
+
" <th>5194</th>\n",
|
710 |
+
" <td>0.009997</td>\n",
|
711 |
+
" <td>0.009929</td>\n",
|
712 |
+
" <td>0.339218</td>\n",
|
713 |
+
" <td>0.947779</td>\n",
|
714 |
+
" <td>0.375755</td>\n",
|
715 |
+
" <td>0.066685</td>\n",
|
716 |
+
" <td>0.057625</td>\n",
|
717 |
+
" <td>9788179921623</td>\n",
|
718 |
+
" </tr>\n",
|
719 |
+
" <tr>\n",
|
720 |
+
" <th>5195</th>\n",
|
721 |
+
" <td>0.064134</td>\n",
|
722 |
+
" <td>0.104007</td>\n",
|
723 |
+
" <td>0.459269</td>\n",
|
724 |
+
" <td>0.759456</td>\n",
|
725 |
+
" <td>0.951104</td>\n",
|
726 |
+
" <td>0.368111</td>\n",
|
727 |
+
" <td>0.078766</td>\n",
|
728 |
+
" <td>9788185300535</td>\n",
|
729 |
+
" </tr>\n",
|
730 |
+
" <tr>\n",
|
731 |
+
" <th>5196</th>\n",
|
732 |
+
" <td>0.064134</td>\n",
|
733 |
+
" <td>0.104007</td>\n",
|
734 |
+
" <td>0.051363</td>\n",
|
735 |
+
" <td>0.958549</td>\n",
|
736 |
+
" <td>0.915193</td>\n",
|
737 |
+
" <td>0.111690</td>\n",
|
738 |
+
" <td>0.078766</td>\n",
|
739 |
+
" <td>9789027712059</td>\n",
|
740 |
+
" </tr>\n",
|
741 |
+
" </tbody>\n",
|
742 |
+
"</table>\n",
|
743 |
+
"<p>5197 rows × 8 columns</p>\n",
|
744 |
+
"</div>"
|
745 |
+
],
|
746 |
+
"text/plain": [
|
747 |
+
" anger disgust fear joy sadness surprise neutral \\\n",
|
748 |
+
"0 0.064134 0.273591 0.928168 0.932797 0.646217 0.967158 0.729603 \n",
|
749 |
+
"1 0.612619 0.348285 0.942528 0.704421 0.887939 0.111690 0.252545 \n",
|
750 |
+
"2 0.064134 0.104007 0.972321 0.767236 0.549477 0.111690 0.078766 \n",
|
751 |
+
"3 0.351483 0.150722 0.360707 0.251881 0.732685 0.111690 0.078766 \n",
|
752 |
+
"4 0.081412 0.184495 0.095043 0.040564 0.884389 0.475881 0.078766 \n",
|
753 |
+
"... ... ... ... ... ... ... ... \n",
|
754 |
+
"5192 0.148209 0.030643 0.919165 0.255169 0.853721 0.980877 0.030656 \n",
|
755 |
+
"5193 0.064134 0.114383 0.051363 0.400263 0.883199 0.111690 0.227765 \n",
|
756 |
+
"5194 0.009997 0.009929 0.339218 0.947779 0.375755 0.066685 0.057625 \n",
|
757 |
+
"5195 0.064134 0.104007 0.459269 0.759456 0.951104 0.368111 0.078766 \n",
|
758 |
+
"5196 0.064134 0.104007 0.051363 0.958549 0.915193 0.111690 0.078766 \n",
|
759 |
+
"\n",
|
760 |
+
" isbn13 \n",
|
761 |
+
"0 9780002005883 \n",
|
762 |
+
"1 9780002261982 \n",
|
763 |
+
"2 9780006178736 \n",
|
764 |
+
"3 9780006280897 \n",
|
765 |
+
"4 9780006280934 \n",
|
766 |
+
"... ... \n",
|
767 |
+
"5192 9788172235222 \n",
|
768 |
+
"5193 9788173031014 \n",
|
769 |
+
"5194 9788179921623 \n",
|
770 |
+
"5195 9788185300535 \n",
|
771 |
+
"5196 9789027712059 \n",
|
772 |
+
"\n",
|
773 |
+
"[5197 rows x 8 columns]"
|
774 |
+
]
|
775 |
+
},
|
776 |
+
"execution_count": 24,
|
777 |
+
"metadata": {},
|
778 |
+
"output_type": "execute_result"
|
779 |
+
}
|
780 |
+
],
|
781 |
+
"source": [
|
782 |
+
"emotions_df"
|
783 |
+
]
|
784 |
+
},
|
785 |
+
{
|
786 |
+
"cell_type": "code",
|
787 |
+
"execution_count": 25,
|
788 |
+
"id": "93f5ef26",
|
789 |
+
"metadata": {},
|
790 |
+
"outputs": [],
|
791 |
+
"source": [
|
792 |
+
"books = pd.merge(books, emotions_df, on = \"isbn13\")"
|
793 |
+
]
|
794 |
+
},
|
795 |
+
{
|
796 |
+
"cell_type": "code",
|
797 |
+
"execution_count": 26,
|
798 |
+
"id": "88e9a111",
|
799 |
+
"metadata": {},
|
800 |
+
"outputs": [
|
801 |
+
{
|
802 |
+
"data": {
|
803 |
+
"text/html": [
|
804 |
+
"<div>\n",
|
805 |
+
"<style scoped>\n",
|
806 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
807 |
+
" vertical-align: middle;\n",
|
808 |
+
" }\n",
|
809 |
+
"\n",
|
810 |
+
" .dataframe tbody tr th {\n",
|
811 |
+
" vertical-align: top;\n",
|
812 |
+
" }\n",
|
813 |
+
"\n",
|
814 |
+
" .dataframe thead th {\n",
|
815 |
+
" text-align: right;\n",
|
816 |
+
" }\n",
|
817 |
+
"</style>\n",
|
818 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
819 |
+
" <thead>\n",
|
820 |
+
" <tr style=\"text-align: right;\">\n",
|
821 |
+
" <th></th>\n",
|
822 |
+
" <th>isbn13</th>\n",
|
823 |
+
" <th>isbn10</th>\n",
|
824 |
+
" <th>title</th>\n",
|
825 |
+
" <th>authors</th>\n",
|
826 |
+
" <th>categories</th>\n",
|
827 |
+
" <th>thumbnail</th>\n",
|
828 |
+
" <th>description</th>\n",
|
829 |
+
" <th>published_year</th>\n",
|
830 |
+
" <th>average_rating</th>\n",
|
831 |
+
" <th>num_pages</th>\n",
|
832 |
+
" <th>...</th>\n",
|
833 |
+
" <th>title_and_subtitle</th>\n",
|
834 |
+
" <th>tagged_description</th>\n",
|
835 |
+
" <th>simple_categories</th>\n",
|
836 |
+
" <th>anger</th>\n",
|
837 |
+
" <th>disgust</th>\n",
|
838 |
+
" <th>fear</th>\n",
|
839 |
+
" <th>joy</th>\n",
|
840 |
+
" <th>sadness</th>\n",
|
841 |
+
" <th>surprise</th>\n",
|
842 |
+
" <th>neutral</th>\n",
|
843 |
+
" </tr>\n",
|
844 |
+
" </thead>\n",
|
845 |
+
" <tbody>\n",
|
846 |
+
" <tr>\n",
|
847 |
+
" <th>0</th>\n",
|
848 |
+
" <td>9780002005883</td>\n",
|
849 |
+
" <td>0002005883</td>\n",
|
850 |
+
" <td>Gilead</td>\n",
|
851 |
+
" <td>Marilynne Robinson</td>\n",
|
852 |
+
" <td>Fiction</td>\n",
|
853 |
+
" <td>http://books.google.com/books/content?id=KQZCP...</td>\n",
|
854 |
+
" <td>A NOVEL THAT READERS and critics have been eag...</td>\n",
|
855 |
+
" <td>2004.0</td>\n",
|
856 |
+
" <td>3.85</td>\n",
|
857 |
+
" <td>247.0</td>\n",
|
858 |
+
" <td>...</td>\n",
|
859 |
+
" <td>Gilead</td>\n",
|
860 |
+
" <td>9780002005883 A NOVEL THAT READERS and critics...</td>\n",
|
861 |
+
" <td>Fiction</td>\n",
|
862 |
+
" <td>0.064134</td>\n",
|
863 |
+
" <td>0.273591</td>\n",
|
864 |
+
" <td>0.928168</td>\n",
|
865 |
+
" <td>0.932797</td>\n",
|
866 |
+
" <td>0.646217</td>\n",
|
867 |
+
" <td>0.967158</td>\n",
|
868 |
+
" <td>0.729603</td>\n",
|
869 |
+
" </tr>\n",
|
870 |
+
" <tr>\n",
|
871 |
+
" <th>1</th>\n",
|
872 |
+
" <td>9780002261982</td>\n",
|
873 |
+
" <td>0002261987</td>\n",
|
874 |
+
" <td>Spider's Web</td>\n",
|
875 |
+
" <td>Charles Osborne;Agatha Christie</td>\n",
|
876 |
+
" <td>Detective and mystery stories</td>\n",
|
877 |
+
" <td>http://books.google.com/books/content?id=gA5GP...</td>\n",
|
878 |
+
" <td>A new 'Christie for Christmas' -- a full-lengt...</td>\n",
|
879 |
+
" <td>2000.0</td>\n",
|
880 |
+
" <td>3.83</td>\n",
|
881 |
+
" <td>241.0</td>\n",
|
882 |
+
" <td>...</td>\n",
|
883 |
+
" <td>Spider's Web: A Novel</td>\n",
|
884 |
+
" <td>9780002261982 A new 'Christie for Christmas' -...</td>\n",
|
885 |
+
" <td>Fiction</td>\n",
|
886 |
+
" <td>0.612619</td>\n",
|
887 |
+
" <td>0.348285</td>\n",
|
888 |
+
" <td>0.942528</td>\n",
|
889 |
+
" <td>0.704421</td>\n",
|
890 |
+
" <td>0.887939</td>\n",
|
891 |
+
" <td>0.111690</td>\n",
|
892 |
+
" <td>0.252545</td>\n",
|
893 |
+
" </tr>\n",
|
894 |
+
" <tr>\n",
|
895 |
+
" <th>2</th>\n",
|
896 |
+
" <td>9780006178736</td>\n",
|
897 |
+
" <td>0006178731</td>\n",
|
898 |
+
" <td>Rage of angels</td>\n",
|
899 |
+
" <td>Sidney Sheldon</td>\n",
|
900 |
+
" <td>Fiction</td>\n",
|
901 |
+
" <td>http://books.google.com/books/content?id=FKo2T...</td>\n",
|
902 |
+
" <td>A memorable, mesmerizing heroine Jennifer -- b...</td>\n",
|
903 |
+
" <td>1993.0</td>\n",
|
904 |
+
" <td>3.93</td>\n",
|
905 |
+
" <td>512.0</td>\n",
|
906 |
+
" <td>...</td>\n",
|
907 |
+
" <td>Rage of angels</td>\n",
|
908 |
+
" <td>9780006178736 A memorable, mesmerizing heroine...</td>\n",
|
909 |
+
" <td>Fiction</td>\n",
|
910 |
+
" <td>0.064134</td>\n",
|
911 |
+
" <td>0.104007</td>\n",
|
912 |
+
" <td>0.972321</td>\n",
|
913 |
+
" <td>0.767236</td>\n",
|
914 |
+
" <td>0.549477</td>\n",
|
915 |
+
" <td>0.111690</td>\n",
|
916 |
+
" <td>0.078766</td>\n",
|
917 |
+
" </tr>\n",
|
918 |
+
" <tr>\n",
|
919 |
+
" <th>3</th>\n",
|
920 |
+
" <td>9780006280897</td>\n",
|
921 |
+
" <td>0006280897</td>\n",
|
922 |
+
" <td>The Four Loves</td>\n",
|
923 |
+
" <td>Clive Staples Lewis</td>\n",
|
924 |
+
" <td>Christian life</td>\n",
|
925 |
+
" <td>http://books.google.com/books/content?id=XhQ5X...</td>\n",
|
926 |
+
" <td>Lewis' work on the nature of love divides love...</td>\n",
|
927 |
+
" <td>2002.0</td>\n",
|
928 |
+
" <td>4.15</td>\n",
|
929 |
+
" <td>170.0</td>\n",
|
930 |
+
" <td>...</td>\n",
|
931 |
+
" <td>The Four Loves</td>\n",
|
932 |
+
" <td>9780006280897 Lewis' work on the nature of lov...</td>\n",
|
933 |
+
" <td>Nonfiction</td>\n",
|
934 |
+
" <td>0.351483</td>\n",
|
935 |
+
" <td>0.150722</td>\n",
|
936 |
+
" <td>0.360707</td>\n",
|
937 |
+
" <td>0.251881</td>\n",
|
938 |
+
" <td>0.732685</td>\n",
|
939 |
+
" <td>0.111690</td>\n",
|
940 |
+
" <td>0.078766</td>\n",
|
941 |
+
" </tr>\n",
|
942 |
+
" <tr>\n",
|
943 |
+
" <th>4</th>\n",
|
944 |
+
" <td>9780006280934</td>\n",
|
945 |
+
" <td>0006280935</td>\n",
|
946 |
+
" <td>The Problem of Pain</td>\n",
|
947 |
+
" <td>Clive Staples Lewis</td>\n",
|
948 |
+
" <td>Christian life</td>\n",
|
949 |
+
" <td>http://books.google.com/books/content?id=Kk-uV...</td>\n",
|
950 |
+
" <td>\"In The Problem of Pain, C.S. Lewis, one of th...</td>\n",
|
951 |
+
" <td>2002.0</td>\n",
|
952 |
+
" <td>4.09</td>\n",
|
953 |
+
" <td>176.0</td>\n",
|
954 |
+
" <td>...</td>\n",
|
955 |
+
" <td>The Problem of Pain</td>\n",
|
956 |
+
" <td>9780006280934 \"In The Problem of Pain, C.S. Le...</td>\n",
|
957 |
+
" <td>Nonfiction</td>\n",
|
958 |
+
" <td>0.081412</td>\n",
|
959 |
+
" <td>0.184495</td>\n",
|
960 |
+
" <td>0.095043</td>\n",
|
961 |
+
" <td>0.040564</td>\n",
|
962 |
+
" <td>0.884389</td>\n",
|
963 |
+
" <td>0.475881</td>\n",
|
964 |
+
" <td>0.078766</td>\n",
|
965 |
+
" </tr>\n",
|
966 |
+
" <tr>\n",
|
967 |
+
" <th>...</th>\n",
|
968 |
+
" <td>...</td>\n",
|
969 |
+
" <td>...</td>\n",
|
970 |
+
" <td>...</td>\n",
|
971 |
+
" <td>...</td>\n",
|
972 |
+
" <td>...</td>\n",
|
973 |
+
" <td>...</td>\n",
|
974 |
+
" <td>...</td>\n",
|
975 |
+
" <td>...</td>\n",
|
976 |
+
" <td>...</td>\n",
|
977 |
+
" <td>...</td>\n",
|
978 |
+
" <td>...</td>\n",
|
979 |
+
" <td>...</td>\n",
|
980 |
+
" <td>...</td>\n",
|
981 |
+
" <td>...</td>\n",
|
982 |
+
" <td>...</td>\n",
|
983 |
+
" <td>...</td>\n",
|
984 |
+
" <td>...</td>\n",
|
985 |
+
" <td>...</td>\n",
|
986 |
+
" <td>...</td>\n",
|
987 |
+
" <td>...</td>\n",
|
988 |
+
" <td>...</td>\n",
|
989 |
+
" </tr>\n",
|
990 |
+
" <tr>\n",
|
991 |
+
" <th>5192</th>\n",
|
992 |
+
" <td>9788172235222</td>\n",
|
993 |
+
" <td>8172235224</td>\n",
|
994 |
+
" <td>Mistaken Identity</td>\n",
|
995 |
+
" <td>Nayantara Sahgal</td>\n",
|
996 |
+
" <td>Indic fiction (English)</td>\n",
|
997 |
+
" <td>http://books.google.com/books/content?id=q-tKP...</td>\n",
|
998 |
+
" <td>On A Train Journey Home To North India After L...</td>\n",
|
999 |
+
" <td>2003.0</td>\n",
|
1000 |
+
" <td>2.93</td>\n",
|
1001 |
+
" <td>324.0</td>\n",
|
1002 |
+
" <td>...</td>\n",
|
1003 |
+
" <td>Mistaken Identity</td>\n",
|
1004 |
+
" <td>9788172235222 On A Train Journey Home To North...</td>\n",
|
1005 |
+
" <td>Fiction</td>\n",
|
1006 |
+
" <td>0.148209</td>\n",
|
1007 |
+
" <td>0.030643</td>\n",
|
1008 |
+
" <td>0.919165</td>\n",
|
1009 |
+
" <td>0.255169</td>\n",
|
1010 |
+
" <td>0.853721</td>\n",
|
1011 |
+
" <td>0.980877</td>\n",
|
1012 |
+
" <td>0.030656</td>\n",
|
1013 |
+
" </tr>\n",
|
1014 |
+
" <tr>\n",
|
1015 |
+
" <th>5193</th>\n",
|
1016 |
+
" <td>9788173031014</td>\n",
|
1017 |
+
" <td>8173031010</td>\n",
|
1018 |
+
" <td>Journey to the East</td>\n",
|
1019 |
+
" <td>Hermann Hesse</td>\n",
|
1020 |
+
" <td>Adventure stories</td>\n",
|
1021 |
+
" <td>http://books.google.com/books/content?id=rq6JP...</td>\n",
|
1022 |
+
" <td>This book tells the tale of a man who goes on ...</td>\n",
|
1023 |
+
" <td>2002.0</td>\n",
|
1024 |
+
" <td>3.70</td>\n",
|
1025 |
+
" <td>175.0</td>\n",
|
1026 |
+
" <td>...</td>\n",
|
1027 |
+
" <td>Journey to the East</td>\n",
|
1028 |
+
" <td>9788173031014 This book tells the tale of a ma...</td>\n",
|
1029 |
+
" <td>Nonfiction</td>\n",
|
1030 |
+
" <td>0.064134</td>\n",
|
1031 |
+
" <td>0.114383</td>\n",
|
1032 |
+
" <td>0.051363</td>\n",
|
1033 |
+
" <td>0.400263</td>\n",
|
1034 |
+
" <td>0.883199</td>\n",
|
1035 |
+
" <td>0.111690</td>\n",
|
1036 |
+
" <td>0.227765</td>\n",
|
1037 |
+
" </tr>\n",
|
1038 |
+
" <tr>\n",
|
1039 |
+
" <th>5194</th>\n",
|
1040 |
+
" <td>9788179921623</td>\n",
|
1041 |
+
" <td>817992162X</td>\n",
|
1042 |
+
" <td>The Monk Who Sold His Ferrari: A Fable About F...</td>\n",
|
1043 |
+
" <td>Robin Sharma</td>\n",
|
1044 |
+
" <td>Health & Fitness</td>\n",
|
1045 |
+
" <td>http://books.google.com/books/content?id=c_7mf...</td>\n",
|
1046 |
+
" <td>Wisdom to Create a Life of Passion, Purpose, a...</td>\n",
|
1047 |
+
" <td>2003.0</td>\n",
|
1048 |
+
" <td>3.82</td>\n",
|
1049 |
+
" <td>198.0</td>\n",
|
1050 |
+
" <td>...</td>\n",
|
1051 |
+
" <td>The Monk Who Sold His Ferrari: A Fable About F...</td>\n",
|
1052 |
+
" <td>9788179921623 Wisdom to Create a Life of Passi...</td>\n",
|
1053 |
+
" <td>Fiction</td>\n",
|
1054 |
+
" <td>0.009997</td>\n",
|
1055 |
+
" <td>0.009929</td>\n",
|
1056 |
+
" <td>0.339218</td>\n",
|
1057 |
+
" <td>0.947779</td>\n",
|
1058 |
+
" <td>0.375755</td>\n",
|
1059 |
+
" <td>0.066685</td>\n",
|
1060 |
+
" <td>0.057625</td>\n",
|
1061 |
+
" </tr>\n",
|
1062 |
+
" <tr>\n",
|
1063 |
+
" <th>5195</th>\n",
|
1064 |
+
" <td>9788185300535</td>\n",
|
1065 |
+
" <td>8185300534</td>\n",
|
1066 |
+
" <td>I Am that</td>\n",
|
1067 |
+
" <td>Sri Nisargadatta Maharaj;Sudhakar S. Dikshit</td>\n",
|
1068 |
+
" <td>Philosophy</td>\n",
|
1069 |
+
" <td>http://books.google.com/books/content?id=Fv_JP...</td>\n",
|
1070 |
+
" <td>This collection of the timeless teachings of o...</td>\n",
|
1071 |
+
" <td>1999.0</td>\n",
|
1072 |
+
" <td>4.51</td>\n",
|
1073 |
+
" <td>531.0</td>\n",
|
1074 |
+
" <td>...</td>\n",
|
1075 |
+
" <td>I Am that: Talks with Sri Nisargadatta Maharaj</td>\n",
|
1076 |
+
" <td>9788185300535 This collection of the timeless ...</td>\n",
|
1077 |
+
" <td>Nonfiction</td>\n",
|
1078 |
+
" <td>0.064134</td>\n",
|
1079 |
+
" <td>0.104007</td>\n",
|
1080 |
+
" <td>0.459269</td>\n",
|
1081 |
+
" <td>0.759456</td>\n",
|
1082 |
+
" <td>0.951104</td>\n",
|
1083 |
+
" <td>0.368111</td>\n",
|
1084 |
+
" <td>0.078766</td>\n",
|
1085 |
+
" </tr>\n",
|
1086 |
+
" <tr>\n",
|
1087 |
+
" <th>5196</th>\n",
|
1088 |
+
" <td>9789027712059</td>\n",
|
1089 |
+
" <td>9027712050</td>\n",
|
1090 |
+
" <td>The Berlin Phenomenology</td>\n",
|
1091 |
+
" <td>Georg Wilhelm Friedrich Hegel</td>\n",
|
1092 |
+
" <td>History</td>\n",
|
1093 |
+
" <td>http://books.google.com/books/content?id=Vy7Sk...</td>\n",
|
1094 |
+
" <td>Since the three volume edition ofHegel's Philo...</td>\n",
|
1095 |
+
" <td>1981.0</td>\n",
|
1096 |
+
" <td>0.00</td>\n",
|
1097 |
+
" <td>210.0</td>\n",
|
1098 |
+
" <td>...</td>\n",
|
1099 |
+
" <td>The Berlin Phenomenology</td>\n",
|
1100 |
+
" <td>9789027712059 Since the three volume edition o...</td>\n",
|
1101 |
+
" <td>Nonfiction</td>\n",
|
1102 |
+
" <td>0.064134</td>\n",
|
1103 |
+
" <td>0.104007</td>\n",
|
1104 |
+
" <td>0.051363</td>\n",
|
1105 |
+
" <td>0.958549</td>\n",
|
1106 |
+
" <td>0.915193</td>\n",
|
1107 |
+
" <td>0.111690</td>\n",
|
1108 |
+
" <td>0.078766</td>\n",
|
1109 |
+
" </tr>\n",
|
1110 |
+
" </tbody>\n",
|
1111 |
+
"</table>\n",
|
1112 |
+
"<p>5197 rows × 22 columns</p>\n",
|
1113 |
+
"</div>"
|
1114 |
+
],
|
1115 |
+
"text/plain": [
|
1116 |
+
" isbn13 isbn10 \\\n",
|
1117 |
+
"0 9780002005883 0002005883 \n",
|
1118 |
+
"1 9780002261982 0002261987 \n",
|
1119 |
+
"2 9780006178736 0006178731 \n",
|
1120 |
+
"3 9780006280897 0006280897 \n",
|
1121 |
+
"4 9780006280934 0006280935 \n",
|
1122 |
+
"... ... ... \n",
|
1123 |
+
"5192 9788172235222 8172235224 \n",
|
1124 |
+
"5193 9788173031014 8173031010 \n",
|
1125 |
+
"5194 9788179921623 817992162X \n",
|
1126 |
+
"5195 9788185300535 8185300534 \n",
|
1127 |
+
"5196 9789027712059 9027712050 \n",
|
1128 |
+
"\n",
|
1129 |
+
" title \\\n",
|
1130 |
+
"0 Gilead \n",
|
1131 |
+
"1 Spider's Web \n",
|
1132 |
+
"2 Rage of angels \n",
|
1133 |
+
"3 The Four Loves \n",
|
1134 |
+
"4 The Problem of Pain \n",
|
1135 |
+
"... ... \n",
|
1136 |
+
"5192 Mistaken Identity \n",
|
1137 |
+
"5193 Journey to the East \n",
|
1138 |
+
"5194 The Monk Who Sold His Ferrari: A Fable About F... \n",
|
1139 |
+
"5195 I Am that \n",
|
1140 |
+
"5196 The Berlin Phenomenology \n",
|
1141 |
+
"\n",
|
1142 |
+
" authors \\\n",
|
1143 |
+
"0 Marilynne Robinson \n",
|
1144 |
+
"1 Charles Osborne;Agatha Christie \n",
|
1145 |
+
"2 Sidney Sheldon \n",
|
1146 |
+
"3 Clive Staples Lewis \n",
|
1147 |
+
"4 Clive Staples Lewis \n",
|
1148 |
+
"... ... \n",
|
1149 |
+
"5192 Nayantara Sahgal \n",
|
1150 |
+
"5193 Hermann Hesse \n",
|
1151 |
+
"5194 Robin Sharma \n",
|
1152 |
+
"5195 Sri Nisargadatta Maharaj;Sudhakar S. Dikshit \n",
|
1153 |
+
"5196 Georg Wilhelm Friedrich Hegel \n",
|
1154 |
+
"\n",
|
1155 |
+
" categories \\\n",
|
1156 |
+
"0 Fiction \n",
|
1157 |
+
"1 Detective and mystery stories \n",
|
1158 |
+
"2 Fiction \n",
|
1159 |
+
"3 Christian life \n",
|
1160 |
+
"4 Christian life \n",
|
1161 |
+
"... ... \n",
|
1162 |
+
"5192 Indic fiction (English) \n",
|
1163 |
+
"5193 Adventure stories \n",
|
1164 |
+
"5194 Health & Fitness \n",
|
1165 |
+
"5195 Philosophy \n",
|
1166 |
+
"5196 History \n",
|
1167 |
+
"\n",
|
1168 |
+
" thumbnail \\\n",
|
1169 |
+
"0 http://books.google.com/books/content?id=KQZCP... \n",
|
1170 |
+
"1 http://books.google.com/books/content?id=gA5GP... \n",
|
1171 |
+
"2 http://books.google.com/books/content?id=FKo2T... \n",
|
1172 |
+
"3 http://books.google.com/books/content?id=XhQ5X... \n",
|
1173 |
+
"4 http://books.google.com/books/content?id=Kk-uV... \n",
|
1174 |
+
"... ... \n",
|
1175 |
+
"5192 http://books.google.com/books/content?id=q-tKP... \n",
|
1176 |
+
"5193 http://books.google.com/books/content?id=rq6JP... \n",
|
1177 |
+
"5194 http://books.google.com/books/content?id=c_7mf... \n",
|
1178 |
+
"5195 http://books.google.com/books/content?id=Fv_JP... \n",
|
1179 |
+
"5196 http://books.google.com/books/content?id=Vy7Sk... \n",
|
1180 |
+
"\n",
|
1181 |
+
" description published_year \\\n",
|
1182 |
+
"0 A NOVEL THAT READERS and critics have been eag... 2004.0 \n",
|
1183 |
+
"1 A new 'Christie for Christmas' -- a full-lengt... 2000.0 \n",
|
1184 |
+
"2 A memorable, mesmerizing heroine Jennifer -- b... 1993.0 \n",
|
1185 |
+
"3 Lewis' work on the nature of love divides love... 2002.0 \n",
|
1186 |
+
"4 \"In The Problem of Pain, C.S. Lewis, one of th... 2002.0 \n",
|
1187 |
+
"... ... ... \n",
|
1188 |
+
"5192 On A Train Journey Home To North India After L... 2003.0 \n",
|
1189 |
+
"5193 This book tells the tale of a man who goes on ... 2002.0 \n",
|
1190 |
+
"5194 Wisdom to Create a Life of Passion, Purpose, a... 2003.0 \n",
|
1191 |
+
"5195 This collection of the timeless teachings of o... 1999.0 \n",
|
1192 |
+
"5196 Since the three volume edition ofHegel's Philo... 1981.0 \n",
|
1193 |
+
"\n",
|
1194 |
+
" average_rating num_pages ... \\\n",
|
1195 |
+
"0 3.85 247.0 ... \n",
|
1196 |
+
"1 3.83 241.0 ... \n",
|
1197 |
+
"2 3.93 512.0 ... \n",
|
1198 |
+
"3 4.15 170.0 ... \n",
|
1199 |
+
"4 4.09 176.0 ... \n",
|
1200 |
+
"... ... ... ... \n",
|
1201 |
+
"5192 2.93 324.0 ... \n",
|
1202 |
+
"5193 3.70 175.0 ... \n",
|
1203 |
+
"5194 3.82 198.0 ... \n",
|
1204 |
+
"5195 4.51 531.0 ... \n",
|
1205 |
+
"5196 0.00 210.0 ... \n",
|
1206 |
+
"\n",
|
1207 |
+
" title_and_subtitle \\\n",
|
1208 |
+
"0 Gilead \n",
|
1209 |
+
"1 Spider's Web: A Novel \n",
|
1210 |
+
"2 Rage of angels \n",
|
1211 |
+
"3 The Four Loves \n",
|
1212 |
+
"4 The Problem of Pain \n",
|
1213 |
+
"... ... \n",
|
1214 |
+
"5192 Mistaken Identity \n",
|
1215 |
+
"5193 Journey to the East \n",
|
1216 |
+
"5194 The Monk Who Sold His Ferrari: A Fable About F... \n",
|
1217 |
+
"5195 I Am that: Talks with Sri Nisargadatta Maharaj \n",
|
1218 |
+
"5196 The Berlin Phenomenology \n",
|
1219 |
+
"\n",
|
1220 |
+
" tagged_description simple_categories \\\n",
|
1221 |
+
"0 9780002005883 A NOVEL THAT READERS and critics... Fiction \n",
|
1222 |
+
"1 9780002261982 A new 'Christie for Christmas' -... Fiction \n",
|
1223 |
+
"2 9780006178736 A memorable, mesmerizing heroine... Fiction \n",
|
1224 |
+
"3 9780006280897 Lewis' work on the nature of lov... Nonfiction \n",
|
1225 |
+
"4 9780006280934 \"In The Problem of Pain, C.S. Le... Nonfiction \n",
|
1226 |
+
"... ... ... \n",
|
1227 |
+
"5192 9788172235222 On A Train Journey Home To North... Fiction \n",
|
1228 |
+
"5193 9788173031014 This book tells the tale of a ma... Nonfiction \n",
|
1229 |
+
"5194 9788179921623 Wisdom to Create a Life of Passi... Fiction \n",
|
1230 |
+
"5195 9788185300535 This collection of the timeless ... Nonfiction \n",
|
1231 |
+
"5196 9789027712059 Since the three volume edition o... Nonfiction \n",
|
1232 |
+
"\n",
|
1233 |
+
" anger disgust fear joy sadness surprise neutral \n",
|
1234 |
+
"0 0.064134 0.273591 0.928168 0.932797 0.646217 0.967158 0.729603 \n",
|
1235 |
+
"1 0.612619 0.348285 0.942528 0.704421 0.887939 0.111690 0.252545 \n",
|
1236 |
+
"2 0.064134 0.104007 0.972321 0.767236 0.549477 0.111690 0.078766 \n",
|
1237 |
+
"3 0.351483 0.150722 0.360707 0.251881 0.732685 0.111690 0.078766 \n",
|
1238 |
+
"4 0.081412 0.184495 0.095043 0.040564 0.884389 0.475881 0.078766 \n",
|
1239 |
+
"... ... ... ... ... ... ... ... \n",
|
1240 |
+
"5192 0.148209 0.030643 0.919165 0.255169 0.853721 0.980877 0.030656 \n",
|
1241 |
+
"5193 0.064134 0.114383 0.051363 0.400263 0.883199 0.111690 0.227765 \n",
|
1242 |
+
"5194 0.009997 0.009929 0.339218 0.947779 0.375755 0.066685 0.057625 \n",
|
1243 |
+
"5195 0.064134 0.104007 0.459269 0.759456 0.951104 0.368111 0.078766 \n",
|
1244 |
+
"5196 0.064134 0.104007 0.051363 0.958549 0.915193 0.111690 0.078766 \n",
|
1245 |
+
"\n",
|
1246 |
+
"[5197 rows x 22 columns]"
|
1247 |
+
]
|
1248 |
+
},
|
1249 |
+
"execution_count": 26,
|
1250 |
+
"metadata": {},
|
1251 |
+
"output_type": "execute_result"
|
1252 |
+
}
|
1253 |
+
],
|
1254 |
+
"source": [
|
1255 |
+
"books"
|
1256 |
+
]
|
1257 |
+
},
|
1258 |
+
{
|
1259 |
+
"cell_type": "code",
|
1260 |
+
"execution_count": 27,
|
1261 |
+
"id": "6e7c5bd9",
|
1262 |
+
"metadata": {},
|
1263 |
+
"outputs": [],
|
1264 |
+
"source": [
|
1265 |
+
"books.to_csv(\"books_with_emotions.csv\", index = False)"
|
1266 |
+
]
|
1267 |
+
}
|
1268 |
+
],
|
1269 |
+
"metadata": {
|
1270 |
+
"kernelspec": {
|
1271 |
+
"display_name": "books_env",
|
1272 |
+
"language": "python",
|
1273 |
+
"name": "python3"
|
1274 |
+
},
|
1275 |
+
"language_info": {
|
1276 |
+
"codemirror_mode": {
|
1277 |
+
"name": "ipython",
|
1278 |
+
"version": 3
|
1279 |
+
},
|
1280 |
+
"file_extension": ".py",
|
1281 |
+
"mimetype": "text/x-python",
|
1282 |
+
"name": "python",
|
1283 |
+
"nbconvert_exporter": "python",
|
1284 |
+
"pygments_lexer": "ipython3",
|
1285 |
+
"version": "3.13.1"
|
1286 |
+
}
|
1287 |
+
},
|
1288 |
+
"nbformat": 4,
|
1289 |
+
"nbformat_minor": 5
|
1290 |
+
}
|
tagged_description.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
text-classification.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
vector-search.ipynb
ADDED
@@ -0,0 +1,954 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"id": "2b931208",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"from langchain_community.document_loaders import TextLoader\n",
|
11 |
+
"from langchain_text_splitters import CharacterTextSplitter\n",
|
12 |
+
"from langchain_chroma import Chroma"
|
13 |
+
]
|
14 |
+
},
|
15 |
+
{
|
16 |
+
"cell_type": "code",
|
17 |
+
"execution_count": 9,
|
18 |
+
"id": "1adaad97",
|
19 |
+
"metadata": {},
|
20 |
+
"outputs": [
|
21 |
+
{
|
22 |
+
"data": {
|
23 |
+
"text/html": [
|
24 |
+
"<div>\n",
|
25 |
+
"<style scoped>\n",
|
26 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
27 |
+
" vertical-align: middle;\n",
|
28 |
+
" }\n",
|
29 |
+
"\n",
|
30 |
+
" .dataframe tbody tr th {\n",
|
31 |
+
" vertical-align: top;\n",
|
32 |
+
" }\n",
|
33 |
+
"\n",
|
34 |
+
" .dataframe thead th {\n",
|
35 |
+
" text-align: right;\n",
|
36 |
+
" }\n",
|
37 |
+
"</style>\n",
|
38 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
39 |
+
" <thead>\n",
|
40 |
+
" <tr style=\"text-align: right;\">\n",
|
41 |
+
" <th></th>\n",
|
42 |
+
" <th>isbn13</th>\n",
|
43 |
+
" <th>isbn10</th>\n",
|
44 |
+
" <th>title</th>\n",
|
45 |
+
" <th>authors</th>\n",
|
46 |
+
" <th>categories</th>\n",
|
47 |
+
" <th>thumbnail</th>\n",
|
48 |
+
" <th>description</th>\n",
|
49 |
+
" <th>published_year</th>\n",
|
50 |
+
" <th>average_rating</th>\n",
|
51 |
+
" <th>num_pages</th>\n",
|
52 |
+
" <th>ratings_count</th>\n",
|
53 |
+
" <th>agg_of_book</th>\n",
|
54 |
+
" <th>title_and_subtitle</th>\n",
|
55 |
+
" <th>tagged_description</th>\n",
|
56 |
+
" </tr>\n",
|
57 |
+
" </thead>\n",
|
58 |
+
" <tbody>\n",
|
59 |
+
" <tr>\n",
|
60 |
+
" <th>0</th>\n",
|
61 |
+
" <td>9780002005883</td>\n",
|
62 |
+
" <td>0002005883</td>\n",
|
63 |
+
" <td>Gilead</td>\n",
|
64 |
+
" <td>Marilynne Robinson</td>\n",
|
65 |
+
" <td>Fiction</td>\n",
|
66 |
+
" <td>http://books.google.com/books/content?id=KQZCP...</td>\n",
|
67 |
+
" <td>A NOVEL THAT READERS and critics have been eag...</td>\n",
|
68 |
+
" <td>2004.0</td>\n",
|
69 |
+
" <td>3.85</td>\n",
|
70 |
+
" <td>247.0</td>\n",
|
71 |
+
" <td>361.0</td>\n",
|
72 |
+
" <td>21.0</td>\n",
|
73 |
+
" <td>Gilead</td>\n",
|
74 |
+
" <td>9780002005883 A NOVEL THAT READERS and critics...</td>\n",
|
75 |
+
" </tr>\n",
|
76 |
+
" <tr>\n",
|
77 |
+
" <th>1</th>\n",
|
78 |
+
" <td>9780002261982</td>\n",
|
79 |
+
" <td>0002261987</td>\n",
|
80 |
+
" <td>Spider's Web</td>\n",
|
81 |
+
" <td>Charles Osborne;Agatha Christie</td>\n",
|
82 |
+
" <td>Detective and mystery stories</td>\n",
|
83 |
+
" <td>http://books.google.com/books/content?id=gA5GP...</td>\n",
|
84 |
+
" <td>A new 'Christie for Christmas' -- a full-lengt...</td>\n",
|
85 |
+
" <td>2000.0</td>\n",
|
86 |
+
" <td>3.83</td>\n",
|
87 |
+
" <td>241.0</td>\n",
|
88 |
+
" <td>5164.0</td>\n",
|
89 |
+
" <td>25.0</td>\n",
|
90 |
+
" <td>Spider's Web: A Novel</td>\n",
|
91 |
+
" <td>9780002261982 A new 'Christie for Christmas' -...</td>\n",
|
92 |
+
" </tr>\n",
|
93 |
+
" <tr>\n",
|
94 |
+
" <th>2</th>\n",
|
95 |
+
" <td>9780006178736</td>\n",
|
96 |
+
" <td>0006178731</td>\n",
|
97 |
+
" <td>Rage of angels</td>\n",
|
98 |
+
" <td>Sidney Sheldon</td>\n",
|
99 |
+
" <td>Fiction</td>\n",
|
100 |
+
" <td>http://books.google.com/books/content?id=FKo2T...</td>\n",
|
101 |
+
" <td>A memorable, mesmerizing heroine Jennifer -- b...</td>\n",
|
102 |
+
" <td>1993.0</td>\n",
|
103 |
+
" <td>3.93</td>\n",
|
104 |
+
" <td>512.0</td>\n",
|
105 |
+
" <td>29532.0</td>\n",
|
106 |
+
" <td>32.0</td>\n",
|
107 |
+
" <td>Rage of angels</td>\n",
|
108 |
+
" <td>9780006178736 A memorable, mesmerizing heroine...</td>\n",
|
109 |
+
" </tr>\n",
|
110 |
+
" <tr>\n",
|
111 |
+
" <th>3</th>\n",
|
112 |
+
" <td>9780006280897</td>\n",
|
113 |
+
" <td>0006280897</td>\n",
|
114 |
+
" <td>The Four Loves</td>\n",
|
115 |
+
" <td>Clive Staples Lewis</td>\n",
|
116 |
+
" <td>Christian life</td>\n",
|
117 |
+
" <td>http://books.google.com/books/content?id=XhQ5X...</td>\n",
|
118 |
+
" <td>Lewis' work on the nature of love divides love...</td>\n",
|
119 |
+
" <td>2002.0</td>\n",
|
120 |
+
" <td>4.15</td>\n",
|
121 |
+
" <td>170.0</td>\n",
|
122 |
+
" <td>33684.0</td>\n",
|
123 |
+
" <td>23.0</td>\n",
|
124 |
+
" <td>The Four Loves</td>\n",
|
125 |
+
" <td>9780006280897 Lewis' work on the nature of lov...</td>\n",
|
126 |
+
" </tr>\n",
|
127 |
+
" <tr>\n",
|
128 |
+
" <th>4</th>\n",
|
129 |
+
" <td>9780006280934</td>\n",
|
130 |
+
" <td>0006280935</td>\n",
|
131 |
+
" <td>The Problem of Pain</td>\n",
|
132 |
+
" <td>Clive Staples Lewis</td>\n",
|
133 |
+
" <td>Christian life</td>\n",
|
134 |
+
" <td>http://books.google.com/books/content?id=Kk-uV...</td>\n",
|
135 |
+
" <td>\"In The Problem of Pain, C.S. Lewis, one of th...</td>\n",
|
136 |
+
" <td>2002.0</td>\n",
|
137 |
+
" <td>4.09</td>\n",
|
138 |
+
" <td>176.0</td>\n",
|
139 |
+
" <td>37569.0</td>\n",
|
140 |
+
" <td>23.0</td>\n",
|
141 |
+
" <td>The Problem of Pain</td>\n",
|
142 |
+
" <td>9780006280934 \"In The Problem of Pain, C.S. Le...</td>\n",
|
143 |
+
" </tr>\n",
|
144 |
+
" <tr>\n",
|
145 |
+
" <th>...</th>\n",
|
146 |
+
" <td>...</td>\n",
|
147 |
+
" <td>...</td>\n",
|
148 |
+
" <td>...</td>\n",
|
149 |
+
" <td>...</td>\n",
|
150 |
+
" <td>...</td>\n",
|
151 |
+
" <td>...</td>\n",
|
152 |
+
" <td>...</td>\n",
|
153 |
+
" <td>...</td>\n",
|
154 |
+
" <td>...</td>\n",
|
155 |
+
" <td>...</td>\n",
|
156 |
+
" <td>...</td>\n",
|
157 |
+
" <td>...</td>\n",
|
158 |
+
" <td>...</td>\n",
|
159 |
+
" <td>...</td>\n",
|
160 |
+
" </tr>\n",
|
161 |
+
" <tr>\n",
|
162 |
+
" <th>5192</th>\n",
|
163 |
+
" <td>9788172235222</td>\n",
|
164 |
+
" <td>8172235224</td>\n",
|
165 |
+
" <td>Mistaken Identity</td>\n",
|
166 |
+
" <td>Nayantara Sahgal</td>\n",
|
167 |
+
" <td>Indic fiction (English)</td>\n",
|
168 |
+
" <td>http://books.google.com/books/content?id=q-tKP...</td>\n",
|
169 |
+
" <td>On A Train Journey Home To North India After L...</td>\n",
|
170 |
+
" <td>2003.0</td>\n",
|
171 |
+
" <td>2.93</td>\n",
|
172 |
+
" <td>324.0</td>\n",
|
173 |
+
" <td>0.0</td>\n",
|
174 |
+
" <td>22.0</td>\n",
|
175 |
+
" <td>Mistaken Identity</td>\n",
|
176 |
+
" <td>9788172235222 On A Train Journey Home To North...</td>\n",
|
177 |
+
" </tr>\n",
|
178 |
+
" <tr>\n",
|
179 |
+
" <th>5193</th>\n",
|
180 |
+
" <td>9788173031014</td>\n",
|
181 |
+
" <td>8173031010</td>\n",
|
182 |
+
" <td>Journey to the East</td>\n",
|
183 |
+
" <td>Hermann Hesse</td>\n",
|
184 |
+
" <td>Adventure stories</td>\n",
|
185 |
+
" <td>http://books.google.com/books/content?id=rq6JP...</td>\n",
|
186 |
+
" <td>This book tells the tale of a man who goes on ...</td>\n",
|
187 |
+
" <td>2002.0</td>\n",
|
188 |
+
" <td>3.70</td>\n",
|
189 |
+
" <td>175.0</td>\n",
|
190 |
+
" <td>24.0</td>\n",
|
191 |
+
" <td>23.0</td>\n",
|
192 |
+
" <td>Journey to the East</td>\n",
|
193 |
+
" <td>9788173031014 This book tells the tale of a ma...</td>\n",
|
194 |
+
" </tr>\n",
|
195 |
+
" <tr>\n",
|
196 |
+
" <th>5194</th>\n",
|
197 |
+
" <td>9788179921623</td>\n",
|
198 |
+
" <td>817992162X</td>\n",
|
199 |
+
" <td>The Monk Who Sold His Ferrari: A Fable About F...</td>\n",
|
200 |
+
" <td>Robin Sharma</td>\n",
|
201 |
+
" <td>Health & Fitness</td>\n",
|
202 |
+
" <td>http://books.google.com/books/content?id=c_7mf...</td>\n",
|
203 |
+
" <td>Wisdom to Create a Life of Passion, Purpose, a...</td>\n",
|
204 |
+
" <td>2003.0</td>\n",
|
205 |
+
" <td>3.82</td>\n",
|
206 |
+
" <td>198.0</td>\n",
|
207 |
+
" <td>1568.0</td>\n",
|
208 |
+
" <td>22.0</td>\n",
|
209 |
+
" <td>The Monk Who Sold His Ferrari: A Fable About F...</td>\n",
|
210 |
+
" <td>9788179921623 Wisdom to Create a Life of Passi...</td>\n",
|
211 |
+
" </tr>\n",
|
212 |
+
" <tr>\n",
|
213 |
+
" <th>5195</th>\n",
|
214 |
+
" <td>9788185300535</td>\n",
|
215 |
+
" <td>8185300534</td>\n",
|
216 |
+
" <td>I Am that</td>\n",
|
217 |
+
" <td>Sri Nisargadatta Maharaj;Sudhakar S. Dikshit</td>\n",
|
218 |
+
" <td>Philosophy</td>\n",
|
219 |
+
" <td>http://books.google.com/books/content?id=Fv_JP...</td>\n",
|
220 |
+
" <td>This collection of the timeless teachings of o...</td>\n",
|
221 |
+
" <td>1999.0</td>\n",
|
222 |
+
" <td>4.51</td>\n",
|
223 |
+
" <td>531.0</td>\n",
|
224 |
+
" <td>104.0</td>\n",
|
225 |
+
" <td>26.0</td>\n",
|
226 |
+
" <td>I Am that: Talks with Sri Nisargadatta Maharaj</td>\n",
|
227 |
+
" <td>9788185300535 This collection of the timeless ...</td>\n",
|
228 |
+
" </tr>\n",
|
229 |
+
" <tr>\n",
|
230 |
+
" <th>5196</th>\n",
|
231 |
+
" <td>9789027712059</td>\n",
|
232 |
+
" <td>9027712050</td>\n",
|
233 |
+
" <td>The Berlin Phenomenology</td>\n",
|
234 |
+
" <td>Georg Wilhelm Friedrich Hegel</td>\n",
|
235 |
+
" <td>History</td>\n",
|
236 |
+
" <td>http://books.google.com/books/content?id=Vy7Sk...</td>\n",
|
237 |
+
" <td>Since the three volume edition ofHegel's Philo...</td>\n",
|
238 |
+
" <td>1981.0</td>\n",
|
239 |
+
" <td>0.00</td>\n",
|
240 |
+
" <td>210.0</td>\n",
|
241 |
+
" <td>0.0</td>\n",
|
242 |
+
" <td>44.0</td>\n",
|
243 |
+
" <td>The Berlin Phenomenology</td>\n",
|
244 |
+
" <td>9789027712059 Since the three volume edition o...</td>\n",
|
245 |
+
" </tr>\n",
|
246 |
+
" </tbody>\n",
|
247 |
+
"</table>\n",
|
248 |
+
"<p>5197 rows × 14 columns</p>\n",
|
249 |
+
"</div>"
|
250 |
+
],
|
251 |
+
"text/plain": [
|
252 |
+
" isbn13 isbn10 \\\n",
|
253 |
+
"0 9780002005883 0002005883 \n",
|
254 |
+
"1 9780002261982 0002261987 \n",
|
255 |
+
"2 9780006178736 0006178731 \n",
|
256 |
+
"3 9780006280897 0006280897 \n",
|
257 |
+
"4 9780006280934 0006280935 \n",
|
258 |
+
"... ... ... \n",
|
259 |
+
"5192 9788172235222 8172235224 \n",
|
260 |
+
"5193 9788173031014 8173031010 \n",
|
261 |
+
"5194 9788179921623 817992162X \n",
|
262 |
+
"5195 9788185300535 8185300534 \n",
|
263 |
+
"5196 9789027712059 9027712050 \n",
|
264 |
+
"\n",
|
265 |
+
" title \\\n",
|
266 |
+
"0 Gilead \n",
|
267 |
+
"1 Spider's Web \n",
|
268 |
+
"2 Rage of angels \n",
|
269 |
+
"3 The Four Loves \n",
|
270 |
+
"4 The Problem of Pain \n",
|
271 |
+
"... ... \n",
|
272 |
+
"5192 Mistaken Identity \n",
|
273 |
+
"5193 Journey to the East \n",
|
274 |
+
"5194 The Monk Who Sold His Ferrari: A Fable About F... \n",
|
275 |
+
"5195 I Am that \n",
|
276 |
+
"5196 The Berlin Phenomenology \n",
|
277 |
+
"\n",
|
278 |
+
" authors \\\n",
|
279 |
+
"0 Marilynne Robinson \n",
|
280 |
+
"1 Charles Osborne;Agatha Christie \n",
|
281 |
+
"2 Sidney Sheldon \n",
|
282 |
+
"3 Clive Staples Lewis \n",
|
283 |
+
"4 Clive Staples Lewis \n",
|
284 |
+
"... ... \n",
|
285 |
+
"5192 Nayantara Sahgal \n",
|
286 |
+
"5193 Hermann Hesse \n",
|
287 |
+
"5194 Robin Sharma \n",
|
288 |
+
"5195 Sri Nisargadatta Maharaj;Sudhakar S. Dikshit \n",
|
289 |
+
"5196 Georg Wilhelm Friedrich Hegel \n",
|
290 |
+
"\n",
|
291 |
+
" categories \\\n",
|
292 |
+
"0 Fiction \n",
|
293 |
+
"1 Detective and mystery stories \n",
|
294 |
+
"2 Fiction \n",
|
295 |
+
"3 Christian life \n",
|
296 |
+
"4 Christian life \n",
|
297 |
+
"... ... \n",
|
298 |
+
"5192 Indic fiction (English) \n",
|
299 |
+
"5193 Adventure stories \n",
|
300 |
+
"5194 Health & Fitness \n",
|
301 |
+
"5195 Philosophy \n",
|
302 |
+
"5196 History \n",
|
303 |
+
"\n",
|
304 |
+
" thumbnail \\\n",
|
305 |
+
"0 http://books.google.com/books/content?id=KQZCP... \n",
|
306 |
+
"1 http://books.google.com/books/content?id=gA5GP... \n",
|
307 |
+
"2 http://books.google.com/books/content?id=FKo2T... \n",
|
308 |
+
"3 http://books.google.com/books/content?id=XhQ5X... \n",
|
309 |
+
"4 http://books.google.com/books/content?id=Kk-uV... \n",
|
310 |
+
"... ... \n",
|
311 |
+
"5192 http://books.google.com/books/content?id=q-tKP... \n",
|
312 |
+
"5193 http://books.google.com/books/content?id=rq6JP... \n",
|
313 |
+
"5194 http://books.google.com/books/content?id=c_7mf... \n",
|
314 |
+
"5195 http://books.google.com/books/content?id=Fv_JP... \n",
|
315 |
+
"5196 http://books.google.com/books/content?id=Vy7Sk... \n",
|
316 |
+
"\n",
|
317 |
+
" description published_year \\\n",
|
318 |
+
"0 A NOVEL THAT READERS and critics have been eag... 2004.0 \n",
|
319 |
+
"1 A new 'Christie for Christmas' -- a full-lengt... 2000.0 \n",
|
320 |
+
"2 A memorable, mesmerizing heroine Jennifer -- b... 1993.0 \n",
|
321 |
+
"3 Lewis' work on the nature of love divides love... 2002.0 \n",
|
322 |
+
"4 \"In The Problem of Pain, C.S. Lewis, one of th... 2002.0 \n",
|
323 |
+
"... ... ... \n",
|
324 |
+
"5192 On A Train Journey Home To North India After L... 2003.0 \n",
|
325 |
+
"5193 This book tells the tale of a man who goes on ... 2002.0 \n",
|
326 |
+
"5194 Wisdom to Create a Life of Passion, Purpose, a... 2003.0 \n",
|
327 |
+
"5195 This collection of the timeless teachings of o... 1999.0 \n",
|
328 |
+
"5196 Since the three volume edition ofHegel's Philo... 1981.0 \n",
|
329 |
+
"\n",
|
330 |
+
" average_rating num_pages ratings_count agg_of_book \\\n",
|
331 |
+
"0 3.85 247.0 361.0 21.0 \n",
|
332 |
+
"1 3.83 241.0 5164.0 25.0 \n",
|
333 |
+
"2 3.93 512.0 29532.0 32.0 \n",
|
334 |
+
"3 4.15 170.0 33684.0 23.0 \n",
|
335 |
+
"4 4.09 176.0 37569.0 23.0 \n",
|
336 |
+
"... ... ... ... ... \n",
|
337 |
+
"5192 2.93 324.0 0.0 22.0 \n",
|
338 |
+
"5193 3.70 175.0 24.0 23.0 \n",
|
339 |
+
"5194 3.82 198.0 1568.0 22.0 \n",
|
340 |
+
"5195 4.51 531.0 104.0 26.0 \n",
|
341 |
+
"5196 0.00 210.0 0.0 44.0 \n",
|
342 |
+
"\n",
|
343 |
+
" title_and_subtitle \\\n",
|
344 |
+
"0 Gilead \n",
|
345 |
+
"1 Spider's Web: A Novel \n",
|
346 |
+
"2 Rage of angels \n",
|
347 |
+
"3 The Four Loves \n",
|
348 |
+
"4 The Problem of Pain \n",
|
349 |
+
"... ... \n",
|
350 |
+
"5192 Mistaken Identity \n",
|
351 |
+
"5193 Journey to the East \n",
|
352 |
+
"5194 The Monk Who Sold His Ferrari: A Fable About F... \n",
|
353 |
+
"5195 I Am that: Talks with Sri Nisargadatta Maharaj \n",
|
354 |
+
"5196 The Berlin Phenomenology \n",
|
355 |
+
"\n",
|
356 |
+
" tagged_description \n",
|
357 |
+
"0 9780002005883 A NOVEL THAT READERS and critics... \n",
|
358 |
+
"1 9780002261982 A new 'Christie for Christmas' -... \n",
|
359 |
+
"2 9780006178736 A memorable, mesmerizing heroine... \n",
|
360 |
+
"3 9780006280897 Lewis' work on the nature of lov... \n",
|
361 |
+
"4 9780006280934 \"In The Problem of Pain, C.S. Le... \n",
|
362 |
+
"... ... \n",
|
363 |
+
"5192 9788172235222 On A Train Journey Home To North... \n",
|
364 |
+
"5193 9788173031014 This book tells the tale of a ma... \n",
|
365 |
+
"5194 9788179921623 Wisdom to Create a Life of Passi... \n",
|
366 |
+
"5195 9788185300535 This collection of the timeless ... \n",
|
367 |
+
"5196 9789027712059 Since the three volume edition o... \n",
|
368 |
+
"\n",
|
369 |
+
"[5197 rows x 14 columns]"
|
370 |
+
]
|
371 |
+
},
|
372 |
+
"execution_count": 9,
|
373 |
+
"metadata": {},
|
374 |
+
"output_type": "execute_result"
|
375 |
+
}
|
376 |
+
],
|
377 |
+
"source": [
|
378 |
+
"import pandas as pd\n",
|
379 |
+
"\n",
|
380 |
+
"books = pd.read_csv(\"books_cleaned.csv\")\n",
|
381 |
+
"books"
|
382 |
+
]
|
383 |
+
},
|
384 |
+
{
|
385 |
+
"cell_type": "code",
|
386 |
+
"execution_count": 9,
|
387 |
+
"id": "4144c4c6",
|
388 |
+
"metadata": {},
|
389 |
+
"outputs": [],
|
390 |
+
"source": [
|
391 |
+
"books[\"tagged_description\"].to_csv(\"tagged_description.txt\",\n",
|
392 |
+
" sep = \"\\n\",\n",
|
393 |
+
" index = False,\n",
|
394 |
+
" header = False)"
|
395 |
+
]
|
396 |
+
},
|
397 |
+
{
|
398 |
+
"cell_type": "code",
|
399 |
+
"execution_count": null,
|
400 |
+
"id": "80bd0392",
|
401 |
+
"metadata": {},
|
402 |
+
"outputs": [],
|
403 |
+
"source": [
|
404 |
+
"raw_documents = TextLoader(\"tagged_description.txt\", encoding='utf-8').load()\n",
|
405 |
+
"text_splitter = CharacterTextSplitter(chunk_size=0, chunk_overlap=0, separator=\"\\n\")\n",
|
406 |
+
"documents = text_splitter.split_documents(raw_documents)"
|
407 |
+
]
|
408 |
+
},
|
409 |
+
{
|
410 |
+
"cell_type": "code",
|
411 |
+
"execution_count": 12,
|
412 |
+
"id": "ddbb69ec",
|
413 |
+
"metadata": {},
|
414 |
+
"outputs": [
|
415 |
+
{
|
416 |
+
"data": {
|
417 |
+
"text/plain": [
|
418 |
+
"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.')"
|
419 |
+
]
|
420 |
+
},
|
421 |
+
"execution_count": 12,
|
422 |
+
"metadata": {},
|
423 |
+
"output_type": "execute_result"
|
424 |
+
}
|
425 |
+
],
|
426 |
+
"source": [
|
427 |
+
"documents[0]"
|
428 |
+
]
|
429 |
+
},
|
430 |
+
{
|
431 |
+
"cell_type": "code",
|
432 |
+
"execution_count": null,
|
433 |
+
"id": "1bc1e564",
|
434 |
+
"metadata": {},
|
435 |
+
"outputs": [
|
436 |
+
{
|
437 |
+
"name": "stderr",
|
438 |
+
"output_type": "stream",
|
439 |
+
"text": [
|
440 |
+
"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",
|
441 |
+
" from .autonotebook import tqdm as notebook_tqdm\n",
|
442 |
+
"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",
|
443 |
+
"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",
|
444 |
+
" warnings.warn(message)\n",
|
445 |
+
"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"
|
446 |
+
]
|
447 |
+
}
|
448 |
+
],
|
449 |
+
"source": [
|
450 |
+
"from langchain_community.embeddings import HuggingFaceEmbeddings\n",
|
451 |
+
"from langchain.vectorstores import Chroma\n",
|
452 |
+
"\n",
|
453 |
+
"embedding_model = HuggingFaceEmbeddings(model_name=\"sentence-transformers/paraphrase-MiniLM-L3-v2\")\n",
|
454 |
+
"\n",
|
455 |
+
"db_books = Chroma.from_documents(\n",
|
456 |
+
" documents,\n",
|
457 |
+
" embedding=embedding_model\n",
|
458 |
+
")\n"
|
459 |
+
]
|
460 |
+
},
|
461 |
+
{
|
462 |
+
"cell_type": "code",
|
463 |
+
"execution_count": 8,
|
464 |
+
"id": "8ed611b6",
|
465 |
+
"metadata": {},
|
466 |
+
"outputs": [
|
467 |
+
{
|
468 |
+
"data": {
|
469 |
+
"text/plain": [
|
470 |
+
"[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",
|
471 |
+
" 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",
|
472 |
+
" 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",
|
473 |
+
" 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",
|
474 |
+
" 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",
|
475 |
+
" 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",
|
476 |
+
" 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",
|
477 |
+
" 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",
|
478 |
+
" 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",
|
479 |
+
" 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.')]"
|
480 |
+
]
|
481 |
+
},
|
482 |
+
"execution_count": 8,
|
483 |
+
"metadata": {},
|
484 |
+
"output_type": "execute_result"
|
485 |
+
}
|
486 |
+
],
|
487 |
+
"source": [
|
488 |
+
"query = \"A book to teach children about nature\"\n",
|
489 |
+
"docs = db_books.similarity_search(query, k = 10)\n",
|
490 |
+
"docs"
|
491 |
+
]
|
492 |
+
},
|
493 |
+
{
|
494 |
+
"cell_type": "code",
|
495 |
+
"execution_count": null,
|
496 |
+
"id": "47e4c48c",
|
497 |
+
"metadata": {},
|
498 |
+
"outputs": [
|
499 |
+
{
|
500 |
+
"data": {
|
501 |
+
"text/html": [
|
502 |
+
"<div>\n",
|
503 |
+
"<style scoped>\n",
|
504 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
505 |
+
" vertical-align: middle;\n",
|
506 |
+
" }\n",
|
507 |
+
"\n",
|
508 |
+
" .dataframe tbody tr th {\n",
|
509 |
+
" vertical-align: top;\n",
|
510 |
+
" }\n",
|
511 |
+
"\n",
|
512 |
+
" .dataframe thead th {\n",
|
513 |
+
" text-align: right;\n",
|
514 |
+
" }\n",
|
515 |
+
"</style>\n",
|
516 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
517 |
+
" <thead>\n",
|
518 |
+
" <tr style=\"text-align: right;\">\n",
|
519 |
+
" <th></th>\n",
|
520 |
+
" <th>isbn13</th>\n",
|
521 |
+
" <th>isbn10</th>\n",
|
522 |
+
" <th>title</th>\n",
|
523 |
+
" <th>authors</th>\n",
|
524 |
+
" <th>categories</th>\n",
|
525 |
+
" <th>thumbnail</th>\n",
|
526 |
+
" <th>description</th>\n",
|
527 |
+
" <th>published_year</th>\n",
|
528 |
+
" <th>average_rating</th>\n",
|
529 |
+
" <th>num_pages</th>\n",
|
530 |
+
" <th>ratings_count</th>\n",
|
531 |
+
" <th>agg_of_book</th>\n",
|
532 |
+
" <th>title_and_subtitle</th>\n",
|
533 |
+
" <th>tagged_description</th>\n",
|
534 |
+
" </tr>\n",
|
535 |
+
" </thead>\n",
|
536 |
+
" <tbody>\n",
|
537 |
+
" <tr>\n",
|
538 |
+
" <th>4264</th>\n",
|
539 |
+
" <td>9780941807555</td>\n",
|
540 |
+
" <td>094180755X</td>\n",
|
541 |
+
" <td>The Little Big Book for God's Children</td>\n",
|
542 |
+
" <td>Lena Tabori;Alice Wong</td>\n",
|
543 |
+
" <td>Religion</td>\n",
|
544 |
+
" <td>http://books.google.com/books/content?id=s2PfT...</td>\n",
|
545 |
+
" <td>THE LITTLE BIG BOOK FOR GOD'S CHILDREN is a wo...</td>\n",
|
546 |
+
" <td>2001.0</td>\n",
|
547 |
+
" <td>4.88</td>\n",
|
548 |
+
" <td>352.0</td>\n",
|
549 |
+
" <td>8.0</td>\n",
|
550 |
+
" <td>24.0</td>\n",
|
551 |
+
" <td>The Little Big Book for God's Children</td>\n",
|
552 |
+
" <td>9780941807555 THE LITTLE BIG BOOK FOR GOD'S CH...</td>\n",
|
553 |
+
" </tr>\n",
|
554 |
+
" </tbody>\n",
|
555 |
+
"</table>\n",
|
556 |
+
"</div>"
|
557 |
+
],
|
558 |
+
"text/plain": [
|
559 |
+
" isbn13 isbn10 title \\\n",
|
560 |
+
"4264 9780941807555 094180755X The Little Big Book for God's Children \n",
|
561 |
+
"\n",
|
562 |
+
" authors categories \\\n",
|
563 |
+
"4264 Lena Tabori;Alice Wong Religion \n",
|
564 |
+
"\n",
|
565 |
+
" thumbnail \\\n",
|
566 |
+
"4264 http://books.google.com/books/content?id=s2PfT... \n",
|
567 |
+
"\n",
|
568 |
+
" description published_year \\\n",
|
569 |
+
"4264 THE LITTLE BIG BOOK FOR GOD'S CHILDREN is a wo... 2001.0 \n",
|
570 |
+
"\n",
|
571 |
+
" average_rating num_pages ratings_count agg_of_book \\\n",
|
572 |
+
"4264 4.88 352.0 8.0 24.0 \n",
|
573 |
+
"\n",
|
574 |
+
" title_and_subtitle \\\n",
|
575 |
+
"4264 The Little Big Book for God's Children \n",
|
576 |
+
"\n",
|
577 |
+
" tagged_description \n",
|
578 |
+
"4264 9780941807555 THE LITTLE BIG BOOK FOR GOD'S CH... "
|
579 |
+
]
|
580 |
+
},
|
581 |
+
"execution_count": 10,
|
582 |
+
"metadata": {},
|
583 |
+
"output_type": "execute_result"
|
584 |
+
}
|
585 |
+
],
|
586 |
+
"source": [
|
587 |
+
"books[books[\"isbn13\"] == int(docs[0].page_content.split()[0].strip())]"
|
588 |
+
]
|
589 |
+
},
|
590 |
+
{
|
591 |
+
"cell_type": "code",
|
592 |
+
"execution_count": 11,
|
593 |
+
"id": "43ed7a8c",
|
594 |
+
"metadata": {},
|
595 |
+
"outputs": [],
|
596 |
+
"source": [
|
597 |
+
"def retrieve_semantic_recommendation(\n",
|
598 |
+
" query:str,\n",
|
599 |
+
" top_k: int = 10,\n",
|
600 |
+
") -> pd.DataFrame :\n",
|
601 |
+
" recs = db_books.similarity_search(query, k = 50)\n",
|
602 |
+
"\n",
|
603 |
+
" books_list = []\n",
|
604 |
+
"\n",
|
605 |
+
" for i in range (0, len(recs)):\n",
|
606 |
+
" books_list += [int(recs[i].page_content.strip('\"\"').split()[0])]\n",
|
607 |
+
"\n",
|
608 |
+
" return books[books[\"isbn13\"].isin(books_list)].head(top_k)"
|
609 |
+
]
|
610 |
+
},
|
611 |
+
{
|
612 |
+
"cell_type": "code",
|
613 |
+
"execution_count": 12,
|
614 |
+
"id": "89dfb386",
|
615 |
+
"metadata": {},
|
616 |
+
"outputs": [
|
617 |
+
{
|
618 |
+
"data": {
|
619 |
+
"text/html": [
|
620 |
+
"<div>\n",
|
621 |
+
"<style scoped>\n",
|
622 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
623 |
+
" vertical-align: middle;\n",
|
624 |
+
" }\n",
|
625 |
+
"\n",
|
626 |
+
" .dataframe tbody tr th {\n",
|
627 |
+
" vertical-align: top;\n",
|
628 |
+
" }\n",
|
629 |
+
"\n",
|
630 |
+
" .dataframe thead th {\n",
|
631 |
+
" text-align: right;\n",
|
632 |
+
" }\n",
|
633 |
+
"</style>\n",
|
634 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
635 |
+
" <thead>\n",
|
636 |
+
" <tr style=\"text-align: right;\">\n",
|
637 |
+
" <th></th>\n",
|
638 |
+
" <th>isbn13</th>\n",
|
639 |
+
" <th>isbn10</th>\n",
|
640 |
+
" <th>title</th>\n",
|
641 |
+
" <th>authors</th>\n",
|
642 |
+
" <th>categories</th>\n",
|
643 |
+
" <th>thumbnail</th>\n",
|
644 |
+
" <th>description</th>\n",
|
645 |
+
" <th>published_year</th>\n",
|
646 |
+
" <th>average_rating</th>\n",
|
647 |
+
" <th>num_pages</th>\n",
|
648 |
+
" <th>ratings_count</th>\n",
|
649 |
+
" <th>agg_of_book</th>\n",
|
650 |
+
" <th>title_and_subtitle</th>\n",
|
651 |
+
" <th>tagged_description</th>\n",
|
652 |
+
" </tr>\n",
|
653 |
+
" </thead>\n",
|
654 |
+
" <tbody>\n",
|
655 |
+
" <tr>\n",
|
656 |
+
" <th>31</th>\n",
|
657 |
+
" <td>9780007105045</td>\n",
|
658 |
+
" <td>0007105045</td>\n",
|
659 |
+
" <td>Tree and Leaf</td>\n",
|
660 |
+
" <td>John Ronald Reuel Tolkien</td>\n",
|
661 |
+
" <td>Literary Collections</td>\n",
|
662 |
+
" <td>http://books.google.com/books/content?id=aPb_A...</td>\n",
|
663 |
+
" <td>\"The two works 'On fairy-stories' and 'Leaf by...</td>\n",
|
664 |
+
" <td>2001.0</td>\n",
|
665 |
+
" <td>4.09</td>\n",
|
666 |
+
" <td>176.0</td>\n",
|
667 |
+
" <td>2245.0</td>\n",
|
668 |
+
" <td>24.0</td>\n",
|
669 |
+
" <td>Tree and Leaf: The Homecoming of Beorhtnoth : ...</td>\n",
|
670 |
+
" <td>9780007105045 \"The two works 'On fairy-stories...</td>\n",
|
671 |
+
" </tr>\n",
|
672 |
+
" <tr>\n",
|
673 |
+
" <th>267</th>\n",
|
674 |
+
" <td>9780060882600</td>\n",
|
675 |
+
" <td>0060882603</td>\n",
|
676 |
+
" <td>The Annotated Charlotte's Web</td>\n",
|
677 |
+
" <td>E. B. White</td>\n",
|
678 |
+
" <td>Juvenile Nonfiction</td>\n",
|
679 |
+
" <td>http://books.google.com/books/content?id=vaYYH...</td>\n",
|
680 |
+
" <td>Charlotte's Web, one of America's best-loved c...</td>\n",
|
681 |
+
" <td>2006.0</td>\n",
|
682 |
+
" <td>4.16</td>\n",
|
683 |
+
" <td>320.0</td>\n",
|
684 |
+
" <td>41.0</td>\n",
|
685 |
+
" <td>19.0</td>\n",
|
686 |
+
" <td>The Annotated Charlotte's Web</td>\n",
|
687 |
+
" <td>9780060882600 Charlotte's Web, one of America'...</td>\n",
|
688 |
+
" </tr>\n",
|
689 |
+
" <tr>\n",
|
690 |
+
" <th>324</th>\n",
|
691 |
+
" <td>9780060959036</td>\n",
|
692 |
+
" <td>0060959037</td>\n",
|
693 |
+
" <td>Prodigal Summer</td>\n",
|
694 |
+
" <td>Barbara Kingsolver</td>\n",
|
695 |
+
" <td>Fiction</td>\n",
|
696 |
+
" <td>http://books.google.com/books/content?id=06IwG...</td>\n",
|
697 |
+
" <td>Barbara Kingsolver's fifth novel is a hymn to ...</td>\n",
|
698 |
+
" <td>2001.0</td>\n",
|
699 |
+
" <td>4.00</td>\n",
|
700 |
+
" <td>444.0</td>\n",
|
701 |
+
" <td>85440.0</td>\n",
|
702 |
+
" <td>24.0</td>\n",
|
703 |
+
" <td>Prodigal Summer: A Novel</td>\n",
|
704 |
+
" <td>9780060959036 Barbara Kingsolver's fifth novel...</td>\n",
|
705 |
+
" </tr>\n",
|
706 |
+
" <tr>\n",
|
707 |
+
" <th>397</th>\n",
|
708 |
+
" <td>9780062512796</td>\n",
|
709 |
+
" <td>006251279X</td>\n",
|
710 |
+
" <td>The Pilgrimage</td>\n",
|
711 |
+
" <td>Paulo Coelho;Alan R. Clarke</td>\n",
|
712 |
+
" <td>Fiction</td>\n",
|
713 |
+
" <td>http://books.google.com/books/content?id=atdJc...</td>\n",
|
714 |
+
" <td>Previously published as The Diary of a Magus, ...</td>\n",
|
715 |
+
" <td>1995.0</td>\n",
|
716 |
+
" <td>3.65</td>\n",
|
717 |
+
" <td>272.0</td>\n",
|
718 |
+
" <td>878.0</td>\n",
|
719 |
+
" <td>30.0</td>\n",
|
720 |
+
" <td>The Pilgrimage</td>\n",
|
721 |
+
" <td>9780062512796 Previously published as The Diar...</td>\n",
|
722 |
+
" </tr>\n",
|
723 |
+
" <tr>\n",
|
724 |
+
" <th>416</th>\n",
|
725 |
+
" <td>9780064406925</td>\n",
|
726 |
+
" <td>006440692X</td>\n",
|
727 |
+
" <td>Winter on the Farm</td>\n",
|
728 |
+
" <td>Laura Ingalls Wilder</td>\n",
|
729 |
+
" <td>Juvenile Fiction</td>\n",
|
730 |
+
" <td>http://books.google.com/books/content?id=IvlKH...</td>\n",
|
731 |
+
" <td>The Little House books tell the story of a lit...</td>\n",
|
732 |
+
" <td>1997.0</td>\n",
|
733 |
+
" <td>4.13</td>\n",
|
734 |
+
" <td>32.0</td>\n",
|
735 |
+
" <td>400.0</td>\n",
|
736 |
+
" <td>28.0</td>\n",
|
737 |
+
" <td>Winter on the Farm</td>\n",
|
738 |
+
" <td>9780064406925 The Little House books tell the ...</td>\n",
|
739 |
+
" </tr>\n",
|
740 |
+
" <tr>\n",
|
741 |
+
" <th>429</th>\n",
|
742 |
+
" <td>9780064434980</td>\n",
|
743 |
+
" <td>0064434982</td>\n",
|
744 |
+
" <td>The Deer in the Wood</td>\n",
|
745 |
+
" <td>Laura Ingalls Wilder</td>\n",
|
746 |
+
" <td>Juvenile Fiction</td>\n",
|
747 |
+
" <td>http://books.google.com/books/content?id=V7YDW...</td>\n",
|
748 |
+
" <td>Even the youngest child can enjoy a special ad...</td>\n",
|
749 |
+
" <td>1999.0</td>\n",
|
750 |
+
" <td>4.17</td>\n",
|
751 |
+
" <td>32.0</td>\n",
|
752 |
+
" <td>302.0</td>\n",
|
753 |
+
" <td>26.0</td>\n",
|
754 |
+
" <td>The Deer in the Wood</td>\n",
|
755 |
+
" <td>9780064434980 Even the youngest child can enjo...</td>\n",
|
756 |
+
" </tr>\n",
|
757 |
+
" <tr>\n",
|
758 |
+
" <th>434</th>\n",
|
759 |
+
" <td>9780064462044</td>\n",
|
760 |
+
" <td>0064462048</td>\n",
|
761 |
+
" <td>My Little House Crafts Book</td>\n",
|
762 |
+
" <td>Carolyn Strom Collins</td>\n",
|
763 |
+
" <td>Juvenile Nonfiction</td>\n",
|
764 |
+
" <td>http://books.google.com/books/content?id=lTzrs...</td>\n",
|
765 |
+
" <td>Make the same pioneer crafts that Laura did! I...</td>\n",
|
766 |
+
" <td>1998.0</td>\n",
|
767 |
+
" <td>4.05</td>\n",
|
768 |
+
" <td>64.0</td>\n",
|
769 |
+
" <td>56.0</td>\n",
|
770 |
+
" <td>27.0</td>\n",
|
771 |
+
" <td>My Little House Crafts Book: 18 Projects from ...</td>\n",
|
772 |
+
" <td>9780064462044 Make the same pioneer crafts tha...</td>\n",
|
773 |
+
" </tr>\n",
|
774 |
+
" <tr>\n",
|
775 |
+
" <th>435</th>\n",
|
776 |
+
" <td>9780064462341</td>\n",
|
777 |
+
" <td>006446234X</td>\n",
|
778 |
+
" <td>Pioneer Girl</td>\n",
|
779 |
+
" <td>William Anderson</td>\n",
|
780 |
+
" <td>Juvenile Nonfiction</td>\n",
|
781 |
+
" <td>http://books.google.com/books/content?id=Sj4UD...</td>\n",
|
782 |
+
" <td>The pioneer spirit lives on... Readers around ...</td>\n",
|
783 |
+
" <td>2000.0</td>\n",
|
784 |
+
" <td>4.15</td>\n",
|
785 |
+
" <td>32.0</td>\n",
|
786 |
+
" <td>414.0</td>\n",
|
787 |
+
" <td>25.0</td>\n",
|
788 |
+
" <td>Pioneer Girl: The Story of Laura Ingalls Wilder</td>\n",
|
789 |
+
" <td>9780064462341 The pioneer spirit lives on... R...</td>\n",
|
790 |
+
" </tr>\n",
|
791 |
+
" <tr>\n",
|
792 |
+
" <th>440</th>\n",
|
793 |
+
" <td>9780066238500</td>\n",
|
794 |
+
" <td>0066238501</td>\n",
|
795 |
+
" <td>The Chronicles of Narnia (adult)</td>\n",
|
796 |
+
" <td>C. S. Lewis</td>\n",
|
797 |
+
" <td>Fiction</td>\n",
|
798 |
+
" <td>http://books.google.com/books/content?id=3VGkK...</td>\n",
|
799 |
+
" <td>Journeys to the end of the world, fantastic cr...</td>\n",
|
800 |
+
" <td>2001.0</td>\n",
|
801 |
+
" <td>4.26</td>\n",
|
802 |
+
" <td>767.0</td>\n",
|
803 |
+
" <td>425445.0</td>\n",
|
804 |
+
" <td>24.0</td>\n",
|
805 |
+
" <td>The Chronicles of Narnia (adult)</td>\n",
|
806 |
+
" <td>9780066238500 Journeys to the end of the world...</td>\n",
|
807 |
+
" </tr>\n",
|
808 |
+
" <tr>\n",
|
809 |
+
" <th>442</th>\n",
|
810 |
+
" <td>9780067575208</td>\n",
|
811 |
+
" <td>006757520X</td>\n",
|
812 |
+
" <td>The Sense of Wonder</td>\n",
|
813 |
+
" <td>Rachel Carson</td>\n",
|
814 |
+
" <td>Nature</td>\n",
|
815 |
+
" <td>http://books.google.com/books/content?id=Zee5S...</td>\n",
|
816 |
+
" <td>First published more than three decades ago, t...</td>\n",
|
817 |
+
" <td>1998.0</td>\n",
|
818 |
+
" <td>4.39</td>\n",
|
819 |
+
" <td>112.0</td>\n",
|
820 |
+
" <td>1160.0</td>\n",
|
821 |
+
" <td>27.0</td>\n",
|
822 |
+
" <td>The Sense of Wonder</td>\n",
|
823 |
+
" <td>9780067575208 First published more than three ...</td>\n",
|
824 |
+
" </tr>\n",
|
825 |
+
" </tbody>\n",
|
826 |
+
"</table>\n",
|
827 |
+
"</div>"
|
828 |
+
],
|
829 |
+
"text/plain": [
|
830 |
+
" isbn13 isbn10 title \\\n",
|
831 |
+
"31 9780007105045 0007105045 Tree and Leaf \n",
|
832 |
+
"267 9780060882600 0060882603 The Annotated Charlotte's Web \n",
|
833 |
+
"324 9780060959036 0060959037 Prodigal Summer \n",
|
834 |
+
"397 9780062512796 006251279X The Pilgrimage \n",
|
835 |
+
"416 9780064406925 006440692X Winter on the Farm \n",
|
836 |
+
"429 9780064434980 0064434982 The Deer in the Wood \n",
|
837 |
+
"434 9780064462044 0064462048 My Little House Crafts Book \n",
|
838 |
+
"435 9780064462341 006446234X Pioneer Girl \n",
|
839 |
+
"440 9780066238500 0066238501 The Chronicles of Narnia (adult) \n",
|
840 |
+
"442 9780067575208 006757520X The Sense of Wonder \n",
|
841 |
+
"\n",
|
842 |
+
" authors categories \\\n",
|
843 |
+
"31 John Ronald Reuel Tolkien Literary Collections \n",
|
844 |
+
"267 E. B. White Juvenile Nonfiction \n",
|
845 |
+
"324 Barbara Kingsolver Fiction \n",
|
846 |
+
"397 Paulo Coelho;Alan R. Clarke Fiction \n",
|
847 |
+
"416 Laura Ingalls Wilder Juvenile Fiction \n",
|
848 |
+
"429 Laura Ingalls Wilder Juvenile Fiction \n",
|
849 |
+
"434 Carolyn Strom Collins Juvenile Nonfiction \n",
|
850 |
+
"435 William Anderson Juvenile Nonfiction \n",
|
851 |
+
"440 C. S. Lewis Fiction \n",
|
852 |
+
"442 Rachel Carson Nature \n",
|
853 |
+
"\n",
|
854 |
+
" thumbnail \\\n",
|
855 |
+
"31 http://books.google.com/books/content?id=aPb_A... \n",
|
856 |
+
"267 http://books.google.com/books/content?id=vaYYH... \n",
|
857 |
+
"324 http://books.google.com/books/content?id=06IwG... \n",
|
858 |
+
"397 http://books.google.com/books/content?id=atdJc... \n",
|
859 |
+
"416 http://books.google.com/books/content?id=IvlKH... \n",
|
860 |
+
"429 http://books.google.com/books/content?id=V7YDW... \n",
|
861 |
+
"434 http://books.google.com/books/content?id=lTzrs... \n",
|
862 |
+
"435 http://books.google.com/books/content?id=Sj4UD... \n",
|
863 |
+
"440 http://books.google.com/books/content?id=3VGkK... \n",
|
864 |
+
"442 http://books.google.com/books/content?id=Zee5S... \n",
|
865 |
+
"\n",
|
866 |
+
" description published_year \\\n",
|
867 |
+
"31 \"The two works 'On fairy-stories' and 'Leaf by... 2001.0 \n",
|
868 |
+
"267 Charlotte's Web, one of America's best-loved c... 2006.0 \n",
|
869 |
+
"324 Barbara Kingsolver's fifth novel is a hymn to ... 2001.0 \n",
|
870 |
+
"397 Previously published as The Diary of a Magus, ... 1995.0 \n",
|
871 |
+
"416 The Little House books tell the story of a lit... 1997.0 \n",
|
872 |
+
"429 Even the youngest child can enjoy a special ad... 1999.0 \n",
|
873 |
+
"434 Make the same pioneer crafts that Laura did! I... 1998.0 \n",
|
874 |
+
"435 The pioneer spirit lives on... Readers around ... 2000.0 \n",
|
875 |
+
"440 Journeys to the end of the world, fantastic cr... 2001.0 \n",
|
876 |
+
"442 First published more than three decades ago, t... 1998.0 \n",
|
877 |
+
"\n",
|
878 |
+
" average_rating num_pages ratings_count agg_of_book \\\n",
|
879 |
+
"31 4.09 176.0 2245.0 24.0 \n",
|
880 |
+
"267 4.16 320.0 41.0 19.0 \n",
|
881 |
+
"324 4.00 444.0 85440.0 24.0 \n",
|
882 |
+
"397 3.65 272.0 878.0 30.0 \n",
|
883 |
+
"416 4.13 32.0 400.0 28.0 \n",
|
884 |
+
"429 4.17 32.0 302.0 26.0 \n",
|
885 |
+
"434 4.05 64.0 56.0 27.0 \n",
|
886 |
+
"435 4.15 32.0 414.0 25.0 \n",
|
887 |
+
"440 4.26 767.0 425445.0 24.0 \n",
|
888 |
+
"442 4.39 112.0 1160.0 27.0 \n",
|
889 |
+
"\n",
|
890 |
+
" title_and_subtitle \\\n",
|
891 |
+
"31 Tree and Leaf: The Homecoming of Beorhtnoth : ... \n",
|
892 |
+
"267 The Annotated Charlotte's Web \n",
|
893 |
+
"324 Prodigal Summer: A Novel \n",
|
894 |
+
"397 The Pilgrimage \n",
|
895 |
+
"416 Winter on the Farm \n",
|
896 |
+
"429 The Deer in the Wood \n",
|
897 |
+
"434 My Little House Crafts Book: 18 Projects from ... \n",
|
898 |
+
"435 Pioneer Girl: The Story of Laura Ingalls Wilder \n",
|
899 |
+
"440 The Chronicles of Narnia (adult) \n",
|
900 |
+
"442 The Sense of Wonder \n",
|
901 |
+
"\n",
|
902 |
+
" tagged_description \n",
|
903 |
+
"31 9780007105045 \"The two works 'On fairy-stories... \n",
|
904 |
+
"267 9780060882600 Charlotte's Web, one of America'... \n",
|
905 |
+
"324 9780060959036 Barbara Kingsolver's fifth novel... \n",
|
906 |
+
"397 9780062512796 Previously published as The Diar... \n",
|
907 |
+
"416 9780064406925 The Little House books tell the ... \n",
|
908 |
+
"429 9780064434980 Even the youngest child can enjo... \n",
|
909 |
+
"434 9780064462044 Make the same pioneer crafts tha... \n",
|
910 |
+
"435 9780064462341 The pioneer spirit lives on... R... \n",
|
911 |
+
"440 9780066238500 Journeys to the end of the world... \n",
|
912 |
+
"442 9780067575208 First published more than three ... "
|
913 |
+
]
|
914 |
+
},
|
915 |
+
"execution_count": 12,
|
916 |
+
"metadata": {},
|
917 |
+
"output_type": "execute_result"
|
918 |
+
}
|
919 |
+
],
|
920 |
+
"source": [
|
921 |
+
"retrieve_semantic_recommendation(\"A book to teach children about nature\")"
|
922 |
+
]
|
923 |
+
},
|
924 |
+
{
|
925 |
+
"cell_type": "code",
|
926 |
+
"execution_count": null,
|
927 |
+
"id": "f655cdbb",
|
928 |
+
"metadata": {},
|
929 |
+
"outputs": [],
|
930 |
+
"source": []
|
931 |
+
}
|
932 |
+
],
|
933 |
+
"metadata": {
|
934 |
+
"kernelspec": {
|
935 |
+
"display_name": "books_env",
|
936 |
+
"language": "python",
|
937 |
+
"name": "python3"
|
938 |
+
},
|
939 |
+
"language_info": {
|
940 |
+
"codemirror_mode": {
|
941 |
+
"name": "ipython",
|
942 |
+
"version": 3
|
943 |
+
},
|
944 |
+
"file_extension": ".py",
|
945 |
+
"mimetype": "text/x-python",
|
946 |
+
"name": "python",
|
947 |
+
"nbconvert_exporter": "python",
|
948 |
+
"pygments_lexer": "ipython3",
|
949 |
+
"version": "3.13.1"
|
950 |
+
}
|
951 |
+
},
|
952 |
+
"nbformat": 4,
|
953 |
+
"nbformat_minor": 5
|
954 |
+
}
|