Hosted with nbsanity. See source notebook on GitHub.

The Idea

  1. Scrape the plot of every James Bond Movie from Wikipedia
  2. Create embeddings for every plot
  3. Do dimensionality reduction using tSNE or PCA
  4. Plot the embeddings in a 2D plot
import httpx
import bs4

url = "https://en.wikipedia.org/wiki/List_of_James_Bond_films"

response = httpx.get(url)

response.text
'<!DOCTYPE html>\n<html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available" lang="en" dir="ltr">\n<head>\n<meta charset="UTF-8">\n<title>List of James Bond films - Wikipedia</title>\n<script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )enwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split(\'%2C\').forEach(function(pref){className=className.replace(new RegExp(\'(^| )\'+pref.replace(/-clientpref-\\w+$|[^\\w-]+/g,\'\')+\'-clientpref-\\\\w+( |$)\'),\'$1\'+pref+\'$2\');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy",\n"wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"eea0d489-1153-424f-bd0b-ea3fd0a0e94f","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"List_of_James_Bond_films","wgTitle":"List of James Bond films","wgCurRevisionId":1269603875,"wgRevisionId":1269603875,"wgArticleId":33190861,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["IMDb ID (Cite Mojo) not in Wikidata","Articles with short description","Short description is different from Wikidata","Use dmy dates from June 2020","EngvarB from February 2023","Webarchive template wayback links","Featured lists","James Bond in film","Lists of films by franchise"],"wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"List_of_James_Bond_films","wgRelevantArticleId":33190861,\n"wgIsProbablyEditable":true,"wgRelevantPageIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgNoticeProject":"wikipedia","wgCiteReferencePreviewsActive":false,"wgFlaggedRevsParams":{"tags":{"status":{"levels":1}}},"wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault":true,"wgPopupsFlags":0,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby":true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":100000,"wgRelatedArticlesCompat":[],"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"interlanguage","wgULSisCompactLinksEnabled":false,"wgVector2022LanguageInHeader":true,"wgULSisLanguageSelectorEmpty":false,"wgWikibaseItemId":"Q151472","wgCheckUserClientHintsHeadersJsApi":["brands","architecture","bitness","fullVersionList","mobile","model","platform","platformVersion"],"GEHomepageSuggestedEditsEnableTopics":true,\n"wgGETopicsMatchModeEnabled":false,"wgGEStructuredTaskRejectionReasonTextInputEnabled":false,"wgGELevelingUpEnabledForUser":false};RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.cite.styles":"ready","skins.vector.search.codex.styles":"ready","skins.vector.styles":"ready","skins.vector.icons":"read'
========== TRUNCATED ==========
'FBen_Fritz2015\\"] = 1,\\n    [\\"CITEREFBlockAutrey_Wilson2010\\"] = 1,\\n    [\\"CITEREFBrent_Lang2015\\"] = 1,\\n    [\\"CITEREFChapman2009\\"] = 1,\\n    [\\"CITEREFCorkScivally2002\\"] = 1,\\n    [\\"CITEREFFord2019\\"] = 1,\\n    [\\"CITEREFHoffman2021\\"] = 1,\\n    [\\"CITEREFJudge_M._Margaret_McKeown2001\\"] = 1,\\n    [\\"CITEREFLangDonnelly2020\\"] = 1,\\n    [\\"CITEREFMartin2014\\"] = 1,\\n    [\\"CITEREFMunden1997\\"] = 1,\\n    [\\"CITEREFPamela_McClintock2015\\"] = 1,\\n    [\\"CITEREFPoliakoff2000\\"] = 1,\\n    [\\"CITEREFShprintz1999\\"] = 1,\\n    [\\"CITEREFSmith2012\\"] = 1,\\n    [\\"CITEREFSterngold1999\\"] = 1,\\n}\\ntemplate_list = table#1 {\\n    [\\"!\\"] = 27,\\n    [\\"Abbr\\"] = 2,\\n    [\\"Cbignore\\"] = 1,\\n    [\\"Cite Box Office Mojo\\"] = 1,\\n    [\\"Cite book\\"] = 5,\\n    [\\"Cite journal\\"] = 1,\\n    [\\"Cite magazine\\"] = 1,\\n    [\\"Cite news\\"] = 9,\\n    [\\"Cite press release\\"] = 1,\\n    [\\"Cite web\\"] = 121,\\n    [\\"Clear\\"] = 1,\\n    [\\"Efn\\"] = 2,\\n    [\\"EngvarB\\"] = 1,\\n    [\\"Featured list\\"] = 1,\\n    [\\"Formatnum:{{#expr: {{Inflation\\"] = 3,\\n    [\\"Formatnum:{{#expr:1.1+2.0+3.0+6.8+10.3+7.0+7.2+7.0+7.0+14.0+34.0+28.0+27.5+30.0+40.0+36.0+60.0+110.0+135.0+142.0+150.0+200.0+150.0+245.0+250.0 round 0\\"] = 1,\\n    [\\"Formatnum:{{#expr:1.1+2.0+3.0+6.8+10.3+7.0+7.2+7.0+7.0+14.0+34.0+28.0+27.5+30.0+40.0+36.0+60.0+110.0+135.0+142.0+150.0+200.0+200.0+250.0+301.1 round 0\\"] = 1,\\n    [\\"Formatnum:{{#expr:59.5+78.9+124.9+141.2+101.0+64.6+116.0+126.4+98.5+185.4+210.3+194.9+183.7+152.4+191.2+156.2+351.9+338.9+361.8+431.9+606.0+576.0+1108.6+880.7+771.2 round 0\\"] = 1,\\n    [\\"Formatnum:{{#expr:{{Inflation\\"] = 1,\\n    [\\"Formatnum:{{Inflation\\"] = 45,\\n    [\\"Inflation\\"] = 75,\\n    [\\"Inflation-fn\\"] = 2,\\n    [\\"Inflation/fn\\"] = 2,\\n    [\\"Italic title\\"] = 1,\\n    [\\"James Bond films\\"] = 1,\\n    [\\"Main\\"] = 27,\\n    [\\"N/a\\"] = 19,\\n    [\\"Nowrap\\"] = 2,\\n    [\\"Redirect\\"] = 1,\\n    [\\"Reflist\\"] = 2,\\n    [\\"Round\\"] = 15,\\n    [\\"Sfn\\"] = 42,\\n    [\\"Short description\\"] = 1,\\n    [\\"Sort\\"] = 65,\\n    [\\"Sort grade\\"] = 10,\\n    [\\"TOC limit\\"] = 1,\\n    [\\"Use dmy dates\\"] = 1,\\n    [\\"Webarchive\\"] = 1,\\n}\\narticle_whitelist = table#1 {\\n}\\nciteref_patterns = table#1 {\\n}\\n","limitreport-profile":[["MediaWiki\\\\Extension\\\\Scribunto\\\\Engines\\\\LuaSandbox\\\\LuaSandboxCallback::getExpandedArgument","380","25.7"],["MediaWiki\\\\Extension\\\\Scribunto\\\\Engines\\\\LuaSandbox\\\\LuaSandboxCallback::callParserFunction","200","13.5"],["?","180","12.2"],["recursiveClone \\u003CmwInit.lua:45\\u003E","140","9.5"],["MediaWiki\\\\Extension\\\\Scribunto\\\\Engines\\\\LuaSandbox\\\\LuaSandboxCallback::match","140","9.5"],["dataWrapper \\u003Cmw.lua:672\\u003E","120","8.1"],["MediaWiki\\\\Extension\\\\Scribunto\\\\Engines\\\\LuaSandbox\\\\LuaSandboxCallback::find","60","4.1"],["type","40","2.7"],["MediaWiki\\\\Extension\\\\Scribunto\\\\Engines\\\\LuaSandbox\\\\LuaSandboxCallback::sub","40","2.7"],["MediaWiki\\\\Extension\\\\Scribunto\\\\Engines\\\\LuaSandbox\\\\LuaSandboxCallback::preprocess","40","2.7"],["[others]","140","9.5"]]},"cachereport":{"origin":"mw-web.eqiad.main-66cc88c876-n9pk9","timestamp":"20250115133417","ttl":2592000,"transientcontent":false}}});});</script>\n<script type="application/ld+json">{"@context":"https:\\/\\/schema.org","@type":"Article","name":"List of James Bond films","url":"https:\\/\\/en.wikipedia.org\\/wiki\\/List_of_James_Bond_films","sameAs":"http:\\/\\/www.wikidata.org\\/entity\\/Q151472","mainEntity":"http:\\/\\/www.wikidata.org\\/entity\\/Q151472","author":{"@type":"Organization","name":"Contributors to Wikimedia projects"},"publisher":{"@type":"Organization","name":"Wikimedia Foundation, Inc.","logo":{"@type":"ImageObject","url":"https:\\/\\/www.wikimedia.org\\/static\\/images\\/wmf-hor-googpub.png"}},"datePublished":"2011-09-24T01:19:05Z","dateModified":"2025-01-15T13:34:13Z","headline":"Wikimedia list article"}</script>\n</body>\n</html>'
========== MIDDLE OF OUTPUT TRUNCATED ==========
soup = bs4.BeautifulSoup(response.text, "html.parser")

soup
<!DOCTYPE html>

<html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available" dir="ltr" lang="en">
<head>
<meta charset="utf-8"/>
<title>List of James Bond films - Wikipedia</title>
<script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )enwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy",
"wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"eea0d489-1153-424f-bd0b-ea3fd0a0e94f","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"List_of_James_Bond_films","wgTitle":"List of James Bond films","wgCurRevisionId":1269603875,"wgRevisionId":1269603875,"wgArticleId":33190861,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["IMDb ID (Cite Mojo) not in Wikidata","Articles with short description","Short description is different from Wikidata","Use dmy dates from June 2020","EngvarB from February 2023","Webarchive template wayback links","Featured lists","James Bond in film","Lists of films by franchise"],"wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"List_of_James_Bond_films","wgRelevantArticleId":33190861,
"wgIsProbablyEditable":true,"wgRelevantPageIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgNoticeProject":"wikipedia","wgCiteReferencePreviewsActive":false,"wgFlaggedRevsParams":{"tags":{"status":{"levels":1}}},"wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault":true,"wgPopupsFlags":0,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby":true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":100000,"wgRelatedArticlesCompat":[],"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"interlanguage","wgULSisCompactLinksEnabled":false,"wgVector2022LanguageInHeader":true,"wgULSisLanguageSelectorEmpty":false,"wgWikibaseItemId":"Q151472","wgCheckUserClientHintsHeadersJsApi":["brands","architecture","bitness","fullVersionList","mobile","model","platform","platformVersion"],"GEHomepageSuggestedEditsEnableTopics":true,
"wgGETopicsMatchModeEnabled":false,"wgGEStructuredTaskRejectionReasonTextInputEnabled":false,"wgGELevelingUpEnabledForUser":false};RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.cite.styles":"ready","skins.vector.search.codex.styles":"ready","skins.vector.styles":"ready","skins.vector.icons":"ready","jquery.tablesorter.
========== TRUNCATED ==========
"},"limitreport-memusage":{"value":7715599,"limit":52428800},"limitreport-logs":"anchor_id_list = table#1 {\n    [\"CITEREFAlicia_Adejobi2015\"] = 1,\n    [\"CITEREFAnthony_D\u0026#039;Alessandro2015\"] = 2,\n    [\"CITEREFBalio1987\"] = 1,\n    [\"CITEREFBen_Fritz2015\"] = 1,\n    [\"CITEREFBlockAutrey_Wilson2010\"] = 1,\n    [\"CITEREFBrent_Lang2015\"] = 1,\n    [\"CITEREFChapman2009\"] = 1,\n    [\"CITEREFCorkScivally2002\"] = 1,\n    [\"CITEREFFord2019\"] = 1,\n    [\"CITEREFHoffman2021\"] = 1,\n    [\"CITEREFJudge_M._Margaret_McKeown2001\"] = 1,\n    [\"CITEREFLangDonnelly2020\"] = 1,\n    [\"CITEREFMartin2014\"] = 1,\n    [\"CITEREFMunden1997\"] = 1,\n    [\"CITEREFPamela_McClintock2015\"] = 1,\n    [\"CITEREFPoliakoff2000\"] = 1,\n    [\"CITEREFShprintz1999\"] = 1,\n    [\"CITEREFSmith2012\"] = 1,\n    [\"CITEREFSterngold1999\"] = 1,\n}\ntemplate_list = table#1 {\n    [\"!\"] = 27,\n    [\"Abbr\"] = 2,\n    [\"Cbignore\"] = 1,\n    [\"Cite Box Office Mojo\"] = 1,\n    [\"Cite book\"] = 5,\n    [\"Cite journal\"] = 1,\n    [\"Cite magazine\"] = 1,\n    [\"Cite news\"] = 9,\n    [\"Cite press release\"] = 1,\n    [\"Cite web\"] = 121,\n    [\"Clear\"] = 1,\n    [\"Efn\"] = 2,\n    [\"EngvarB\"] = 1,\n    [\"Featured list\"] = 1,\n    [\"Formatnum:{{#expr: {{Inflation\"] = 3,\n    [\"Formatnum:{{#expr:1.1+2.0+3.0+6.8+10.3+7.0+7.2+7.0+7.0+14.0+34.0+28.0+27.5+30.0+40.0+36.0+60.0+110.0+135.0+142.0+150.0+200.0+150.0+245.0+250.0 round 0\"] = 1,\n    [\"Formatnum:{{#expr:1.1+2.0+3.0+6.8+10.3+7.0+7.2+7.0+7.0+14.0+34.0+28.0+27.5+30.0+40.0+36.0+60.0+110.0+135.0+142.0+150.0+200.0+200.0+250.0+301.1 round 0\"] = 1,\n    [\"Formatnum:{{#expr:59.5+78.9+124.9+141.2+101.0+64.6+116.0+126.4+98.5+185.4+210.3+194.9+183.7+152.4+191.2+156.2+351.9+338.9+361.8+431.9+606.0+576.0+1108.6+880.7+771.2 round 0\"] = 1,\n    [\"Formatnum:{{#expr:{{Inflation\"] = 1,\n    [\"Formatnum:{{Inflation\"] = 45,\n    [\"Inflation\"] = 75,\n    [\"Inflation-fn\"] = 2,\n    [\"Inflation/fn\"] = 2,\n    [\"Italic title\"] = 1,\n    [\"James Bond films\"] = 1,\n    [\"Main\"] = 27,\n    [\"N/a\"] = 19,\n    [\"Nowrap\"] = 2,\n    [\"Redirect\"] = 1,\n    [\"Reflist\"] = 2,\n    [\"Round\"] = 15,\n    [\"Sfn\"] = 42,\n    [\"Short description\"] = 1,\n    [\"Sort\"] = 65,\n    [\"Sort grade\"] = 10,\n    [\"TOC limit\"] = 1,\n    [\"Use dmy dates\"] = 1,\n    [\"Webarchive\"] = 1,\n}\narticle_whitelist = table#1 {\n}\nciteref_patterns = table#1 {\n}\n","limitreport-profile":[["MediaWiki\\Extension\\Scribunto\\Engines\\LuaSandbox\\LuaSandboxCallback::getExpandedArgument","380","25.7"],["MediaWiki\\Extension\\Scribunto\\Engines\\LuaSandbox\\LuaSandboxCallback::callParserFunction","200","13.5"],["?","180","12.2"],["recursiveClone \u003CmwInit.lua:45\u003E","140","9.5"],["MediaWiki\\Extension\\Scribunto\\Engines\\LuaSandbox\\LuaSandboxCallback::match","140","9.5"],["dataWrapper \u003Cmw.lua:672\u003E","120","8.1"],["MediaWiki\\Extension\\Scribunto\\Engines\\LuaSandbox\\LuaSandboxCallback::find","60","4.1"],["type","40","2.7"],["MediaWiki\\Extension\\Scribunto\\Engines\\LuaSandbox\\LuaSandboxCallback::sub","40","2.7"],["MediaWiki\\Extension\\Scribunto\\Engines\\LuaSandbox\\LuaSandboxCallback::preprocess","40","2.7"],["[others]","140","9.5"]]},"cachereport":{"origin":"mw-web.eqiad.main-66cc88c876-n9pk9","timestamp":"20250115133417","ttl":2592000,"transientcontent":false}}});});</script>
<script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"Article","name":"List of James Bond films","url":"https:\/\/en.wikipedia.org\/wiki\/List_of_James_Bond_films","sameAs":"http:\/\/www.wikidata.org\/entity\/Q151472","mainEntity":"http:\/\/www.wikidata.org\/entity\/Q151472","author":{"@type":"Organization","name":"Contributors to Wikimedia projects"},"publisher":{"@type":"Organization","name":"Wikimedia Foundation, Inc.","logo":{"@type":"ImageObject","url":"https:\/\/www.wikimedia.org\/static\/images\/wmf-hor-googpub.png"}},"datePublished":"2011-09-24T01:19:05Z","dateModified":"2025-01-15T13:34:13Z","headline":"Wikimedia list article"}</script>
</body>
</html>
========== MIDDLE OF OUTPUT TRUNCATED ==========

AI Prompt

how can I find the table with the following selector in the soup: “#mw-content-text > div.mw-content-ltr.mw-parser-output > table:nth-child(11)”

AI Response

To find that specific table using BeautifulSoup, you can break down the CSS selector into parts and use BeautifulSoup’s find/select methods. Here’s how you can do it:

# Using select method with the full CSS selector
table = soup.select("#mw-content-text > div.mw-content-ltr.mw-parser-output > table:nth-child(11)")

# Or break it down with find/find_all
table = soup.find(id="mw-content-text")\
    .find("div", class_="mw-parser-output")\
    .find_all("table")[10]  # nth-child(11) is the 11th child, index 10 in 0-based indexing

Either approach should work. The second approach might be more reliable since it’s less dependent on exact class names and structure. Would you like to try one of these approaches?

table = soup.select("#mw-content-text > div.mw-content-ltr.mw-parser-output > table:nth-child(11)")

table
[<table class="wikitable plainrowheaders sortable" style="text-align:center;">
 <caption>Eon films
 </caption>
 <tbody><tr>
 <th rowspan="2" scope="col">Title
 </th>
 <th rowspan="2" scope="col">Year
 </th>
 <th rowspan="2" scope="col">Bond actor
 </th>
 <th rowspan="2" scope="col">Director
 </th>
 <th class="unsortable" colspan="2">Box office (millions)<sup class="reference" id="cite_ref-FOOTNOTEBlockAutrey_Wilson2010428–429_14-0"><a href="#cite_note-FOOTNOTEBlockAutrey_Wilson2010428–429-14"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup><sup class="reference" id="cite_ref-inflation-US_15-0"><a href="#cite_note-inflation-US-15"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup>
 </th>
 <th class="unsortable" colspan="2">Budget (millions)<sup class="reference" id="cite_ref-FOOTNOTEBlockAutrey_Wilson2010428–429_14-1"><a href="#cite_note-FOOTNOTEBlockAutrey_Wilson2010428–429-14"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup><sup class="reference" id="cite_ref-inflation-US_15-1"><a href="#cite_note-inflation-US-15"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup>
 </th>
 <th class="unsortable" rowspan="2" scope="col"><span class="nowrap"><abbr title="References">Ref(s)</abbr></span>
 </th></tr>
 <tr class="unsortable">
 <th data-sort-type="number" scope="col">Actual $
 </th>
 <th data-sort-type="number" scope="col">Adjusted $ (2023)
 </th>
 <th data-sort-type="number" scope="col">Actual $
 </th>
 <th data-sort-type="number" scope="col">Adjusted $ (2023)
 </th></tr>
 <tr>
 <th scope="row"><i><a href="/wiki/Dr._No_(film)" title="Dr. No (film)">Dr. No</a></i>
 </th>
 <td>1962
 </td>
 <td><span data-sort-value="Connery Sean !"><a href="/wiki/Sean_Connery" title="Sean Connery">Sean Connery</a></span>
 </td>
 <td><span data-sort-value="Young Terence !"><a href="/wiki/Terence_Young_(director)" title="Terence Young (director)">Terence Young</a></span>
 </td>
 <td>59.5
 </td>
 <td>700.2
 </td>
 <td>1.1
 </td>
 <td>10.9
 </td>
 <td><sup class="reference" id="cite_ref-FOOTNOTEBlockAutrey_Wilson2010428–429_14-2"><a href="#cite_note-FOOTNOTEBlockAutrey_Wilson2010428–429-14"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup><sup class="reference" id="cite_ref-FOOTNOTECorkScivally2002300–303_16-0"><a href="#cite_note-FOOTNOTECorkScivally2002300–303-16"><span class="cite-bracket">[</span>15<span class="cite-bracket">]</span></a></sup>
 </td></tr>
 <tr>
 <th scope="row"><i><a href="/wiki/From_Russia_with_Love_(film)" title="From Russia with Love (film)">From Russia with Love</a></i>
 </th>
 <td>1963
 </td>
 <td><span data-sort-value="Connery Sean !"><a href="/wiki/Sean_Connery" title="Sean Connery">Sean Connery</a></span>
 </td>
 <td><span data-sort-value="Young Terence !"><a href="/wiki/Terence_Young_(director)" title="Terence Young (director)">Terence Young</a></span>
 </td>
 <td>78.9
 </td>
 <td>848.4
 </td>
 <td>2.0
 </td>
 <td>19.7
 </td>
 <td><sup class="reference" id="cite_ref-FOOTNOTEBlockAutrey_Wilson2010428–429_14-3"><a href="#cite_note-FOOTNOTEBlockAutrey_Wilson2010428–429-14"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup><sup class="reference" id="cite_ref-FOOTNOTECorkScivally2002300–303_16-1"><a href="#cite_note-FOOTNOTECorkScivally2002300–303-16"><span class="cite-bracket">[</span>15<span class="cite-bracket">]</span></a></sup><sup class="reference" id="cite_ref-17"><a href="#cite_note-17"><span class="cite-bracket">[</span>16<span class="cite-bracket">]</span></a></sup>
 </td></tr>
 <tr>
 <th scope="row"><i><a href="/wiki/Goldfinger_(film)" title="Goldfinger (film)">Goldfinger</a></i>
 </th>
 <td>1964
 </td>
 <td><span data-sort-value="Connery Sean !"><a href="/wiki/Sean_Connery" title="Sean Connery">Sean Connery</a></span>
 </td>
 <td><span data-sort-value="Hamilton Guy !"><a href="/wiki/Guy_Hamilton" title="Guy Hamilton">Guy Hamilton</a></span>
 </td>
 <td>124.9
 </td>
 <td>1,279.9
 </td>
 <td>3.0
 </td>
 <td>29.0
 </td>
 
========== TRUNCATED ==========
e (2006 film)">Casino Royale</a></i>
 </th>
 <td>2006
 </td>
 <td><span data-sort-value="Craig Daniel !"><a href="/wiki/Daniel_Craig" title="Daniel Craig">Daniel Craig</a></span>
 </td>
 <td><span data-sort-value="Campbell Martin !"><a href="/wiki/Martin_Campbell" title="Martin Campbell">Martin Campbell</a></span>
 </td>
 <td>606.0
 </td>
 <td>919.2
 </td>
 <td>150.0
 </td>
 <td>234.0
 </td>
 <td><sup class="reference" id="cite_ref-31"><a href="#cite_note-31"><span class="cite-bracket">[</span>30<span class="cite-bracket">]</span></a></sup><sup class="reference" id="cite_ref-FOOTNOTEBlockAutrey_Wilson2010428–429_14-19"><a href="#cite_note-FOOTNOTEBlockAutrey_Wilson2010428–429-14"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup>
 </td></tr>
 <tr>
 <th scope="row"><i><a href="/wiki/Quantum_of_Solace" title="Quantum of Solace">Quantum of Solace</a></i>
 </th>
 <td>2008
 </td>
 <td><span data-sort-value="Craig Daniel !"><a href="/wiki/Daniel_Craig" title="Daniel Craig">Daniel Craig</a></span>
 </td>
 <td><span data-sort-value="Forster Marc !"><a href="/wiki/Marc_Forster" title="Marc Forster">Marc Forster</a></span>
 </td>
 <td>586.1
 </td>
 <td>802.2
 </td>
 <td>200.0
 </td>
 <td>283.0
 </td>
 <td><sup class="reference" id="cite_ref-32"><a href="#cite_note-32"><span class="cite-bracket">[</span>31<span class="cite-bracket">]</span></a></sup>
 </td></tr>
 <tr>
 <th scope="row"><i><a href="/wiki/Skyfall" title="Skyfall">Skyfall</a></i>
 </th>
 <td>2012
 </td>
 <td><span data-sort-value="Craig Daniel !"><a href="/wiki/Daniel_Craig" title="Daniel Craig">Daniel Craig</a></span>
 </td>
 <td><span data-sort-value="Mendes Sam !"><a href="/wiki/Sam_Mendes" title="Sam Mendes">Sam Mendes</a></span>
 </td>
 <td>1,108.6
 </td>
 <td>1,471.3
 </td>
 <td>150–200
 </td>
 <td>199–265
 </td>
 <td><sup class="reference" id="cite_ref-33"><a href="#cite_note-33"><span class="cite-bracket">[</span>32<span class="cite-bracket">]</span></a></sup><sup class="reference" id="cite_ref-34"><a href="#cite_note-34"><span class="cite-bracket">[</span>33<span class="cite-bracket">]</span></a></sup>
 </td></tr>
 <tr>
 <th scope="row"><i><a href="/wiki/Spectre_(2015_film)" title="Spectre (2015 film)">Spectre</a></i>
 </th>
 <td>2015
 </td>
 <td><span data-sort-value="Craig Daniel !"><a href="/wiki/Daniel_Craig" title="Daniel Craig">Daniel Craig</a></span>
 </td>
 <td><span data-sort-value="Mendes Sam !"><a href="/wiki/Sam_Mendes" title="Sam Mendes">Sam Mendes</a></span>
 </td>
 <td>880.7
 </td>
 <td>1,132.1
 </td>
 <td>245–250<sup class="reference" id="cite_ref-41"><a href="#cite_note-41"><span class="cite-bracket">[</span>b<span class="cite-bracket">]</span></a></sup>
 </td>
 <td>315–321
 </td>
 <td><sup class="reference" id="cite_ref-42"><a href="#cite_note-42"><span class="cite-bracket">[</span>40<span class="cite-bracket">]</span></a></sup>
 </td></tr>
 <tr>
 <th scope="row"><i><a href="/wiki/No_Time_to_Die" title="No Time to Die">No Time to Die</a></i>
 </th>
 <td>2021
 </td>
 <td><span data-sort-value="Craig Daniel !"><a href="/wiki/Daniel_Craig" title="Daniel Craig">Daniel Craig</a></span>
 </td>
 <td><span data-sort-value="Fukunaga Cary Joji !"><a href="/wiki/Cary_Joji_Fukunaga" title="Cary Joji Fukunaga">Cary Joji Fukunaga</a></span>
 </td>
 <td>771.2
 </td>
 <td>867.1
 </td>
 <td>250–301
 </td>
 <td>281–387
 </td>
 <td><sup class="reference" id="cite_ref-BOM_43-0"><a href="#cite_note-BOM-43"><span class="cite-bracket">[</span>41<span class="cite-bracket">]</span></a></sup><sup class="reference" id="cite_ref-NTTD_budget_44-0"><a href="#cite_note-NTTD_budget-44"><span class="cite-bracket">[</span>42<span class="cite-bracket">]</span></a></sup><sup class="reference" id="cite_ref-NTTD_budget2_45-0"><a href="#cite_note-NTTD_budget2-45"><span class="cite-bracket">[</span>43<span class="cite-bracket">]</span></a></sup>
 </td></tr>
 <tr>
 <th colspan="4" scope="col">Total of Eon-produced films
 </th>
 <th>7,612
 </th>
 <th>19,733
 </th>
 <th>1,703<b>–</b>1,809
 </th>
 <th>3,228–3,360
 </th>
 <th>
 </th></tr></tbody></table>]
========== MIDDLE OF OUTPUT TRUNCATED ==========

AI Prompt

now I need to get the title and the url as well as the actor from this table for every movie.

AI Response

Here’s how you can extract that information from the table using BeautifulSoup:

movies = []
for row in table[0].find_all('tr')[2:]:  # Skip header rows
    cols = row.find_all(['th', 'td'])
    
    # Skip the total row at the bottom
    if len(cols) < 3:
        continue
        
    title_cell = cols[0].find('a')
    if title_cell:
        title = title_cell.get_text()
        url = "https://en.wikipedia.org" + title_cell['href']
        actor = cols[2].get_text().strip()
        
        movies.append({
            'title': title,
            'url': url,
            'actor': actor
        })

# Let's see what we got
for movie in movies:
    print(f"Title: {movie['title']}")
    print(f"URL: {movie['url']}")
    print(f"Actor: {movie['actor']}")
    print("---")

This code will: 1. Create an empty list to store movie data 2. Loop through each row in the table (skipping the header rows) 3. Extract the title and URL from the link in the first column 4. Extract the actor name from the third column 5. Store everything in a dictionary 6. Print out the results to verify

Would you like me to explain any part in more detail?

AI Prompt

while this code works, it’s too verbose. Make it more concise and succinct. Also make sure to create a function for extracting the title and link for every row so we can map over the rows. Also extract the actor as well.

AI Response

Here’s a more concise version using functional programming concepts:

def extract_movie_info(row):
    cols = row.find_all(['th', 'td'])
    if len(cols) < 3 or not (title_cell := cols[0].find('a')):
        return None
    return {
        'title': title_cell.get_text(),
        'url': f"https://en.wikipedia.org{title_cell['href']}",
        'actor': cols[2].get_text().strip()
    }

movies = list(filter(None, map(extract_movie_info, table[0].find_all('tr')[2:])))

# Verify (optional)
for m in movies: print(f"{m['title']} ({m['actor']})")

This version: 1. Creates a single function to handle all extraction logic 2. Uses map to apply the function to all rows 3. Uses filter to remove any None values (from header/footer rows) 4. Uses the walrus operator (:=) to combine the existence check with assignment 5. Uses f-strings for cleaner string formatting

Would you like me to explain any part of this more concise version?

from fastcore.utils import L
movies = L(table[0].find_all('tr')[2:-1])
def extract_movie_info(row):
    cols = row.find_all(['th', 'td'])
    link = row.find('th', scope="row").find('a')
    return {
        "title": link.get_text(),
        "url": f"https://en.wikipedia.org{link['href']}",
        "actor": cols[2].get_text().strip()
    } if link else None
extract_movie_info(movies[0])
{'title': 'Dr. No',
 'url': 'https://en.wikipedia.org/wiki/Dr._No_(film)',
 'actor': 'Sean Connery'}
movie_details = movies.map(extract_movie_info).filter()
x = movie_details[-1]
r = httpx.get(x["url"])
r.text
'<!DOCTYPE html>\n<html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available" lang="en" dir="ltr">\n<head>\n<meta charset="UTF-8">\n<title>No Time to Die - Wikipedia</title>\n<script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )enwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split(\'%2C\').forEach(function(pref){className=className.replace(new RegExp(\'(^| )\'+pref.replace(/-clientpref-\\w+$|[^\\w-]+/g,\'\')+\'-clientpref-\\\\w+( |$)\'),\'$1\'+pref+\'$2\');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy",\n"wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"416c0c63-9c8e-4d6d-85bb-4ac9f0e4f62a","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"No_Time_to_Die","wgTitle":"No Time to Die","wgCurRevisionId":1269752929,"wgRevisionId":1269752929,"wgArticleId":38042908,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["IMDb ID (Cite Mojo) different from Wikidata","The Numbers ID different from Wikidata","CS1 maint: bot: original URL status unknown","CS1 Spanish-language sources (es)","Wikipedia articles incorporating a citation from the ODNB","CS1 Brazilian Portuguese-language sources (pt-br)","CS1 maint: archived copy as title","CS1 Italian-language sources (it)","Webarchive template wayback links","CS1 French-language sources (fr)","Articles with short description",\n"Short description is different from Wikidata","Good articles","Use British English from September 2024","Use dmy dates from September 2024","Template film date with 3 release dates","Pages using multiple image with auto scaled images","Commons category link from Wikidata","Official website different in Wikidata and Wikipedia","2021 films","James Bond films","2021 3D films","2020s American films","2020s British films","2020s English-language films","2020s spy action films","4DX films","American action drama films","American action thriller films","American sequel films","American spy action films","American spy drama films","American spy thriller films","Films about biological weapons","British action drama films","British action thriller films","British sequel films","British spy action films","British spy drama films","British spy thriller films","Eon Productions films","Films about bioterrorism","Films about the Central Intelligence Agency","Films about MI6",\n"Films about mother–daughter relationships","Films about terrorism","Films directed by Cary Joji Fukunaga","Films postponed due to the COVID-19 pandemic","Films produced by Barbara Broccoli","Films produced by Michael G. Wilson","Films scored by Hans Zimmer","Films set in 2015","Films set in 2020","Films set in Basilicata","Films set in Jamaica","Films set in London","Films set in Norway","Films set in Santiago de Cuba","Films set in the Pacific Ocean","Films'
========== TRUNCATED ==========
'ats.wikimedia.org/#/en.wikipedia.org">Statistics</a></li>\n\t<li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Cookie statement</a></li>\n\t<li id="footer-places-mobileview"><a href="//en.m.wikipedia.org/w/index.php?title=No_Time_to_Die&amp;mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li>\n</ul>\n\n\t<ul id="footer-icons" class="noprint">\n\t<li id="footer-copyrightico"><a href="https://wikimediafoundation.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/static/images/footer/wikimedia-button.svg" width="84" height="29" alt="Wikimedia Foundation" loading="lazy"></a></li>\n\t<li id="footer-poweredbyico"><a href="https://www.mediawiki.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/w/resources/assets/poweredby_mediawiki.svg" alt="Powered by MediaWiki" width="88" height="31" loading="lazy"></a></li>\n</ul>\n\n</footer>\n\n\t\t</div>\n\t</div> \n</div> \n<div class="vector-settings" id="p-dock-bottom">\n\t<ul></ul>\n</div><script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.eqiad.main-6ffdbbbcbf-lbkk7","wgBackendResponseTime":228,"wgPageParseReport":{"limitreport":{"cputime":"2.234","walltime":"2.493","ppvisitednodes":{"value":16075,"limit":1000000},"postexpandincludesize":{"value":641866,"limit":2097152},"templateargumentsize":{"value":27476,"limit":2097152},"expansiondepth":{"value":24,"limit":100},"expensivefunctioncount":{"value":10,"limit":500},"unstrip-depth":{"value":1,"limit":20},"unstrip-size":{"value":981193,"limit":5000000},"entityaccesscount":{"value":1,"limit":400},"timingprofile":["100.00% 2216.187      1 -total"," 69.19% 1533.318      2 Template:Reflist"," 33.14%  734.415    138 Template:Cite_web"," 19.35%  428.869     89 Template:Cite_news","  4.69%  103.879      1 Template:Infobox_film","  3.74%   82.975      1 Template:Infobox","  3.71%   82.171      4 Template:Navbox","  3.38%   74.798      1 Template:Short_description","  3.33%   73.706      1 Template:James_Bond_films","  3.01%   66.618     19 Template:Main_other"]},"scribunto":{"limitreport-timeusage":{"value":"1.465","limit":"10.000"},"limitreport-memusage":{"value":10843705,"limit":52428800},"limitreport-profile":[["MediaWiki\\\\Extension\\\\Scribunto\\\\Engines\\\\LuaSandbox\\\\LuaSandboxCallback::callParserFunction","240","16.2"],["dataWrapper \\u003Cmw.lua:672\\u003E","200","13.5"],["?","160","10.8"],["recursiveClone \\u003CmwInit.lua:45\\u003E","120","8.1"],["MediaWiki\\\\Extension\\\\Scribunto\\\\Engines\\\\LuaSandbox\\\\LuaSandboxCallback::match","100","6.8"],["MediaWiki\\\\Extension\\\\Scribunto\\\\Engines\\\\LuaSandbox\\\\LuaSandboxCallback::preprocess","60","4.1"],["type","60","4.1"],["init \\u003CModule:Citation/CS1/Date_validation\\u003E","40","2.7"],["MediaWiki\\\\Extension\\\\Scribunto\\\\Engines\\\\LuaSandbox\\\\LuaSandboxCallback::anchorEncode","40","2.7"],["\\u003Cmw.lua:694\\u003E","40","2.7"],["[others]","420","28.4"]]},"cachereport":{"origin":"mw-web.eqiad.main-6ffdbbbcbf-dfzcb","timestamp":"20250116183916","ttl":3600,"transientcontent":true}}});});</script>\n<script type="application/ld+json">{"@context":"https:\\/\\/schema.org","@type":"Article","name":"No Time to Die","url":"https:\\/\\/en.wikipedia.org\\/wiki\\/No_Time_to_Die","sameAs":"http:\\/\\/www.wikidata.org\\/entity\\/Q21534241","mainEntity":"http:\\/\\/www.wikidata.org\\/entity\\/Q21534241","author":{"@type":"Organization","name":"Contributors to Wikimedia projects"},"publisher":{"@type":"Organization","name":"Wikimedia Foundation, Inc.","logo":{"@type":"ImageObject","url":"https:\\/\\/www.wikimedia.org\\/static\\/images\\/wmf-hor-googpub.png"}},"datePublished":"2012-12-27T23:33:31Z","dateModified":"2025-01-16T05:47:28Z","image":"https:\\/\\/upload.wikimedia.org\\/wikipedia\\/en\\/f\\/fe\\/No_Time_to_Die_poster.jpg","headline":"2021 film by Cary Joji Fukunaga"}</script>\n</body>\n</html>'
========== MIDDLE OF OUTPUT TRUNCATED ==========
soup = bs4.BeautifulSoup(r.text, 'html.parser')

soup
<!DOCTYPE html>

<html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available" dir="ltr" lang="en">
<head>
<meta charset="utf-8"/>
<title>No Time to Die - Wikipedia</title>
<script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )enwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy",
"wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"416c0c63-9c8e-4d6d-85bb-4ac9f0e4f62a","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"No_Time_to_Die","wgTitle":"No Time to Die","wgCurRevisionId":1269752929,"wgRevisionId":1269752929,"wgArticleId":38042908,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["IMDb ID (Cite Mojo) different from Wikidata","The Numbers ID different from Wikidata","CS1 maint: bot: original URL status unknown","CS1 Spanish-language sources (es)","Wikipedia articles incorporating a citation from the ODNB","CS1 Brazilian Portuguese-language sources (pt-br)","CS1 maint: archived copy as title","CS1 Italian-language sources (it)","Webarchive template wayback links","CS1 French-language sources (fr)","Articles with short description",
"Short description is different from Wikidata","Good articles","Use British English from September 2024","Use dmy dates from September 2024","Template film date with 3 release dates","Pages using multiple image with auto scaled images","Commons category link from Wikidata","Official website different in Wikidata and Wikipedia","2021 films","James Bond films","2021 3D films","2020s American films","2020s British films","2020s English-language films","2020s spy action films","4DX films","American action drama films","American action thriller films","American sequel films","American spy action films","American spy drama films","American spy thriller films","Films about biological weapons","British action drama films","British action thriller films","British sequel films","British spy action films","British spy drama films","British spy thriller films","Eon Productions films","Films about bioterrorism","Films about the Central Intelligence Agency","Films about MI6",
"Films about mother–daughter relationships","Films about terrorism","Films directed by Cary Joji Fukunaga","Films postponed due to the COVID-19 pandemic","Films produced by Barbara Broccoli","Films produced by Michael G. Wilson","Films scored by Hans Zimmer","Films set in 2015","Films set in 2020","Films set in Basilicata","Films set in Jamaica","Films set in London","Films set in Norway","Films set in Santiago de Cuba","Films set in the Pacific Ocean","Films set in Washington, D.C
========== TRUNCATED ==========
"><a href="https://developer.wikimedia.org">Developers</a></li>
<li id="footer-places-statslink"><a href="https://stats.wikimedia.org/#/en.wikipedia.org">Statistics</a></li>
<li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Cookie statement</a></li>
<li id="footer-places-mobileview"><a class="noprint stopMobileRedirectToggle" href="//en.m.wikipedia.org/w/index.php?title=No_Time_to_Die&amp;mobileaction=toggle_view_mobile">Mobile view</a></li>
</ul>
<ul class="noprint" id="footer-icons">
<li id="footer-copyrightico"><a class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled" href="https://wikimediafoundation.org/"><img alt="Wikimedia Foundation" height="29" loading="lazy" src="/static/images/footer/wikimedia-button.svg" width="84"/></a></li>
<li id="footer-poweredbyico"><a class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled" href="https://www.mediawiki.org/"><img alt="Powered by MediaWiki" height="31" loading="lazy" src="/w/resources/assets/poweredby_mediawiki.svg" width="88"/></a></li>
</ul>
</footer>
</div>
</div>
</div>
<div class="vector-settings" id="p-dock-bottom">
<ul></ul>
</div><script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.eqiad.main-6ffdbbbcbf-lbkk7","wgBackendResponseTime":228,"wgPageParseReport":{"limitreport":{"cputime":"2.234","walltime":"2.493","ppvisitednodes":{"value":16075,"limit":1000000},"postexpandincludesize":{"value":641866,"limit":2097152},"templateargumentsize":{"value":27476,"limit":2097152},"expansiondepth":{"value":24,"limit":100},"expensivefunctioncount":{"value":10,"limit":500},"unstrip-depth":{"value":1,"limit":20},"unstrip-size":{"value":981193,"limit":5000000},"entityaccesscount":{"value":1,"limit":400},"timingprofile":["100.00% 2216.187      1 -total"," 69.19% 1533.318      2 Template:Reflist"," 33.14%  734.415    138 Template:Cite_web"," 19.35%  428.869     89 Template:Cite_news","  4.69%  103.879      1 Template:Infobox_film","  3.74%   82.975      1 Template:Infobox","  3.71%   82.171      4 Template:Navbox","  3.38%   74.798      1 Template:Short_description","  3.33%   73.706      1 Template:James_Bond_films","  3.01%   66.618     19 Template:Main_other"]},"scribunto":{"limitreport-timeusage":{"value":"1.465","limit":"10.000"},"limitreport-memusage":{"value":10843705,"limit":52428800},"limitreport-profile":[["MediaWiki\\Extension\\Scribunto\\Engines\\LuaSandbox\\LuaSandboxCallback::callParserFunction","240","16.2"],["dataWrapper \u003Cmw.lua:672\u003E","200","13.5"],["?","160","10.8"],["recursiveClone \u003CmwInit.lua:45\u003E","120","8.1"],["MediaWiki\\Extension\\Scribunto\\Engines\\LuaSandbox\\LuaSandboxCallback::match","100","6.8"],["MediaWiki\\Extension\\Scribunto\\Engines\\LuaSandbox\\LuaSandboxCallback::preprocess","60","4.1"],["type","60","4.1"],["init \u003CModule:Citation/CS1/Date_validation\u003E","40","2.7"],["MediaWiki\\Extension\\Scribunto\\Engines\\LuaSandbox\\LuaSandboxCallback::anchorEncode","40","2.7"],["\u003Cmw.lua:694\u003E","40","2.7"],["[others]","420","28.4"]]},"cachereport":{"origin":"mw-web.eqiad.main-6ffdbbbcbf-dfzcb","timestamp":"20250116183916","ttl":3600,"transientcontent":true}}});});</script>
<script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"Article","name":"No Time to Die","url":"https:\/\/en.wikipedia.org\/wiki\/No_Time_to_Die","sameAs":"http:\/\/www.wikidata.org\/entity\/Q21534241","mainEntity":"http:\/\/www.wikidata.org\/entity\/Q21534241","author":{"@type":"Organization","name":"Contributors to Wikimedia projects"},"publisher":{"@type":"Organization","name":"Wikimedia Foundation, Inc.","logo":{"@type":"ImageObject","url":"https:\/\/www.wikimedia.org\/static\/images\/wmf-hor-googpub.png"}},"datePublished":"2012-12-27T23:33:31Z","dateModified":"2025-01-16T05:47:28Z","image":"https:\/\/upload.wikimedia.org\/wikipedia\/en\/f\/fe\/No_Time_to_Die_poster.jpg","headline":"2021 film by Cary Joji Fukunaga"}</script>
</body>
</html>
========== MIDDLE OF OUTPUT TRUNCATED ==========
plot_heading = soup.find('h2', {'id': 'Plot'})

plot_heading
<h2 id="Plot">Plot</h2>
plot_text = []
current = plot_heading.parent.find_next_sibling()
while current and current.name != 'div':
    if current.name == 'p':
        plot_text.append(current.get_text().strip())
    current = current.find_next_sibling()
    
plot_text = ' '.join(plot_text)

plot_text
'A young Madeleine Swann witnesses her mother\'s murder by Lyutsifer Safin, whose family was murdered by Swann\'s father, Mr. White, under orders from Ernst Stavro Blofeld. Swann shoots Safin and flees, falling into a frozen lake. Safin rescues her. Decades later, after Blofeld\'s arrest,[a] Swann travels to Matera with James Bond and persuades him to visit his ex-lover Vesper Lynd\'s grave to help get over her. While Bond visits the tomb, it explodes, and Bond is attacked by SPECTRE operatives led by Primo, a mercenary with a bionic eye. While fleeing with Bond, Swann receives a congratulatory phone call from Blofeld. Bond accuses Swann of betraying him and sends her away, saying they will never meet again. Five years later, Spectre agents infiltrate an MI6 laboratory to kidnap scientist Valdo Obruchev, who secretly works for Safin, and steal Project Heracles, a programmable DNA-targeting nanobot bioweapon developed under M\'s oversight. Retired in Jamaica, Bond is asked by CIA ally Felix Leiter and State Department agent Logan Ash to extract Obruchev from a Spectre party in Cuba. Bond accepts after Nomi, his successor as Agent 007, warns him not to interfere with her extraction of Obruchev and puts him in contact with M, who refuses to explain Heracles. Bond infiltrates the Spectre party with Leiter\'s Cuban agent Paloma. Blofeld, overseeing the party from Belmarsh prison through Primo\'s bionic eye, deploys a nanobot mist to kill Bond, but Obruchev programmed the nanobots under Safin\'s orders to kill the Spectre members instead. Bond takes Obruchev to Ash and Leiter aboard a trawler. As Bond questions Obruchev about Heracles and Blofeld, Obruchev looks to Ash, exposing him as his co-conspirator. Ash shoots Leiter and traps him with Bond below deck, then triggers explosives to sink the ship as he flees with Obruchev. Leiter dies, but Bond escapes. In London, Bond seeks to interrogate Blofeld in Belmarsh, but Blofeld will only speak to his psychiatrist, Swann. Safin coerces Swann into infecting herself with nanobots to assassinate Blofeld. MI6 has Bond visit Blofeld with Swann. Bond touches Swann, unknowingly infecting himself with the nanobots. Swann, too distressed to face Blofeld, tells Bond she is going "home." Blofeld tells Bond he planned the ambush at Vesper\'s grave to make Bond believe Swann betrayed him. Bond briefly chokes Blofeld, unknowingly killing him with Safin\'s nanobots. Bond reconciles with Swann at her childhood home in Norway and meets her five-year-old daughter Mathilde, who Swann insists is not Bond\'s child, despite their resemblance. Swann shares intelligence that her father gathered about Safin and his family\'s island. MI6 alerts Bond to Ash\'s approach. Ash and his thugs pursue Bond, Mathilde, and Swann into a forest. Bond orders Swann and Mathilde to hide while he confronts Ash over Leiter\'s death. He kills Ash and his men, but Safin kidnaps Swann and Mathilde. Q provides Bond and Nomi with a submersible glider to infiltrate Safin\'s nanobot factory headquarters, where they plan to kill Obruchev and Safin and rescue Swann and Mathilde. Bond confronts Safin and kills his bodyguards, but Safin flees with Mathilde. Swann escapes Primo and reunites with Bond, and the pair find Mathilde, whom Safin abandoned. Nomi kicks Obruchev into an acid pool and escorts Swann and Mathilde off the island. Bond convinces M to authorize a missile strike on the facility from HMS Dragon, and kills Primo and Safin\'s remaining men. Safin reappears, shoots Bond repeatedly, and breaks open a vial of nanobots programmed to kill Swann and Mathilde. Despite his injuries, Bond shoots Safin dead and opens the facility\'s blast doors but remains on the island to ensure that the nanobots cannot harm Swann and Mathilde. Bond radios Swann to say goodbye and express his love for her and Mathilde. Swann confirms that Mathilde is his daughter, and Bond assures her that he knew all along. Bond is killed as missiles destroy the facility. At MI6, M, Moneypenny, Nomi, Q, and Bill Tanner drink to Bond\'s memory. Driving Mathilde to Matera, Swann begins to tell her about her father, James Bond.'
def get_plot_text(url):
    r = httpx.get(url)
    soup = bs4.BeautifulSoup(r.text, 'html.parser')
    
    plot_heading = soup.find('h2', {'id': 'Plot'})
    
    plot_text = []
    current = plot_heading.parent.find_next_sibling()
    while current and current.name != 'div':
        if current.name == 'p':
            plot_text.append(current.get_text().strip())
        current = current.find_next_sibling()
        
    return ' '.join(plot_text)
get_plot_text(movie_details[0]["url"])
"John Strangways, the Station Chief of MI6 in Jamaica, is murdered, along with his secretary Mary, by a trio of assassins before his home is ransacked. After MI6 loses radio contact with the station, James Bond is found playing baccarat in a private London club; Sylvia Trench is one of the other players. M, the head of MI6, assigns Bond to go to Jamaica; Strangways was helping the CIA investigate radio jamming of rocket launches from Cape Canaveral. M also confiscates Bond's Beretta handgun, which he had used for ten years, replacing it with a Walther PPK 7.65\xa0mm. At Bond's home he finds Sylvia Trench, a brief encounter as he is on the way to his flight. Landing in Jamaica, Bond accepts a ride from an enemy agent. He overpowers the agent, who  kills himself by biting into a cyanide-laced cigarette. Bond arranges with principal secretary Pleydell-Smith to meet those who saw Strangways last, including Professor Dent. At Strangway's home, Bond finds a receipt from Dent and a picture of Strangways and Quarrel, who tailed Bond from the airport earlier. Bond finds Quarrel, they fight, and CIA agent Felix Leiter stops it, explaining that Quarrel worked with him and Strangways looking for the radio jamming source. One island, Crab Key, is generally off limits, controlled by Dr. No, with a bauxite mine; Quarrel and Strangways got rock samples at night. Bond visits Dent, who claims the samples were iron pyrite. Dent travels to Crab Key and is given a tarantula to kill Bond. However Bond kills the spider. He arranges to meet Pleydell-Smith's corrupt secretary Miss Taro. On the drive to her home, the assassins try to run Bond off the road, but themselves crash and die. After an intimate interlude, Bond has Taro arrested. He waits in her home. Dent arrives to kill Bond and is killed by Bond. During the night Quarrel takes Bond to Crab Key. The next morning they meet Honey Ryder, a shell diver. Armed guards search for them. At nightfall the group encounter a flame tank disguised as a dragon to deter locals, which kills Quarrel. Bond and Ryder are captured. Radioactive from the contaminated swamp, both are put through a decontamination process. Taken to comfortable suites with clothes in their sizes, they drink drugged coffee and sleep. Upon awakening, the pair are escorted to dine with the base's owner, Dr Julius No: a Chinese-German scientist with prosthetic metal hands due to radiation exposure. No was a member of a Chinese tong, until he stole $10\xa0million in gold, and now works for SPECTRE (Special Executive for Counter-intelligence, Terrorism, Revenge, and Extortion). The radio jamming will disrupt a Project Mercury space launch at Cape Canaveral. When Bond refuses to join SPECTRE, No has Ryder taken away and Bond beaten. Bond escapes his cell through an air vent, disguises himself as a worker, and infiltrates the base's control centre. Bond overloads the nuclear pool reactor as the launch commences. Dr. No fights him, but falls into the reactor pool and is boiled to death. As the base's personnel evacuate, Bond frees Ryder before the two escape the island by boat, moments before the base is destroyed. Felix finds the pair adrift at sea after their boat runs out of fuel, and has them towed to safety by a Royal Navy ship. As Ryder passionately kisses him, Bond lets go of the towrope to embrace her."

AI Prompt

Now I want to map over all of the movie_details and get a new list of dicts with an additional plot key with the plot in it.

AI Response

Here’s a concise way to add plot information to all movies using fastcore’s L class:

def add_plot(movie):
    return {**movie, "plot": get_plot_text(movie["url"])}

movies_with_plots = movie_details.map(add_plot)

This does: 1. Creates a function that adds plot to a movie dict using dictionary unpacking 2. Maps this function over all movies using fastcore’s L class

Note: This will make multiple HTTP requests, one for each movie. You might want to add a small delay between requests or implement error handling if needed. Would you like me to show you how to add those features?

def add_plot(movie):
    return {**movie, "plot": get_plot_text(movie["url"])}
add_plot(movie_details[0])
{'title': 'Dr. No',
 'url': 'https://en.wikipedia.org/wiki/Dr._No_(film)',
 'actor': 'Sean Connery',
 'plot': "John Strangways, the Station Chief of MI6 in Jamaica, is murdered, along with his secretary Mary, by a trio of assassins before his home is ransacked. After MI6 loses radio contact with the station, James Bond is found playing baccarat in a private London club; Sylvia Trench is one of the other players. M, the head of MI6, assigns Bond to go to Jamaica; Strangways was helping the CIA investigate radio jamming of rocket launches from Cape Canaveral. M also confiscates Bond's Beretta handgun, which he had used for ten years, replacing it with a Walther PPK 7.65\xa0mm. At Bond's home he finds Sylvia Trench, a brief encounter as he is on the way to his flight. Landing in Jamaica, Bond accepts a ride from an enemy agent. He overpowers the agent, who  kills himself by biting into a cyanide-laced cigarette. Bond arranges with principal secretary Pleydell-Smith to meet those who saw Strangways last, including Professor Dent. At Strangway's home, Bond finds a receipt from Dent and a picture of Strangways and Quarrel, who tailed Bond from the airport earlier. Bond finds Quarrel, they fight, and CIA agent Felix Leiter stops it, explaining that Quarrel worked with him and Strangways looking for the radio jamming source. One island, Crab Key, is generally off limits, controlled by Dr. No, with a bauxite mine; Quarrel and Strangways got rock samples at night. Bond visits Dent, who claims the samples were iron pyrite. Dent travels to Crab Key and is given a tarantula to kill Bond. However Bond kills the spider. He arranges to meet Pleydell-Smith's corrupt secretary Miss Taro. On the drive to her home, the assassins try to run Bond off the road, but themselves crash and die. After an intimate interlude, Bond has Taro arrested. He waits in her home. Dent arrives to kill Bond and is killed by Bond. During the night Quarrel takes Bond to Crab Key. The next morning they meet Honey Ryder, a shell diver. Armed guards search for them. At nightfall the group encounter a flame tank disguised as a dragon to deter locals, which kills Quarrel. Bond and Ryder are captured. Radioactive from the contaminated swamp, both are put through a decontamination process. Taken to comfortable suites with clothes in their sizes, they drink drugged coffee and sleep. Upon awakening, the pair are escorted to dine with the base's owner, Dr Julius No: a Chinese-German scientist with prosthetic metal hands due to radiation exposure. No was a member of a Chinese tong, until he stole $10\xa0million in gold, and now works for SPECTRE (Special Executive for Counter-intelligence, Terrorism, Revenge, and Extortion). The radio jamming will disrupt a Project Mercury space launch at Cape Canaveral. When Bond refuses to join SPECTRE, No has Ryder taken away and Bond beaten. Bond escapes his cell through an air vent, disguises himself as a worker, and infiltrates the base's control centre. Bond overloads the nuclear pool reactor as the launch commences. Dr. No fights him, but falls into the reactor pool and is boiled to death. As the base's personnel evacuate, Bond frees Ryder before the two escape the island by boat, moments before the base is destroyed. Felix finds the pair adrift at sea after their boat runs out of fuel, and has them towed to safety by a Royal Navy ship. As Ryder passionately kisses him, Bond lets go of the towrope to embrace her."}
from fastcore.parallel import parallel
parallel?
Signature:
parallel(
    f,
    items,
    *args,
    n_workers=64,
    total=None,
    progress=None,
    pause=0,
    method=None,
    threadpool=False,
    timeout=None,
    chunksize=1,
    **kwargs,
)
Docstring: Applies `func` in parallel to `items`, using `n_workers`
File:      /usr/local/lib/python3.11/site-packages/fastcore/parallel.py
Type:      function
movie_details2 = parallel(add_plot, movie_details, n_workers=10, threadpool=True)

movie_details2
(#25) [{'title': 'Dr. No', 'url': 'https://en.wikipedia.org/wiki/Dr._No_(film)', 'actor': 'Sean Connery', 'plot': "John Strangways, the Station Chief of MI6 in Jamaica, is murdered, along with his secretary Mary, by a trio of assassins before his home is ransacked. After MI6 loses radio contact with the station, James Bond is found playing baccarat in a private London club; Sylvia Trench is one of the other players. M, the head of MI6, assigns Bond to go to Jamaica; Strangways was helping the CIA investigate radio jamming of rocket launches from Cape Canaveral. M also confiscates Bond's Beretta handgun, which he had used for ten years, replacing it with a Walther PPK 7.65\xa0mm. At Bond's home he finds Sylvia Trench, a brief encounter as he is on the way to his flight. Landing in Jamaica, Bond accepts a ride from an enemy agent. He overpowers the agent, who  kills himself by biting into a cyanide-laced cigarette. Bond arranges with principal secretary Pleydell-Smith to meet those who saw Strangways last, including Professor Dent. At Strangway's home, Bond finds a receipt from Dent and a picture of Strangways and Quarrel, who tailed Bond from the airport earlier. Bond finds Quarrel, they fight, and CIA agent Felix Leiter stops it, explaining that Quarrel worked with him and Strangways looking for the radio jamming source. One island, Crab Key, is generally off limits, controlled by Dr. No, with a bauxite mine; Quarrel and Strangways got rock samples at night. Bond visits Dent, who claims the samples were iron pyrite. Dent travels to Crab Key and is given a tarantula to kill Bond. However Bond kills the spider. He arranges to meet Pleydell-Smith's corrupt secretary Miss Taro. On the drive to her home, the assassins try to run Bond off the road, but themselves crash and die. After an intimate interlude, Bond has Taro arrested. He waits in her home. Dent arrives to kill Bond and is killed by Bond. During the night Quarrel takes Bond to Crab Key. The next morning they meet Honey Ryder, a shell diver. Armed guards search for them. At nightfall the group encounter a flame tank disguised as a dragon to deter locals, which kills Quarrel. Bond and Ryder are captured. Radioactive from the contaminated swamp, both are put through a decontamination process. Taken to comfortable suites with clothes in their sizes, they drink drugged coffee and sleep. Upon awakening, the pair are escorted to dine with the base's owner, Dr Julius No: a Chinese-German scientist with prosthetic metal hands due to radiation exposure. No was a member of a Chinese tong, until he stole $10\xa0million in gold, and now works for SPECTRE (Special Executive for Counter-intelligence, Terrorism, Revenge, and Extortion). The radio jamming will disrupt a Project Mercury space launch at Cape Canaveral. When Bond refuses to join SPECTRE, No has Ryder taken away and Bond beaten. Bond escapes his cell through an air vent, disguises himself as a worker, and infiltrates the base's control centre. Bond overloads the nuclear pool reactor as the launch commences. Dr. No fights him, but falls into the reactor pool and is boiled to death. As the base's personnel evacuate, Bond frees Ryder before the two escape the island by boat, moments before the base is destroyed. Felix finds the pair adrift at sea after their boat runs out of fuel, and has them towed to safety by a Royal Navy ship. As Ryder passionately kisses him, Bond lets go of the towrope to embrace her."},{'title': 'From Russia with Love', 'url': 'https://en.wikipedia.org/wiki/From_Russia_with_Love_(film)', 'actor': 'Sean Connery', 'plot': "International criminal organisation SPECTRE seeks revenge against MI6 agent James Bond for the death of their agent Dr. No in Jamaica.[Notes 1] SPECTRE's chief planner, Czechoslovak chess grandmaster Kronsteen, devises a plan to lure Bond into a trap, using as bait the prospects of procuring a Lektor cryptography device from the Soviet Union's consulate in Istanbul. SPECTRE operative Rosa Klebb, a former head of SMERSH (Soviet counter-intelligence), is assigned to oversee the missio
========== TRUNCATED ==========
e_Another_Day', 'actor': 'Pierce Brosnan', 'plot': 'MI6 agent James Bond infiltrates a North Korean military base where Colonel Tan-Sun Moon is trading weapons for African conflict diamonds. After Moon\'s right-hand man Zao receives notification of Bond\'s real identity, Moon attempts to kill Bond and a hovercraft chase ensues, ending with Moon\'s craft tumbling over a waterfall. Bond is captured by North Korean soldiers and imprisoned by the Colonel\'s father, General Moon. After fourteen months of captivity and torture at the hands of the Korean People\'s Army, Bond is traded for Zao in a prisoner exchange across the Bridge of No Return. He is sedated and taken to meet M, who informs him that his status as a 00 Agent has been suspended under suspicion of having leaked information under duress to the North Koreans. Bond is convinced that he has been set up by a double agent in the British government. After escaping MI6 custody, he finds himself in Hong Kong, where he learns from Chang, a Chinese agent and old colleague, that Zao is in Cuba. In Havana, Bond meets with NSA agent Giacinta "Jinx" Johnson and follows her to a gene therapy clinic, where patients can have their appearances altered through DNA restructuring. Jinx kills Dr. Alvarez, the leader of the therapy, while Bond locates Zao inside the clinic and fights him. Zao escapes, leaving behind a pendant which leads Bond to a cache of conflict diamonds bearing the crest of the company owned by British billionaire Gustav Graves. Bond learns that Graves only appeared a year prior, apparently discovering a vein of diamonds in Iceland leading to his current wealth and celebrity. At Blades Club in London, Bond meets Graves along with his assistant Miranda Frost, who is also an undercover MI6 agent. After a fencing match that escalates into a claymore duel, Graves invites Bond to Iceland for a scientific demonstration. M restores Bond\'s Double-0 status, and Q issues him an Aston Martin V12 Vanquish with active camouflage. At his ice palace in Iceland, Graves unveils a new orbital mirror satellite Icarus, which is able to focus solar energy on a small area and provide year-round sunshine for agriculture. Frost seduces Bond and Jinx infiltrates Graves\' command centre but is captured by Graves and Zao. Bond rescues her and discovers that Graves is Colonel Moon, who has used the gene therapy technology to change his appearance and amassed his fortune from conflict diamonds as a cover. Bond confronts Graves, but Frost arrives to reveal herself as the traitor who betrayed him in North Korea, forcing Bond to escape from Graves\' facility. He returns in his Vanquish to rescue Jinx, who has been recaptured in the palace. As Graves uses Icarus to melt the ice palace, Zao pursues Bond into the palace using his Jaguar XKR. Bond kills Zao by causing an ice chandelier to fall onto him and revives Jinx after she has almost drowned. Bond and Jinx pursue Graves and Frost to the Korean peninsula and stow away on Graves\' An-124 cargo plane. Graves reveals his identity to his father, and the true purpose of the Icarus satellite: to cut a path through the Korean Demilitarised Zone with concentrated sunlight, allowing North Korean troops to invade South Korea and unite the peninsula. Horrified, General Moon rejects the plan, but Graves murders him. Bond attempts to shoot Graves, but is prevented by a soldier. In their struggle, a gunshot pierces the fuselage, causing the plane to decompress and descend rapidly. Bond and Graves engage in a fistfight, and Jinx attempts to regain control of the plane. Frost attacks Jinx, forcing her to defend herself in a sword duel. After the plane passes through the Icarus beam and is further damaged, Jinx kills Frost. Graves attempts to escape by parachute, but Bond opens the parachute, pulling Graves out of the plane and into one of its engines, disabling the Icarus beam. Bond and Jinx escape from the disintegrating plane in a helicopter from the cargo hold, with Graves\' stash of diamonds. Later, they spend a romantic evening at a Buddhist temple.'}...]
========== MIDDLE OF OUTPUT TRUNCATED ==========
import google.generativeai as genai
import os

genai.configure(api_key=os.environ["GEMINI_API_KEY"])

result = genai.embed_content(
        model="models/text-embedding-004",
        content="What is the meaning of life?")

print(str(result['embedding']))
[-0.010632273, 0.019375853, 0.020965198, 0.0007706437, -0.061464068, 0.014739741, -0.0022759985, 0.013184195, 0.014464715, 0.022593116, 0.02184836, -0.059616957, 0.06032222, -0.047657482, 0.017848385, -0.10987464, -0.0598155, -0.00479664, -0.043298274, -0.05090505, 0.029398112, 0.011642447, 0.04183789, -0.017999396, 0.011026355, 0.049722955, 0.012025892, 0.007331535, 0.01967245, -0.0025621902, 0.028765293, 0.0068937168, 0.0029231338, -0.0002095079, 0.032031864, 0.02518659, -0.032855466, 0.00758291, -0.00011585959, -0.034515556, -0.066151336, 0.03191643, -0.026680378, 0.017334407, -0.025778342, -0.008119435, -0.002431255, -0.009850676, -0.030725427, 0.08225489, 0.036220998, -0.011677602, -0.048477963, 0.026030278, 0.0027632737, -0.036962725, -0.051528536, -0.027265795, 0.04703419, -0.03285586, -0.015140722, -0.003516825, -0.006665491, -0.024252947, -0.031371485, 0.056986455, -0.02846856, 0.009047717, -0.021733612, 0.01993043, -0.016926913, 0.051008012, -0.022356581, 0.05340387, -0.036262874, 0.038486782, 0.00097307086, 0.0058653215, -0.03454564, 0.038883448, -0.020346535, -0.0015010178, 0.050026324, 0.07690296, 0.04075089, 0.031162778, -0.048467305, -0.031640615, -0.050462708, -0.0020114628, 0.028352365, 0.016939064, -0.032321587, -0.017523259, 0.045018278, 0.005056391, -0.08844299, -0.039214693, 0.032369446, 0.013868324, 0.048252415, 0.012212794, -0.0059761675, -0.055453815, 0.059123088, 0.077673666, 0.012595949, -0.030664278, 0.0019445478, -0.04473188, 0.03904732, -0.045189187, 0.005711123, -0.024350755, 0.006020905, -0.056398984, -0.008473793, 0.026584638, -0.019225147, -0.003090118, 0.02925659, 0.037855238, -0.033372607, 0.027388284, 0.058645032, -0.0034353225, -0.00052528176, -0.061926123, -0.047651615, -0.020240242, 0.037042357, -0.101258375, -0.017224912, 0.031264607, -0.029515961, 0.04070285, 0.08155317, -0.02680439, 0.010762277, -0.068192326, 0.010339065, 0.001237995, 0.025081903, 0.025549553, 0.033473987, -0.011019555, 0.025582748, -0.044487614, -0.02351738, -0.019466395, -0.05739292, -0.023219999, 0.06383781, -0.0032941306, 0.0032277782, 0.014958662, 0.037334923, 0.010649138, 0.07434867, -0.024096856, -0.0051036896, -0.05779452, -0.087558694, 0.005070572, -0.059070442, -0.0075670946, 0.020864079, -0.059642896, -0.017373137, 0.010781379, 0.005737636, 0.01155112, -0.051110126, -0.00469127, 0.003082495, 0.021098692, -0.010646007, -0.0075031, 0.01649139, -0.010034379, 0.03665796, -0.02178521, -0.060414966, -0.0110657895, -0.018490821, -0.038217384, -0.008570785, 0.06764553, 0.045524262, 0.028033433, -0.049999256, 0.038643356, -0.001174409, 0.0071052625, -0.0071540354, -0.03563122, 0.040300176, -0.01187511, -0.020187229, 0.034496624, -0.018076168, -0.025241721, -0.03251734, -0.005546835, 0.01218167, 0.001308468, -0.01956061, -0.016109072, 0.033482637, -0.013107253, -0.04336891, 0.017510926, -0.059141196, -0.023261068, 0.025163788, 0.04890369, 0.076442, -0.0016504959, 0.10172619, -0.015871631, -0.023793343, -0.02358568, 0.036539588, -0.06184051, -0.026249573, 0.006468363, -0.031341415, -0.06234132, -0.049488295, -0.018885756, 0.03395302, -0.006009219, -0.031574816, -0.0054155374, -0.033587996, -0.015623983, 0.013743329, 0.06735172, 0.009166206, -0.027008668, 0.053747576, -0.019794546, -0.004977181, -0.0011775235, 0.055169225, 0.031791825, 0.025199965, 0.080965735, 0.0039748563, -0.08897454, -0.027933061, 0.00045005116, -0.013844743, -0.06260468, -0.046366338, -0.029402703, 0.023191761, -0.01076239, 0.0076124803, -0.020023048, 0.039004155, -0.070678934, -0.07069906, -0.02288811, -0.03803117, -0.05004868, -0.018108511, -0.024550572, 0.040691372, -0.05350907, 0.051243976, -0.0021085127, -0.009738572, -0.008890091, -0.015601183, 0.019753162, 0.0053467727, 0.031590473, 0.0041920035, -0.04371269, 0.067351475, -0.019107815, -0.014121782, 0.009763881, 0.031802285, -0.0069985087, 0.013498973, 0.023104675, 0.0006382101, -0.008508383, 0.03777484, 0.008196443, -0.0025804106, -0.033261176, -0.033644095, -0.0039042186, 0.049756225, 0.03194955, 0.018670397, -0.004185749, 0.01654144, 0.06362886, -0.08167434, 0.004465523, 0.005431271
========== TRUNCATED ==========
9716, 0.07723543, 0.013161921, 0.035233274, 0.013950026, -0.026914261, -0.0012491347, 0.022125386, 0.06322952, 0.026747808, 0.016557682, 0.0026654843, 0.018403852, -0.002208754, -0.0043939324, 0.021411125, -0.0720841, -0.014162335, 0.009017187, 0.009589008, 0.013714266, -0.013205313, 0.055074606, 0.0135510815, -0.009647225, -0.0073859296, -0.015533789, 0.041406598, -0.029964559, -0.004557068, 0.042442538, 0.003949693, -0.060314845, -0.0485521, -0.008145191, -0.0008701478, 0.026269091, 0.064659014, -0.0014519938, 0.07755499, 0.012390666, 0.0009994709, 0.010512895, -0.0278039, -0.007720246, -0.017693883, -0.048093677, 0.048450127, -0.0084898835, 0.033827696, 0.012179157, 0.0439037, 0.019806726, -0.0033815033, 0.055004198, -0.010644163, 0.06983634, -0.0012867257, 0.116212435, 0.0018561919, -0.03540732, 0.018552277, -0.014596015, 0.007995569, 0.02062322, -0.013589375, 0.013323644, 0.058206026, 0.014310659, 0.009776701, 0.022025304, 0.043452848, 0.007224779, -0.005841782, 0.07922995, 0.029124206, 0.027332257, 0.011426645, 0.0610715, 0.033370003, -0.0032318854, 0.032962296, 0.044215627, -0.0019828111, -0.015901793, -0.00029608337, 0.013392526, -0.009583505, 0.101087496, 0.029640157, -0.04264001, 0.028663691, 0.0012885618, -0.00042037942, -0.05097693, 0.046501413, 0.034346417, -0.03722956, 0.030485353, -0.028618095, -0.014943351, 0.024176005, 0.0059531713, -0.035492424, 0.04719729, -0.022705767, -0.004888659, 0.013763481, -0.006877845, 0.039462008, -0.022432147, -0.024738846, -0.0030126623, 0.014878597, 0.047142185, -0.028536918, -0.0019756483, -0.024875728, -0.049604762, 0.0076611727, 0.0125418445, 0.06991834, 0.03057351, -0.0378383, -0.01601651, 0.023397712, -0.006465213, -0.016750913, -0.028563995, 0.013968368, 0.04284747, 0.013723971, -0.038290635, 0.0062841102, -0.016612995, 0.0060477066, 0.0071878443, 0.017012084, 0.026105886, -0.029898316, -0.0034338816, 0.022605129, -0.031070229, -0.014588787, -0.05051719, 0.011172559, -0.009865424, -0.0006022246, -0.050201006, 0.010974502, 0.068753, -0.06411741, 0.021827834, -0.079100326, 0.027182067, -0.0049233013, -0.00854883, 0.042056426, -0.041176684, -0.043345083, 0.007900265, 0.03339074, 0.009065677, -0.11376203, 0.026648033, -0.02173746, -0.056054536, -0.05019967, 0.02505995, -0.073714115, 0.00041753243, 0.046410866, -0.00787225, -0.04326591, 0.052950215, -0.020633917, 0.0053053875, 0.038686555, 0.0076096985, -0.044483498, 0.01734079, 0.050843734, 0.041709274, -0.032848667, 0.06583798, -0.0462481, -0.019906212, 0.062381882, 0.010934914, -0.053675517, -0.033560812, 0.027787214, 0.003391649, 0.019972153, 0.0442223, -0.06779605, -0.057355773, -0.00908375, -0.031183494, 0.07079641, -0.020006215, -0.024294054, -0.016699182, 0.0010443482, 0.018393427, 0.032058917, 0.04007311, -0.013608359, -0.02647255, -0.023104627, 0.07973177, 0.0143912, -0.00773088, -0.0105773965, 0.009673522, 0.030086972, 0.021788783, 0.0215211, -0.0021278693, 0.01382664, -0.05028589, 0.0037969938, -0.019241702, -0.055900373, 0.047401533, 0.047825735, -0.008378417, -0.021368338, -0.0029360335, -0.023776283, -0.030378696, 0.0042622155, -0.04370354, 0.046717755, 0.057218548, -0.07626953, 0.06840914, -0.013551472, -0.04081457, 0.0024602, -0.019596782, -0.034115944, 0.022949563, 0.08198656, 0.010917071, 0.012808682, -0.0024835565, -0.06742202, 0.035741765, -0.007581535, 0.01281636, 0.05919395, 0.019007294, -0.057466842, 0.031478077, 0.011478408, 0.0197156, 0.03522307, -0.0039083306, 0.009473974, -0.061164707, -0.010365365, 0.020075476, 0.025542602, -0.030813247, -0.050739173, -0.0037222796, -0.0025314046, 0.03607207, 0.085864864, 0.030587368, -0.011790973, 0.02897135, 0.009813614, 0.0036375853, 0.01939262, -0.012913535, 0.032164395, -0.012496243, 0.053962503, -0.0030092895, -0.013271072, -0.069150545, -0.014564991, 0.01531648, -0.0493518, -0.026759734, -0.030610656, -0.022655917, -0.09071128, -0.051921394, -0.014159941, 0.086534575, 0.039204597, -0.018607471, -0.023076432, 0.016071219, 0.08200573, 0.036090653, -0.0029250141, 0.032362826, -0.014467054, 0.013964356, -0.075049624, 0.047506943, -0.007153866, -0.028534686]

========== MIDDLE OF OUTPUT TRUNCATED ==========
result = genai.embed_content(
        model="models/text-embedding-004",
        content=movie_details2[0]["plot"])

print(str(result['embedding']))
[0.036159527, -0.0041011735, -0.0069002705, 0.018425733, 0.0353543, 0.033877883, 0.096829414, 0.039409623, -0.0005220023, 0.022444148, -0.007817863, 0.004327043, 0.12734483, 0.017526202, -0.025878336, -0.04723419, 0.04076153, 0.02187685, -0.087851524, -0.04110058, -0.010105569, 0.04627606, 0.06332653, -0.00079965976, 0.007842984, 0.027771931, -0.01872913, -0.026507627, 0.027883867, -0.073383346, -0.0018834389, 0.039492734, -0.015988313, -0.03584256, -0.006394466, -0.013122217, -0.0070721894, -0.031217325, 0.030876111, -0.0120998025, -0.028579762, -0.034054697, 0.01398203, 0.052075498, -0.037533455, -0.02921823, -0.028230242, -0.0042867674, 0.02753535, 0.026063826, -0.008102172, 0.03351258, 0.0018556165, 0.02067572, 0.0053398833, -0.027505938, -0.068869084, -0.026667787, 0.014670199, -0.03125691, 0.014344364, 0.02018399, -0.044214204, 0.017889636, 0.012591866, -0.018269269, 0.019864473, -0.004268113, -0.019023273, -0.031649314, -0.05150966, 0.07253918, 0.007642557, 0.07989845, 0.0222211, -0.052010953, -0.021726148, -0.037446667, 0.02839736, 0.05668282, 0.024556484, -0.026016293, 0.072660826, 0.053380493, 0.049527366, 0.019954052, 0.008163638, -0.00620182, -0.06755945, -0.08795026, 0.068396196, 0.008381865, -0.053986005, 0.020141006, 0.0613408, -0.017976647, -0.07967904, -0.09155565, 0.050448734, 0.039305385, -0.011199603, 0.0037060438, -0.051426914, 0.006717575, 0.0068747653, 0.016114343, -0.037106186, -0.06443905, -0.012482196, 0.03381049, 0.008072382, 0.015788907, -0.00626858, -0.008390408, -0.039854214, 0.017296808, -0.024736699, 0.07684739, -0.038328994, -0.036828, -0.0154192615, 0.056894597, -0.0020580124, 0.0492313, -0.0155431265, 0.05398442, -0.07618382, -0.025398154, -0.045623958, -0.043611784, 0.07858493, -0.06339421, -0.0053564073, 0.04549703, -0.0016020043, -0.033956315, 0.03096677, -0.01021963, -0.0037833976, 0.012463423, 0.0074242908, 0.0044292025, -0.005427089, 0.0014352755, -0.027834771, -0.004876574, 0.04178205, 0.03164932, -0.05789746, -0.013213197, -0.03271979, -0.013708513, -0.011437001, -0.01815072, 0.006589568, -0.015127184, 0.0078976285, -0.009644555, 0.018852906, 0.0013284939, -0.040213875, 0.015602763, 0.032684065, 0.015969083, -0.035441548, -0.009889108, 0.015103965, -0.06190873, -0.0035134521, -0.0115933735, -0.02231668, -0.023467336, -0.06058341, -0.03256418, -0.021768125, -0.019813415, 0.0012417843, 0.009586252, -0.008664985, -0.008984404, 0.05264683, -0.015778132, 0.013971135, -0.022195656, -0.00764865, 0.008325181, 0.034202553, 0.03236561, -0.019021532, 0.08715877, -0.098700255, -0.028130846, 0.027432907, 0.013160638, 0.0033105933, 0.04473792, 0.011874808, -0.031740848, -0.028081503, -0.013635327, -0.032185283, 0.03765546, 0.06299591, -0.017997002, -0.06198613, -0.00080028974, 0.008656828, -0.040359072, -0.018815134, -0.034122735, 0.013136808, 0.01262709, -0.013598097, -0.017882325, -0.026517091, -0.041852005, 0.049192622, 0.017995864, 0.10618377, -0.055258453, 0.042196922, -0.048050255, 0.03873943, 0.042057324, -0.00027147817, -0.0017005315, -0.067733206, 0.004597243, -0.029980252, -0.062314544, 0.051249392, 0.055466447, 0.040632226, 0.01424088, -0.09357828, 0.081091404, 0.024966769, 0.015336323, -0.05498361, -0.018379787, 0.00064548117, -0.023475567, 0.045552514, -0.029865947, 0.047903698, -0.07378346, 0.025390046, 0.07089747, -0.008612272, -0.045564294, 0.0005525389, -0.02357415, 0.010615844, 0.040982768, -0.052486967, -0.04523544, 0.017670183, 0.017961705, 0.0025525666, 0.00867936, 0.066446476, -0.03721764, 0.005949916, 0.00046107935, -0.021050144, -0.071795695, -0.042438112, -0.025677687, 0.025962029, -0.05255637, -0.0013498464, -0.02319936, -0.048218343, -0.019689705, -0.036403265, 0.061983127, 0.009318819, -0.031407125, -0.013520788, -0.08651514, 0.0028307936, -0.0038263933, 0.0062158117, -0.02300001, 0.012822346, -0.037454065, 0.0034324278, 0.040981214, 0.02054721, -0.010428668, 0.04756341, 0.07482804, -0.006437022, -0.0073974053, -0.025452845, 0.024971295, 0.02558825, 0.04719217, 0.011407892, -0.03544048, -0.016669944, 0.06441286, -0.009637454, 0.040003963, 0.020254163, 0.0071999473,
========== TRUNCATED ==========
46, 0.027261956, 0.017827919, 0.023643615, -0.02152712, 0.04039102, 0.080337584, 0.021749347, 0.017495755, 0.010977673, 0.066979446, -0.009189687, -0.01176295, 0.039361663, -0.0015934652, -0.02569398, -0.030099489, 0.068721086, -0.0753713, 0.02117001, -0.015388073, 5.6591816e-05, 0.009105574, -0.031695593, -0.06298923, -0.042641412, -0.0397406, -0.02074612, 0.051795438, 0.009171408, 0.022623207, -0.030757638, 0.0025956347, -0.0077893776, 0.047009706, -0.023424374, 0.033152692, 0.040171992, 0.08005129, 0.058811992, 0.013693727, -0.039217576, -0.049503773, -0.0045070546, -0.04329355, -0.039920434, 0.014903838, 0.013826284, 0.056471102, -0.022949606, 0.019134209, 0.013461174, 0.0100293765, 0.034546487, -0.044456787, -0.019406607, -0.040530924, 0.02702973, 0.010482841, -0.033297785, 0.04187093, -0.021082114, 0.021043781, 0.0047046733, 0.06304224, 0.020258576, 0.00891236, -0.00014846127, -0.027799884, 0.012202556, 0.06595284, 0.05062931, -0.014040537, 0.08371871, 0.016606554, -0.034965113, 0.0042384584, 0.038527086, 0.011850533, -0.02160992, -0.011722867, 0.040818855, 0.03543124, 0.02945772, -0.04288305, 0.01935143, -0.05443992, 0.043806057, -0.025205692, -0.014400814, -0.004664181, 0.014632439, 0.05348843, -0.009882196, 0.02660259, -0.048695106, -0.04957654, 0.002852069, 0.019644773, -0.0076115755, 0.034308884, 0.03754551, -0.027837968, -0.04364765, 0.005801978, 0.05195539, 0.011516308, -0.04270354, -0.0031596918, -0.0014003067, 0.017222593, -0.013664943, -0.012255712, 0.015019818, -0.013036135, 0.019067656, 0.012817375, -0.037104182, -0.0009357514, -0.043493576, 0.008222133, 0.015797457, -0.016462428, -0.018705467, 0.016624182, -0.018844616, -0.030627403, -0.048158005, 0.011989288, -0.030657727, 0.02843261, -0.01549342, 0.00095749594, -0.028322417, 0.012885703, 0.0054307054, -0.030576995, 0.018639358, 0.02734482, -0.021853691, 0.012422048, 0.034417424, -0.035822574, -0.017419634, -0.012711505, -0.06918183, -0.0039825793, 0.00572209, 0.009103463, -0.00608491, -0.0031731217, -0.031964257, -0.06316998, 0.018962411, -0.070222765, 0.0011928438, -0.00097325107, 0.010493583, 0.0015686975, 0.025796287, -0.018431863, -0.008165361, -0.049180146, -0.02680602, 0.015975714, -0.016977781, -0.0526973, 0.016053718, -0.016024353, -0.016688801, 0.049031224, -0.06642895, 0.005356048, -0.024223981, 0.0070825056, -0.021676756, -0.004095302, -0.050671257, 0.05662156, 0.049584385, 0.047596928, -0.010143548, -0.044161927, 0.019401733, 0.038492087, 0.047599185, -0.011127819, 0.04832211, -0.028771184, 0.049660835, -0.047991488, 0.018591445, -0.08150059, -0.039005715, 0.00035225064, -0.0478614, -0.04425115, -0.018162597, -0.009819542, -0.022098327, -0.02523555, -0.0070407866, 0.011227148, 0.021736022, -0.0056850114, 0.020337645, 0.03286101, -0.02083808, -0.013252195, -0.044690873, 0.009272999, 0.061455324, -0.0041282843, -0.023336422, 0.036334004, 0.0055419463, -0.011439538, 0.033832498, -0.010151826, -0.010748247, -0.0030925686, -0.00057925965, 0.02232064, -0.024993269, 0.04484049, -0.021845078, -0.022008507, -0.0048875394, -0.0131546175, -0.013809335, 0.0006408179, -0.00024597583, -0.003481365, 0.08096293, -0.053887438, 0.03800941, -0.039773107, 0.004201412, -0.07336182, -0.032128904, -0.024365848, -0.022396224, 0.019055517, -0.030693991, 0.052851096, 0.0030191396, -0.035986464, 0.036393084, -0.045829453, 0.039130453, -0.034178868, -0.022107694, -0.015873672, 0.017622557, 0.028981997, 0.006893491, 0.03961172, -0.023281721, 0.025165634, 0.00029100914, 0.02755347, 0.049534336, -0.009392743, 0.004612524, -0.040346216, -0.04702946, -0.05902757, 0.03916911, 0.008359422, 0.020083122, -0.0075556524, -0.019377911, -0.016558236, 0.023530567, -0.03028431, -0.0144495405, 0.021507055, 0.012178977, -0.0025732268, 0.010080428, -0.05075006, -0.05233254, 0.06832237, 0.024783244, 0.03141776, -0.024110315, -0.01725089, -0.05395118, -0.07001463, 0.05114748, -0.03973037, 0.007836774, 0.053983092, 0.003900244, 0.013045367, -0.0093611125, 0.048658073, 0.060473848, -0.06312708, 0.032884564, -0.018346155, 0.043985993, -0.05827532, -0.013092139, 0.051283102, -0.055124573]

========== MIDDLE OF OUTPUT TRUNCATED ==========
# function to embed the plot of a james bond movie

def embed_plot(plot_text):
    result = genai.embed_content(
        model="models/text-embedding-004",
        content=plot_text)

    return result["embedding"]
embed_plot(movie_details2[-1]["plot"])
[0.0011618003,
 0.01167106,
 -0.044864874,
 0.04088153,
 0.06322551,
 0.03316254,
 0.0539152,
 0.035036497,
 -0.020677943,
 0.007129762,
 0.0024603696,
 0.0034293719,
 0.087857105,
 0.034154158,
 0.02279256,
 -0.041085694,
 0.029042453,
 0.040042166,
 -0.088138334,
 0.017866427,
 -0.0013840642,
 0.024137184,
 0.018714357,
 -0.0124922255,
 0.005035064,
 -0.007518717,
 -0.02420348,
 0.0013956287,
 0.018609084,
 -0.04378139,
 0.053029504,
 0.022274826,
 -0.0039178487,
 -0.032812286,
 0.03240125,
 -0.022015665,
 -0.008607314,
 -0.0065828743,
 0.030196158,
 -0.008952227,
 -0.048068233,
 -0.033643313,
 0.024125613,
 0.09516443,
 -0.03733872,
 -0.0077209226,
 -0.01187418,
 0.0012594102,
 0.008716694,
 0.05361985,
 0.0021700894,
 -0.011338586,
 -0.029058274,
 -0.017615696,
 0.021699566,
 -0.040884074,
 -0.051098533,
 -0.033287667,
 0.012717199,
 -0.034482922,
 -0.0098720165,
 -0.036354654,
 -0.0029309317,
 -0.0074918405,
 0.01740088,
 -0.0269432,
 -0.011207889,
 0.011532409,
 -0.05922423,
 -0.018465085,
 -0.002626913,
 0.05382053,
 -0.014716241,
 0.082158476,
 -0.018070022,
 -0.045099042,
 0.010544523,
 -0.024890956,
 0.032726698,
 0.050139166,
 0.019203354,
 -0.048637163,
 0.03496668,
 0.036795337,
 -0.0023355626,
 0.016048476,
 -0.030319773,
 -0.0072637806,
 -0.06941845,
 -0.052009154,
 0.06857938,
 0.052129164,
 -0.032140657,
 0.055404145,
 0.08835338,
 -0.03221658,
 -0.08306172,
 -0.08423302,
 0.04800829,
 0.01940194,
 0.00226463,
 -0.01618352,
 -0.02910697,
 -0.020952791,
 0.001947492,
 0.015648723,
 -0.02505363,
 -0.071573526,
 -0.021788483,
 0.07093227,
 0.007954719,
 0.0407671,
 -0.000881511,
 -0.025695067,
 -0.021098483,
 0.036473982,
 -0.021528194,
 0.046225708,
 -0.04390835,
 -0.016472975,
 0.007027456,
 0.034933653,
 -0.00010896776,
 0.06343475,
 0.018905854,
 0.03682594,
 -0.045077443,
 -0.054734826,
 -0.033633433,
 -0.03687372,
 0.0838172,
 -0.015736997,
 0.015948823,
 0.046535123,
 -0.0059757824,
 -0.018233035,
 0.049495243,
 -0.024475968,
 -0.002805433,
 -0.004724779,
 0.0073299417,
 0.0036984854,
 -0.05273645,
 0.016415233,
 0.0031622238,
 -0.05587938,
 0.041085083,
 0.05290283,
 -0.010649434,
 -0.009755354,
 -0.053861562,
 -0.009105638,
 0.009594012,
 0.012429599,
 0.0136692785,
 -0.024332093,
 0.010568095,
 -0.042472925,
 0.0035837067,
 -0.018961366,
 -0.018973894,
 -0.037965447,
 0.047921654,
 0.052994154,
 -0.02113655,
 0.007342873,
 -0.012652948,
 -0.0774414,
 -6.6760585e-05,
 -0.014346799,
 -0.042325173,
 -0.03545547,
 -0.04840058,
 -0.04892107,
 -0.07811835,
 0.004539151,
 -0.013619993,
 0.00047663145,
 -0.07390925,
 -0.030308131,
 0.04420002,
 -0.026960654,
 0.023311358,
 -0.02134436,
 -0.0054255626,
 0.0075336206,
 0.030257927,
 -0.0035354935,
 0.01310714,
 0.054398444,
 -0.06702651,
 -0.051930692,
 0.0069270055,
 0.037504934,
 -0.010865035,
 -0.012925939,
 0.0066285874,
 -0.036139663,
 -0.04149732,
 -0.02715465,
 0.0033417144,
 0.04470364,
 0.079570316,
 -0.0041915337,
 -0.034632742,
 -0.0160481,
 0.034281258,
 -0.0343147,
 -0.030939162,
 -0.0104890745,
 -0.045661546,
 -0.033789404,
 -0.03667499,
 -0.03375932,
 0.009200909,
 -0.026346356,
 0.059155714,
 0.025228417,
 0.12381372,
 -0.08529096,
 0.03343941,
 0.00017058468,
 0.009603952,
 0.049154453,
 0.011317189,
 -0.011897198,
 -0.047192268,
 0.026682874,
 -0.043013867,
 -0.08416084,
 0.016562114,
 0.034963015,
 0.049678978,
 -0.037502922,
 -0.09228977,
 0.031861763,
 -0.008943848,
 -0.0059164586,
 -0.09625258,
 -0.016906964,
 -0.03481655,
 -0.02784356,
 0.024802731,
 -0.009931097,
 0.023956321,
 -0.04927875,
 0.0063061053,
 0.03979997,
 0.0069174534,
 -0.03370148,
 0.005508924,
 0.027012607,
 -0.015432299,
 0.041512977,
 -0.03331724,
 -0.026827121,
 0.04242479,
 0.0348339,
 0.0023055281,
 0.0047431416,
 0.06255998,
 -0.039432056,
 -0.037654676,
 0.0069362186,
 -0.01944949,
 -0.06713393,
 -0.056732852,
 -0.05445664,
 0.011820802,
 -0.041796792,
 0.019921904,
 -0.01439389,
 -0.015091541,
 0.005477596,
 0.0031029277,
 0.048850942,
 -0.015798096,
 0.00546149,
 -0.04907966,
 -0.09236139,
 0.02137896,
 0.015002019,
 -0.024871483,
 -0.016836628,
 0.012729493
========== TRUNCATED ==========
7802825,
 -0.0006287453,
 0.045396056,
 -0.025473066,
 -0.05802759,
 -0.038858764,
 -0.0020276026,
 -0.046862826,
 0.023585979,
 -0.0150816385,
 0.024057895,
 -0.06116129,
 0.0120824855,
 -0.032395247,
 0.04583026,
 0.021199208,
 0.0041537234,
 0.013850828,
 0.06758089,
 0.046418775,
 0.0035603805,
 -0.029177342,
 -0.020514803,
 0.0036061325,
 -0.033725984,
 -0.07729535,
 0.033067327,
 0.022546446,
 0.052029774,
 0.013943629,
 0.035651464,
 0.0027820203,
 -0.014523153,
 0.041645978,
 -0.013724144,
 -0.019304816,
 -0.03258022,
 0.035024434,
 0.015434876,
 -0.044701878,
 0.043029044,
 -0.045248404,
 0.05762497,
 -0.025864061,
 0.056576476,
 -0.0026468555,
 0.021225384,
 -0.012205568,
 -0.04397029,
 0.005356288,
 0.026468733,
 0.06963837,
 0.016011992,
 0.079837546,
 0.032753088,
 0.0148225725,
 0.026484985,
 0.051983662,
 0.04252439,
 -0.015253177,
 -0.02770748,
 0.023336029,
 0.02695133,
 0.015458549,
 -0.012294734,
 0.028509509,
 -0.030901678,
 0.035363305,
 -0.009091554,
 0.024632473,
 -0.029911209,
 0.008894501,
 0.026738793,
 -0.011856724,
 0.029630512,
 -0.03874898,
 -0.073969126,
 -0.009765445,
 0.013908997,
 -0.020733135,
 0.02885831,
 -0.009951764,
 -0.015885826,
 -0.013115722,
 -0.005686351,
 0.071495384,
 0.014438858,
 -0.014904102,
 -0.0003812999,
 0.009187855,
 0.016064195,
 0.0027379636,
 0.0017958574,
 -0.014738318,
 -0.016667603,
 0.019865794,
 0.022356573,
 0.0016334135,
 0.005562754,
 -0.018184654,
 -0.0024833276,
 -0.0041545397,
 -0.028659958,
 0.027856827,
 0.049823973,
 -0.05228246,
 0.016979974,
 -0.03036508,
 0.019635808,
 -0.016259413,
 0.028874487,
 -0.032540835,
 0.010009589,
 -0.059778426,
 0.0052087735,
 0.057881437,
 -0.04805896,
 0.024095692,
 0.038381323,
 -0.042215727,
 0.02684416,
 0.022106124,
 -0.053782407,
 -0.062534876,
 -0.017363494,
 -0.07177101,
 -0.0021445625,
 -0.003338951,
 0.018914547,
 0.025441349,
 -0.008263013,
 -0.023918718,
 -0.06723808,
 0.03821327,
 -0.04226931,
 -0.005348126,
 -0.01644892,
 -0.016026193,
 0.0024382826,
 0.011232079,
 0.0029840358,
 -0.010244027,
 -0.029724061,
 -0.013565087,
 0.024074344,
 0.00681719,
 -0.021732088,
 0.03042327,
 -0.014790838,
 -0.03178781,
 0.09034055,
 -0.031082423,
 -0.0055203624,
 -0.003059687,
 -0.003292332,
 0.028314887,
 -0.005630018,
 -0.03947765,
 0.04606552,
 0.023825932,
 0.08910385,
 0.019815926,
 -0.02417875,
 0.0062226327,
 0.017762693,
 0.014525419,
 0.030033479,
 0.064873144,
 0.0030776216,
 0.013479137,
 -0.051807463,
 0.0155884735,
 -0.049432825,
 -0.05329189,
 -0.03568257,
 -0.015937,
 -0.020713763,
 -0.023961466,
 -0.012844009,
 -0.033548933,
 -0.014084112,
 0.025283381,
 -0.023149986,
 0.004890318,
 -0.04731414,
 -0.0023138754,
 0.0029901415,
 -0.0067926417,
 -0.021247793,
 -0.01838686,
 0.008923259,
 0.03005853,
 0.014750388,
 -0.017325833,
 0.015752122,
 -0.020153178,
 -0.039874136,
 0.029715247,
 0.010035458,
 -0.02567952,
 0.013955008,
 -0.014149996,
 0.015598151,
 -0.014309683,
 0.020151986,
 -0.035932235,
 -0.0603243,
 0.016048137,
 -0.020475263,
 -0.039807174,
 -0.035260472,
 0.0067542642,
 0.017807119,
 0.08967745,
 -0.0399243,
 0.00024786542,
 -0.05199508,
 0.0152421165,
 -0.04028302,
 -0.062460233,
 -0.014701564,
 -0.028599247,
 0.03745395,
 -0.020531671,
 0.058734573,
 0.023282362,
 -0.033098966,
 0.03124007,
 -0.025526559,
 0.05467718,
 0.065230444,
 0.009032047,
 -0.0099519305,
 0.020861374,
 0.05844641,
 0.004741804,
 0.04078378,
 0.007904903,
 0.06143117,
 -0.005792545,
 0.01338281,
 0.03790484,
 0.014793246,
 0.012875153,
 -0.046907872,
 -0.02419582,
 -0.08076991,
 0.02606737,
 0.02497915,
 0.022483096,
 -0.01751788,
 0.008379547,
 -0.00923052,
 0.020407224,
 -0.042079944,
 -0.01835412,
 0.0027334825,
 0.015847256,
 0.0020920702,
 -0.036157046,
 -0.024848705,
 -0.06500839,
 0.050899286,
 0.033346254,
 0.02629908,
 -0.043551028,
 0.003607181,
 -0.060407545,
 -0.057489518,
 0.063488044,
 -0.01692975,
 0.013024313,
 0.04491297,
 0.00684465,
 0.004606504,
 -0.018330667,
 0.0370184,
 0.08085544,
 -0.030603796,
 0.06129545,
 -0.05654628,
 0.0060079596,
 -0.06007612,
 -0.014238684,
 0.06450274,
 -0.065668315]
========== MIDDLE OF OUTPUT TRUNCATED ==========
def add_embedding(movie):
    return {**movie, "embedding": embed_plot(movie["plot"])}

add_embedding(movie_details2[0])
{'title': 'Dr. No',
 'url': 'https://en.wikipedia.org/wiki/Dr._No_(film)',
 'plot': "John Strangways, the Station Chief of MI6 in Jamaica, is murdered, along with his secretary Mary, by a trio of assassins before his home is ransacked. After MI6 loses radio contact with the station, James Bond is found playing baccarat in a private London club; Sylvia Trench is one of the other players. M, the head of MI6, assigns Bond to go to Jamaica; Strangways was helping the CIA investigate radio jamming of rocket launches from Cape Canaveral. M also confiscates Bond's Beretta handgun, which he had used for ten years, replacing it with a Walther PPK 7.65\xa0mm. At Bond's home he finds Sylvia Trench, a brief encounter as he is on the way to his flight. Landing in Jamaica, Bond accepts a ride from an enemy agent. He overpowers the agent, who  kills himself by biting into a cyanide-laced cigarette. Bond arranges with principal secretary Pleydell-Smith to meet those who saw Strangways last, including Professor Dent. At Strangway's home, Bond finds a receipt from Dent and a picture of Strangways and Quarrel, who tailed Bond from the airport earlier. Bond finds Quarrel, they fight, and CIA agent Felix Leiter stops it, explaining that Quarrel worked with him and Strangways looking for the radio jamming source. One island, Crab Key, is generally off limits, controlled by Dr. No, with a bauxite mine; Quarrel and Strangways got rock samples at night. Bond visits Dent, who claims the samples were iron pyrite. Dent travels to Crab Key and is given a tarantula to kill Bond. However Bond kills the spider. He arranges to meet Pleydell-Smith's corrupt secretary Miss Taro. On the drive to her home, the assassins try to run Bond off the road, but themselves crash and die. After an intimate interlude, Bond has Taro arrested. He waits in her home. Dent arrives to kill Bond and is killed by Bond. During the night Quarrel takes Bond to Crab Key. The next morning they meet Honey Ryder, a shell diver. Armed guards search for them. At nightfall the group encounter a flame tank disguised as a dragon to deter locals, which kills Quarrel. Bond and Ryder are captured. Radioactive from the contaminated swamp, both are put through a decontamination process. Taken to comfortable suites with clothes in their sizes, they drink drugged coffee and sleep. Upon awakening, the pair are escorted to dine with the base's owner, Dr Julius No: a Chinese-German scientist with prosthetic metal hands due to radiation exposure. No was a member of a Chinese tong, until he stole $10\xa0million in gold, and now works for SPECTRE (Special Executive for Counter-intelligence, Terrorism, Revenge, and Extortion). The radio jamming will disrupt a Project Mercury space launch at Cape Canaveral. When Bond refuses to join SPECTRE, No has Ryder taken away and Bond beaten. Bond escapes his cell through an air vent, disguises himself as a worker, and infiltrates the base's control centre. Bond overloads the nuclear pool reactor as the launch commences. Dr. No fights him, but falls into the reactor pool and is boiled to death. As the base's personnel evacuate, Bond frees Ryder before the two escape the island by boat, moments before the base is destroyed. Felix finds the pair adrift at sea after their boat runs out of fuel, and has them towed to safety by a Royal Navy ship. As Ryder passionately kisses him, Bond lets go of the towrope to embrace her.",
 'embedding': [0.036159527,
  -0.0041011735,
  -0.0069002705,
  0.018425733,
  0.0353543,
  0.033877883,
  0.096829414,
  0.039409623,
  -0.0005220023,
  0.022444148,
  -0.007817863,
  0.004327043,
  0.12734483,
  0.017526202,
  -0.025878336,
  -0.04723419,
  0.04076153,
  0.02187685,
  -0.087851524,
  -0.04110058,
  -0.010105569,
  0.04627606,
  0.06332653,
  -0.00079965976,
  0.007842984,
  0.027771931,
  -0.01872913,
  -0.026507627,
  0.027883867,
  -0.073383346,
  -0.0018834389,
  0.039492734,
  -0.015988313,
  -0.03584256,
  -0.006394466,
  -0.013122217,
  -0.0070721894,
  -0.031217325,
  0.030876111,
  -0.0120998025,
  -0.028579762,
  -0.034
========== TRUNCATED ==========
7,
  -0.039217576,
  -0.049503773,
  -0.0045070546,
  -0.04329355,
  -0.039920434,
  0.014903838,
  0.013826284,
  0.056471102,
  -0.022949606,
  0.019134209,
  0.013461174,
  0.0100293765,
  0.034546487,
  -0.044456787,
  -0.019406607,
  -0.040530924,
  0.02702973,
  0.010482841,
  -0.033297785,
  0.04187093,
  -0.021082114,
  0.021043781,
  0.0047046733,
  0.06304224,
  0.020258576,
  0.00891236,
  -0.00014846127,
  -0.027799884,
  0.012202556,
  0.06595284,
  0.05062931,
  -0.014040537,
  0.08371871,
  0.016606554,
  -0.034965113,
  0.0042384584,
  0.038527086,
  0.011850533,
  -0.02160992,
  -0.011722867,
  0.040818855,
  0.03543124,
  0.02945772,
  -0.04288305,
  0.01935143,
  -0.05443992,
  0.043806057,
  -0.025205692,
  -0.014400814,
  -0.004664181,
  0.014632439,
  0.05348843,
  -0.009882196,
  0.02660259,
  -0.048695106,
  -0.04957654,
  0.002852069,
  0.019644773,
  -0.0076115755,
  0.034308884,
  0.03754551,
  -0.027837968,
  -0.04364765,
  0.005801978,
  0.05195539,
  0.011516308,
  -0.04270354,
  -0.0031596918,
  -0.0014003067,
  0.017222593,
  -0.013664943,
  -0.012255712,
  0.015019818,
  -0.013036135,
  0.019067656,
  0.012817375,
  -0.037104182,
  -0.0009357514,
  -0.043493576,
  0.008222133,
  0.015797457,
  -0.016462428,
  -0.018705467,
  0.016624182,
  -0.018844616,
  -0.030627403,
  -0.048158005,
  0.011989288,
  -0.030657727,
  0.02843261,
  -0.01549342,
  0.00095749594,
  -0.028322417,
  0.012885703,
  0.0054307054,
  -0.030576995,
  0.018639358,
  0.02734482,
  -0.021853691,
  0.012422048,
  0.034417424,
  -0.035822574,
  -0.017419634,
  -0.012711505,
  -0.06918183,
  -0.0039825793,
  0.00572209,
  0.009103463,
  -0.00608491,
  -0.0031731217,
  -0.031964257,
  -0.06316998,
  0.018962411,
  -0.070222765,
  0.0011928438,
  -0.00097325107,
  0.010493583,
  0.0015686975,
  0.025796287,
  -0.018431863,
  -0.008165361,
  -0.049180146,
  -0.02680602,
  0.015975714,
  -0.016977781,
  -0.0526973,
  0.016053718,
  -0.016024353,
  -0.016688801,
  0.049031224,
  -0.06642895,
  0.005356048,
  -0.024223981,
  0.0070825056,
  -0.021676756,
  -0.004095302,
  -0.050671257,
  0.05662156,
  0.049584385,
  0.047596928,
  -0.010143548,
  -0.044161927,
  0.019401733,
  0.038492087,
  0.047599185,
  -0.011127819,
  0.04832211,
  -0.028771184,
  0.049660835,
  -0.047991488,
  0.018591445,
  -0.08150059,
  -0.039005715,
  0.00035225064,
  -0.0478614,
  -0.04425115,
  -0.018162597,
  -0.009819542,
  -0.022098327,
  -0.02523555,
  -0.0070407866,
  0.011227148,
  0.021736022,
  -0.0056850114,
  0.020337645,
  0.03286101,
  -0.02083808,
  -0.013252195,
  -0.044690873,
  0.009272999,
  0.061455324,
  -0.0041282843,
  -0.023336422,
  0.036334004,
  0.0055419463,
  -0.011439538,
  0.033832498,
  -0.010151826,
  -0.010748247,
  -0.0030925686,
  -0.00057925965,
  0.02232064,
  -0.024993269,
  0.04484049,
  -0.021845078,
  -0.022008507,
  -0.0048875394,
  -0.0131546175,
  -0.013809335,
  0.0006408179,
  -0.00024597583,
  -0.003481365,
  0.08096293,
  -0.053887438,
  0.03800941,
  -0.039773107,
  0.004201412,
  -0.07336182,
  -0.032128904,
  -0.024365848,
  -0.022396224,
  0.019055517,
  -0.030693991,
  0.052851096,
  0.0030191396,
  -0.035986464,
  0.036393084,
  -0.045829453,
  0.039130453,
  -0.034178868,
  -0.022107694,
  -0.015873672,
  0.017622557,
  0.028981997,
  0.006893491,
  0.03961172,
  -0.023281721,
  0.025165634,
  0.00029100914,
  0.02755347,
  0.049534336,
  -0.009392743,
  0.004612524,
  -0.040346216,
  -0.04702946,
  -0.05902757,
  0.03916911,
  0.008359422,
  0.020083122,
  -0.0075556524,
  -0.019377911,
  -0.016558236,
  0.023530567,
  -0.03028431,
  -0.0144495405,
  0.021507055,
  0.012178977,
  -0.0025732268,
  0.010080428,
  -0.05075006,
  -0.05233254,
  0.06832237,
  0.024783244,
  0.03141776,
  -0.024110315,
  -0.01725089,
  -0.05395118,
  -0.07001463,
  0.05114748,
  -0.03973037,
  0.007836774,
  0.053983092,
  0.003900244,
  0.013045367,
  -0.0093611125,
  0.048658073,
  0.060473848,
  -0.06312708,
  0.032884564,
  -0.018346155,
  0.043985993,
  -0.05827532,
  -0.013092139,
  0.051283102,
  -0.055124573]}
========== MIDDLE OF OUTPUT TRUNCATED ==========
movie_details3 = parallel(add_embedding, movie_details2, n_workers=10, threadpool=True)

AI Prompt

Perfect, now we have all the embeddings in the movie_details3 list of dicts.

Now I need to reduce the dimensionality and plot them.

AI Response

I’ll help you reduce the dimensionality using TSNE and create a plot using matplotlib. Here’s how we can do it:

import numpy as np
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt

# Extract embeddings and titles
embeddings = np.array([m['embedding'] for m in movie_details3])
titles = [m['title'] for m in movie_details3]

# Reduce dimensionality with TSNE
tsne = TSNE(n_components=2, random_state=42)
embeddings_2d = tsne.fit_transform(embeddings)

# Create the plot
plt.figure(figsize=(12, 8))
plt.scatter(embeddings_2d[:, 0], embeddings_2d[:, 1], alpha=0.5)

# Add labels for each point
for i, title in enumerate(titles):
    plt.annotate(title, (embeddings_2d[i, 0], embeddings_2d[i, 1]), 
                xytext=(5, 5), textcoords='offset points', 
                fontsize=8, alpha=0.8)

plt.title("James Bond Movies Plot Similarity")
plt.xlabel("t-SNE dimension 1")
plt.ylabel("t-SNE dimension 2")
plt.tight_layout()
plt.show()

This will: 1. Extract the embeddings and titles from our movie details 2. Use t-SNE to reduce the embeddings to 2D 3. Create a scatter plot 4. Add movie titles as annotations 5. Add proper labels and show the plot

Movies that are closer together in this visualization have more similar plots according to the embeddings. Would you like me to explain any part of this in more detail?

import numpy as np
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
embeddings = np.array([m['embedding'] for m in movie_details3])
titles = [m['title'] for m in movie_details3]
embeddings.shape
(25, 768)
tsne = TSNE(n_components=2, random_state=42, perplexity=15)
embeddings_2d = tsne.fit_transform(embeddings)

embeddings_2d
array([[ -8.201926 ,   1.3441612],
       [ -9.571998 ,   4.3586493],
       [-10.001505 ,   2.695524 ],
       [ -8.340659 ,   2.236397 ],
       [ -9.19186  ,   1.9178257],
       [ -8.069215 ,   3.2852085],
       [ -7.9966784,   2.461805 ],
       [ -6.7460775,   2.2868025],
       [ -6.8775587,   1.8698214],
       [ -9.11798  ,   2.269438 ],
       [ -8.933624 ,   1.3740202],
       [ -9.369714 ,   4.964742 ],
       [-10.128473 ,   3.5482726],
       [-11.016665 ,   3.1824017],
       [-10.071082 ,   4.235895 ],
       [ -7.359714 ,   3.1567845],
       [ -9.880585 ,   3.154864 ],
       [-10.010514 ,   1.813359 ],
       [ -9.176552 ,   3.385289 ],
       [ -9.646272 ,   1.8388394],
       [ -8.233566 ,   3.4669225],
       [ -8.342545 ,   3.6785479],
       [ -8.513047 ,   3.7893045],
       [ -8.127548 ,   4.1515284],
       [ -8.190973 ,   4.376581 ]], dtype=float32)
# Create the plot
plt.figure(figsize=(12, 8))
plt.scatter(embeddings_2d[:, 0], embeddings_2d[:, 1], alpha=0.5)

# Add labels for each point
for i, title in enumerate(titles):
    plt.annotate(title, (embeddings_2d[i, 0], embeddings_2d[i, 1]), 
                xytext=(5, 5), textcoords='offset points', 
                fontsize=8, alpha=0.8)

plt.title("James Bond Movies Plot Similarity")
plt.xlabel("t-SNE dimension 1")
plt.ylabel("t-SNE dimension 2")
plt.tight_layout()
plt.show()

AI Prompt

now mark the different actors using color.

AI Response

Here’s how we can color-code the points by actor and add a legend:

# Get unique actors and assign colors
actors = [m['actor'] for m in movie_details3]
unique_actors = list(set(actors))
colors = plt.cm.Set2(np.linspace(0, 1, len(unique_actors)))
actor_to_color = dict(zip(unique_actors, colors))

# Create the plot
plt.figure(figsize=(12, 8))

# Plot points for each actor with different colors
for actor in unique_actors:
    mask = [a == actor for a in actors]
    plt.scatter(embeddings_2d[mask, 0], embeddings_2d[mask, 1], 
               label=actor, alpha=0.6, color=actor_to_color[actor])

# Add labels for each point
for i, title in enumerate(titles):
    plt.annotate(title, (embeddings_2d[i, 0], embeddings_2d[i, 1]), 
                xytext=(5, 5), textcoords='offset points', 
                fontsize=8, alpha=0.8)

plt.title("James Bond Movies Plot Similarity by Actor")
plt.xlabel("t-SNE dimension 1")
plt.ylabel("t-SNE dimension 2")
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
plt.tight_layout()
plt.show()

This will: 1. Create a color mapping for each unique actor 2. Plot points with different colors based on the actor 3. Add a legend showing which color corresponds to which actor 4. Keep the movie title annotations 5. Adjust the layout to accommodate the legend

The resulting plot should make it easier to see if there are any patterns in plot similarity based on the actor playing Bond.

# Get unique actors and assign colors
actors = [m['actor'] for m in movie_details3]
unique_actors = list(set(actors))
colors = plt.cm.Set2(np.linspace(0, 1, len(unique_actors)))
actor_to_color = dict(zip(unique_actors, colors))

# Create the plot
plt.figure(figsize=(12, 8))

# Plot points for each actor with different colors
for actor in unique_actors:
    mask = [a == actor for a in actors]
    plt.scatter(embeddings_2d[mask, 0], embeddings_2d[mask, 1], 
               label=actor, alpha=0.6, color=actor_to_color[actor])

# Add labels for each point
for i, title in enumerate(titles):
    plt.annotate(title, (embeddings_2d[i, 0], embeddings_2d[i, 1]), 
                xytext=(5, 5), textcoords='offset points', 
                fontsize=8, alpha=0.8)

plt.title("James Bond Movies Plot Similarity by Actor")
plt.xlabel("t-SNE dimension 1")
plt.ylabel("t-SNE dimension 2")
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
plt.tight_layout()
plt.show()

AI Prompt

use another color map. I’m color blind (red/green) and I cannot differentiate the colors well.

AI Response

I’ll use a colorblind-friendly colormap. The ‘Set3’ or ‘tab10’ colormaps are generally better for color blindness, but let’s use ‘tab10’ as it has more distinct colors:

plt.figure(figsize=(12, 8))

# Use tab10 colormap which is more colorblind-friendly
colors = plt.cm.tab10(np.linspace(0, 1, len(unique_actors)))
actor_to_color = dict(zip(unique_actors, colors))

# Plot points for each actor with different colors
for actor in unique_actors:
    mask = [a == actor for a in actors]
    plt.scatter(embeddings_2d[mask, 0], embeddings_2d[mask, 1], 
               label=actor, alpha=0.6, color=actor_to_color[actor],
               s=100)  # Made points slightly larger

# Add labels for each point
for i, title in enumerate(titles):
    plt.annotate(title, (embeddings_2d[i, 0], embeddings_2d[i, 1]), 
                xytext=(5, 5), textcoords='offset points', 
                fontsize=8, alpha=0.8)

plt.title("James Bond Movies Plot Similarity by Actor")
plt.xlabel("t-SNE dimension 1")
plt.ylabel("t-SNE dimension 2")
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
plt.tight_layout()
plt.show()

I also made the points slightly larger (s=100) to make them easier to see. The tab10 colormap uses more distinct colors that should be easier to differentiate for color-blind viewers. Let me know if this is better or if you’d like to try a different colormap.

plt.figure(figsize=(12, 8))

# Use tab10 colormap which is more colorblind-friendly
colors = plt.cm.tab10(np.linspace(0, 1, len(unique_actors)))
actor_to_color = dict(zip(unique_actors, colors))

# Plot points for each actor with different colors
for actor in unique_actors:
    mask = [a == actor for a in actors]
    plt.scatter(embeddings_2d[mask, 0], embeddings_2d[mask, 1], 
               label=actor, alpha=0.6, color=actor_to_color[actor],
               s=100)  # Made points slightly larger

# Add labels for each point
for i, title in enumerate(titles):
    plt.annotate(title, (embeddings_2d[i, 0], embeddings_2d[i, 1]), 
                xytext=(5, 5), textcoords='offset points', 
                fontsize=8, alpha=0.8)

plt.title("James Bond Movies Plot Similarity by Actor")
plt.xlabel("t-SNE dimension 1")
plt.ylabel("t-SNE dimension 2")
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
plt.tight_layout()
plt.show()

That’s interesting. The Daniel Craig movies are actually well clustered, which makes sense, because the have a somewhat continous plot.