{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Alexander Davis",
  "title_listed": "Advanced Topic Modeling with LLMs",
  "keywords": "",
  "domain": "文本处理",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://towardsdatascience.com/advanced-topic-modeling-with-llms/",
  "publish_date": "2025-07-21",
  "corpus_stage": "",
  "notes": "",
  "id": "ea9a30f54726",
  "collected_at": "2026-10-02T01:52:28",
  "title": "Advanced Topic Modeling with LLMs | Towards Data Science",
  "body_markdown": "![Revisit consent button](../images/body-df29beacd7496220cc94.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](../images/body-2159bb67f3de8ad870eb.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Large Language Models](https://towardsdatascience.com/category/artificial-intelligence/large-language-models/)\n# Advanced Topic Modeling with LLMs\nA deep dive into topic modeling by leveraging representation models and generative AI with BERTopic\n[Alex Davis](https://towardsdatascience.com/author/adavis08/)\nJuly 21, 202511 min read\n![](../images/000.png)\n## Introduction\nThis article is a continuation of topic modeling open-source intelligence (OSINT) from the OpenAlex API. In a previous article, I give an introduction into topic modeling, the data used, and a traditional NLP approach using Latent Dirichlet Allocation (LDA).\n_See the previous article here:_\n[![](../images/001.jpeg)Topic Modeling Open-Source Research with the OpenAlex APIAn overview of topic modeling global research through the OpenAlex API and visualizing resultsAlex Davis · 9 min read](https://towardsdatascience.com/topic-modeling-open-source-research-with-the-openalex-api-5191c7db9156/)\nThis article uses a more advanced approach of topic modeling by leveraging representation models, generative AI, and other advanced techniques. **We leverage BERTopic to bring several models together into one pipeline, visualize our topics, and explore variations of topic models.**\nLearn this step by step with the interactive [AI Engineer](https://roadmap.sh/ai-engineer) roadmap.\n![](../images/002.png)\nImage by Author\n _The data used comes from the OpenAlex API (_[_https://openalex.org/_](https://openalex.org/)_). This is a dataset/catalogue of open-source research from around the world. The data is freely accessible under a No Rights Reserved license (CC0 license)._\n···\n## The BERTopic Pipeline\nUsing a traditional approach to topic modeling can be difficult, needing to build your own pipeline to clean your data, tokenize, lemmatize, create features, etc. Traditional models like LDA or LSA are also computationally expensive and often yield poor results.\n**BERTopic leverages the transformer architecture through embedding models, and incorporates other components like dimensionality reduction and topic representation models, to create high-performing topic models.** BERTopic also provides variations of models to fit a variety of data and use cases, visualizations to explore results, and more.\n![](../images/003.png)\nImage by Author\n**The biggest advantage of BERTopic is its modularity.** Seen above, the pipeline is comprised of several different models:\n  1. Embedding model\n  2. Dimensionality Reduction model\n  3. Clustering model\n  4. Tokenizer\n  5. Weighting Scheme\n  6. Representation model (optional)\n\n\nTherefore, we can experiment with different models in each component, each with its own parameters. For example, we can try different embedding models, switch the dimensionality reduction from PCA to UMAP, or try fine-tuning the parameters on our clustering model. This is a huge advantage that allows us to fit a topic model to our data and use case.\n···\nFirst, we need to import to necessary modules. Most of these are to build the components of our BERTopic model.\npython\n\n```\n#import packages for data management\nimport pickle\n\n#import packages for topic modeling\nfrom bertopic import BERTopic\nfrom bertopic.representation import KeyBERTInspired\nfrom bertopic.vectorizers import ClassTfidfTransformer\nfrom sentence_transformers import SentenceTransformer\nfrom umap.umap_ import UMAP\nfrom hdbscan import HDBSCAN\nfrom sklearn.feature_extraction.text import CountVectorizer\n\n#import packages for data manipulation and visualization\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom scipy.cluster import hierarchy as sch\n```\n\n## Embedding Model\nThe main component of the BERTopic model is the embedding model. First, we initialize the model using the sentence transformer. You can then specify the embedding model you would like to use.\nIn this case, I am using a relatively small model (~30 million parameters). While we can probably get better results using larger embedding models, I decided to use a smaller model to emphasize speed in this pipeline.  _You can find and compare embedding models based on their size, performance, intended use, etc. by using the MTEB leaderboard from Hugging Face (_[_https://huggingface.co/spaces/mteb/leaderboard_](https://huggingface.co/spaces/mteb/leaderboard) _)._\npython\n\n```\n#initalize embedding model\nembedding_model = SentenceTransformer('thenlper/gte-small')\n\n#calculate embeddings\nembeddings = embedding_model.encode(data['all_text'].tolist(), show_progress_bar=True)\n```\n\nOnce we run our model, we can use the .shape function to see the size of the vectors produced. Below, we can see that each embedding contains 384 values which make up the meaning of each document.\npython\n\n```\n#invesigate shape and size of vectors\nembeddings.shape\n\n#output: (6102, 384)\n```\n\n## Dimensionality Reduction Model\nThe next component of the BERTopic model is the dimensionality reduction model. As high-dimensional data can be troublesome to model, we can use a dimensionality reduction model to represent the embeddings in a lower dimensional representation without losing too much information.\n![](../images/body-039ce068c96c714506b4.png)\nImage by Author\nThere are several different types of dimensionality reduction models, with Principal Component Analysis (PCA) being the most popular. In this case, we will use a Uniform Manifold Approximation and Projection (UMAP) model. **The UMAP model is a non-linear model and is likely to better handle the complex relationships in our data better than PCA.**\npython\n\n```\n#initialize dimensionality reduction model and reduce embeddings\numap_model = UMAP(n_neighbors=5, min_dist=0.0, metric='cosine', random_state=42)\nreduced_embeddings = umap_model.fit_transform(embeddings)\n```\n\nIt is important to note that dimensionality reduction is not a solve-all for high-dimensional data. Dimensionality reduction presents a tradeoff between speed and accuracy as information is lost. These models need to be well-thought out and experimented with to avoid losing too much information while maintaining speed and scalability.\n## Clustering Model\nThe third step is to use the reduced embeddings and create clusters. While clustering is not usually necessary for topic modeling, **we can leverage density-based clustering models to isolate outliers and eliminate noise in our data**. Below, we initialize the Hierarchical Density-Based Spatial Clustering of Applications with Noise (HDBSCAN) model and create our clusters.\npython\n\n```\n#initialize clustering model and cluster\nhdbscan_model = HDBSCAN(min_cluster_size=30, metric='euclidean', cluster_selection_method='eom').fit(reduced_embeddings)\nclusters = hdbscan_model.labels_\n```\n\nA density-based approach gives us a few advantages. Documents are not forced into clusters that they shouldn’t be assigned to, therefore isolating outliers and reducing noise in our data. Also, as opposed to centroid-based models, we do not specify the number of clusters, and clusters are more likely to be well-defined.\n_See my guide to clustering algorithms:_\n[![](../images/body-34a24bdd01861082396b.png)A Guide to Clustering AlgorithmsAn overview of clustering and the different families of clustering algorithms.Alex Davis · 5 min read](https://towardsdatascience.com/a-guide-to-clustering-algorithms-e28af85da0b7/)\nSee the code below to visualize the results of the clustering model.\npython\n\n```\n#create dataframe of reduced embeddings and clusters\ndf = pd.DataFrame(reduced_embeddings, columns = ['x', 'y'])\ndf['Cluster'] = [str(c) for c in clusters]\n\n#split between clusters and outliers\nto_plot = df.loc[df.Cluster != '-1', :]\noutliers = df.loc[df.Cluster == '-1', :]\n\n#plot clusters\nplt.scatter(outliers.x, outliers.y, alpha = 0.05, s = 2, c = 'grey')\nplt.scatter(to_plot.x, to_plot.y, alpha = 0.6, s = 2, c = to_plot.Cluster.astype(int), cmap = 'tab20b')\nplt.axis('off')\n```\n\n![](../images/body-796854e903be2fd4cff2.png)\nImage by Author\nWe can see well-defined clusters that do not overlap. We can also see some smaller clusters group together to make up higher-level topics. Lastly, we can see several documents are greyed out and identified as outliers.\n···\n## Creating a BERTopic Pipeline\nWe now have the necessary components to build our BERTopic pipeline (embedding model, dimensionality reduction model, clustering model). We can use the models we have initialized and fit them to our data using the BERTopic function.\npython\n\n```\n#use models above to BERTopic pipeline\ntopic_model = BERTopic(\n  embedding_model=embedding_model,          # Step 1 - Extract embeddings\n  umap_model=umap_model,                    # Step 2 - Reduce dimensionality\n  hdbscan_model=hdbscan_model,              # Step 3 - Cluster reduced embeddings\n  verbose = True).fit(data['all_text'].tolist(), embeddings)\n```\n\nSince I know I ingested papers about human-machine interfaces (augmented reality, virtual reality), let’s see which topic align to the term “augmented reality”.\npython\n\n```\n#topics most similar to 'augmented reality'\ntopic_model.find_topics(\"augmented reality\")\n\n#output: ([18, 3, 16, 24, 12], [0.9532771, 0.9498462, 0.94966936, 0.9451431, 0.9417263])\n```\n\nFrom the output above, we can see that topics 18, 3, 16, 24, and 12 highly align to the term “augmented reality”. **All these topic should (hopefully) contribute to the broader theme of augmented reality, but each cover a different aspect.**\nTo confirm this, let’s investigate the topic representations. **A topic representation is a list of terms that aims to properly represent the underlying theme of the topic.** For example, the terms “cake”, “candles”, “family”, and “presents” may collectively represent the topic of birthdays or birthday parties.\nWe can use the get_topic() function to investigate the representation of topic 18.\npython\n\n```\n#investigate topic 18\ntopic_model.get_topic(18)\n```\n\n![](../images/body-734f99ba3b5c486553d2.png)\nImage by Author\nIn the above representation, we see some useful terms like “reality”, “virtual”, “augmented”, etc. However, this is not useful as a whole, as we see several stop words like “and” and “the”. This is because BERTopic uses Bag of Words as the default way to represent topics. This representation may also match other representations about augmented reality.\n**Next, we will improve our BERTopic pipeline to create more meaningful topic representations that are give us more insight into these themes.**\n···\n## Improving Topic Representations\nWe can improve the topic representations by adding a weighting scheme, which will highlight the most important terms and better differentiate our topics.\nThis does not replace the Bag of Words model, but improves upon it. Below we add a TF-IDF model to better determine the importance of each term. We use the update_topics() function to update our pipeline.\npython\n\n```\n#initialize tokenizer model\nvectorizer_model = CountVectorizer(stop_words=\"english\")\n\n#initialize ctfidf model to weight terms\nctfidf_model = ClassTfidfTransformer()\n\n#add tokenizer and ctfidf to pipeline\ntopic_model.update_topics(data['all_text'].tolist(), vectorizer_model=vectorizer_model, ctfidf_model=ctfidf_model)\n```\n\npython\n\n```\n#investigate how topic representations have changed\ntopic_model.get_topic(18)\n```\n\n![](../images/body-1259819a922f619c5938.png)\nImage by Author\nWith TF-IDF, these topic representations are much more useful. We can see that the meaningless stop words are gone, other terms appear that help describe the topic, and terms are reordered by their importance.\nBut we do not have to stop here. Thanks to countless new developments in the world of AI and NLP, there are methods we can leverage to fine-tune these representations.\nTo fine-tune, we can take one of two approaches:\n  1. A representation model\n  2. A generative model\n\n\n## Fine-Tuning with a Representation Model\nFirst, let’s add the KeyBERTInspired model as our representation model. **This leverages BERT to compare the semantic similarity of the TF-IDF representations with the documents themselves to better determine the relevance of each term, rather than the importance.**\n_See all representation model options here:_[_https://maartengr.github.io/BERTopic/getting_started/representation/representation.html#keybertinspired_](https://maartengr.github.io/BERTopic/getting_started/representation/representation.html#keybertinspired)\npython\n\n```\n#initilzae representation model and add to pipeline\nrepresentation_model = KeyBERTInspired()\ntopic_model.update_topics(data['all_text'].tolist(), vectorizer_model=vectorizer_model, ctfidf_model=ctfidf_model, representation_model=representation_model)\n```\n\n![](../images/body-6c6c60f89dcb271b8b07.png)\nImage by Author\nHere, we see a fairly major change in the terms, with some additional terms and acronyms. Comparing this to the TF-IDF representation, we again get a better understanding of what this topic is about. Also notice that the scores changed from the TF-IDF weights, which did not have any meaning without context, to scores between 0–1. These new scores represent the semantic similarity scores.\n## Topic Model Visualizations\nBefore we move to generative models for fine-tuning, let’s explore some of the visualizations that BERTopic offers. Visualizing topic models is crucial in understanding your data and how the model is working.\nFirst, we can visualize our topics in a 2-dimensional space, allowing us to see the size of topics and what other topics are similar. Below, we can see we have many topics, with clusters of topics making up larger themes. We can also see a topic that is large and isolated, indicating that there is a lot of similar research regarding crispr.\n![](../images/body-ab4fe57890239b166def.png)\nImage by Author\nLet’s zoom into these clusters of topics to see how they break down higher-level themes. Below, we zoom into topics regarding augmented and virtual reality and see how some topics cover different domains and applications.\n![](../images/body-09574d364d0fa73dadc8.png)\nImage by Author\n![](../images/body-1c11fdc142df2681b729.png)\nImage by Author\nWe can also quickly visualize the most important or most relevant terms in each topic. Again, this is dependent on your approach to the topic representations.\n![](../images/body-9d02e4d128b90b0dc434.png)\nImage by Author\nWe can also use a heatmap to explore the similarity between topics.\n![](../images/body-3b8285d6d72bb451a7f5.png)\nImage by Author\nThese are just a few of the visualizations that BERTopic offers.  _See the full list here:_[_https://maartengr.github.io/BERTopic/getting_started/visualization/visualization.html_](https://maartengr.github.io/BERTopic/getting_started/visualization/visualization.html)\n## Leveraging Generative Models\nFor our last step of fine-tuning our topic representations, we can leverage generative AI to produce representations that are coherent descriptions of the topic.\n**BERTopic offers an easy way to leverage OpenAI’s GPT models to interact with the topic model.** We first establish a prompt that shows the model the data and the current representation of the topics. We then ask it to generate a short label for each topic.\nWe then initialize the client and model, and update our pipeline.\npython\n\n```\nimport openai\nfrom bertopic.representation import OpenAI\n\n#promt for GPT to create topic labels\nprompt = \"\"\"\nI have a topic that contains the following documents:\n[DOCUMENTS]\n\nThe topic is described by the following key words: [KEYWORDS]\n\nBased on the information above, extract a short topic label in the following format:\ntopic: <short topic label>\n\"\"\"\n\n#import GPT\nclient = openai.OpenAI(api_key='API KEY')\n\n#add GPT as representation model\nrepresentation_model = OpenAI(client, model = 'gpt-3.5-turbo', exponential_backoff=True, chat=True, prompt=prompt)\ntopic_model.update_topics(data['all_text'].tolist(), representation_model=representation_model)\n```\n\nNow, let’s go back to the augmented reality topic.\npython\n\n```\n#investigate how topic representations have changed\ntopic_model.get_topic(18)\n\n#output: [('Comparative analysis of virtual and augmented reality for immersive analytics',1)]\n```\n\nThe topic representation now reads “Comparative analysis of virtual and augmented reality for immersive analytics”. **The topic is now much more clear, as we can see the objectives, technologies, and domain included in these documents.**\nBelow is the full list of our new topic representations.\n![](../images/body-51e5269af061b0042956.png)\nImage by Author\nIt does not take much code to see how powerful generative AI is in supporting our topic model and its representations. It is of course extremely important to dig deeper and validate these outputs as you build your model and to do plenty of experimentation with different models, parameters, and approaches.\n## Leveraging Topic Models Variations\nLastly, BERTopic provides several variations of topic models to provide solutions for different data and use cases. These include time-series, hierarchical, supervised, semi-supervised, and many more.\n_See the full list and documentation here:_[_https://maartengr.github.io/BERTopic/getting_started/topicsovertime/topicsovertime.html_](https://maartengr.github.io/BERTopic/getting_started/topicsovertime/topicsovertime.html)\nLet’s quickly explore one of these possibilities with hierarchical topic modeling. Below, we create a linkage function using scipy, which establishes distances between our topics. We can easily fit it to our data and visualize the hierarchy of topics.\npython\n\n```\n#create linkages between topics\nlinkage_function = lambda x: sch.linkage(x, 'single', optimal_ordering=True)\nhierarchical_topics = topic_model.hierarchical_topics(data['all_text'], linkage_function=linkage_function)\n\n#visualize topic model hierarchy\ntopic_model.visualize_hierarchy(hierarchical_topics=hierarchical_topics)\n```\n\n![](../images/body-efb4f4b1546c85f14613.png)\nImage by Author\nIn the visualization above, we can see how topics put themselves together to create broader and broader topics. For example, we see topics 25 and 30 come together to form “Smart Cities and Sustainable Development”. This model provides an awesome capability of being able to zoom in and out and deciding how broad or narrow we would like our topics to be.\n···\n## Conclusion\nIn this article, we got to see the power of BERTopic for topic modeling. BERTopics use of transformers and embedding models dramatically improves results from traditional approaches. The BERTopic pipeline also offers both power and modularity, leveraging several models and allowing you to plug-in other models to fit your data. All of these models can be fine-tuned and put together to create a powerful topic model.\nYou can also integrate representation and generative models to improve topic representations and improve interpretability. BERTopic also offers several visualizations to truly explore your data and validate your model. Lastly, BERTopic offers several variations of topic modeling, like time-series or hierarchical topic modeling, to better fit your use case.\n···\n_I hope you have enjoyed my article! Please feel free to comment, ask questions, or request other topics._\n_Connect with me on LinkedIn:_[_https://www.linkedin.com/in/alexdavis2020/_](https://www.linkedin.com/in/alexdavis2020/)\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](../images/body-d879ad8ec57b4f95a4cd.jpeg)\nWritten By\n## [Alex Davis](https://towardsdatascience.com/author/adavis08/)\n[See all from Alex Davis](https://towardsdatascience.com/author/adavis08/)\n[Deep Dives](https://towardsdatascience.com/tag/deep-dives/)[Llm Applications](https://towardsdatascience.com/tag/llm-applications/)[Machine Learning](https://towardsdatascience.com/tag/machine-learning/)[Natural Lanugage Processing](https://towardsdatascience.com/tag/natural-lanugage-processing/)[Topic Modeling](https://towardsdatascience.com/tag/topic-modeling/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fadvanced-topic-modeling-with-llms%2F&title=Advanced%20Topic%20Modeling%20with%20LLMs)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fadvanced-topic-modeling-with-llms%2F&title=Advanced%20Topic%20Modeling%20with%20LLMs)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fadvanced-topic-modeling-with-llms%2F&text=Advanced%20Topic%20Modeling%20with%20LLMs)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](../images/004.jpg)](https://towardsdatascience.com/how-to-analyze-and-optimize-your-llms-in-3-steps/)\n## [How to Analyze and Optimize Your LLMs in 3 Steps](https://towardsdatascience.com/how-to-analyze-and-optimize-your-llms-in-3-steps/)\n[Large Language Models](https://towardsdatascience.com/category/artificial-intelligence/large-language-models/)\nLearn to enhance your LLMs with my 3 step process, inspecting, improving and iterating on your LLMs\n[Eivind Kjosbakken](https://towardsdatascience.com/author/oieivind/)\nSeptember 11, 20258 min read\n  * [![](../images/005.png)](https://towardsdatascience.com/statistics-bootcamp-8-a-tale-of-two-means-ecec013ae414/)\n## [Statistics Bootcamp 8: A Tale of Two Means](https://towardsdatascience.com/statistics-bootcamp-8-a-tale-of-two-means-ecec013ae414/)\n[Statistics](https://towardsdatascience.com/category/statistics/)\nLearn the math and methods behind the libraries you use daily as a data scientist\n[Adrienne Kline](https://towardsdatascience.com/author/askline1/)\nJanuary 4, 202312 min read\n  * [![](../images/006.jpg)](https://towardsdatascience.com/building-a-scalable-and-accurate-audio-interview-transcription-pipeline-with-google-gemini/)\n## [Building a Scalable and Accurate Audio Interview Transcription Pipeline with Google Gemini](https://towardsdatascience.com/building-a-scalable-and-accurate-audio-interview-transcription-pipeline-with-google-gemini/)\n[Large Language Models](https://towardsdatascience.com/category/artificial-intelligence/large-language-models/)\nFrom prototype to production: real-world insights into building smarter transcription pipelines with LLMs.\n[Ugo Pradère](https://towardsdatascience.com/author/ugopradere/)\nApril 29, 202518 min read\n  * [![](../images/007.jpeg)](https://towardsdatascience.com/10-must-know-linux-commands-c6fc20c48312/)\n## [10 Must-Know Linux Commands](https://towardsdatascience.com/10-must-know-linux-commands-c6fc20c48312/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nAn introductory tutorial for Linux operating system\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nDecember 21, 20205 min read\n  * [![](../images/008.jpeg)](https://towardsdatascience.com/build-better-time-series-models-introducing-bytehub-98b548b98977/)\n## [Build better time-series models: introducing ByteHub](https://towardsdatascience.com/build-better-time-series-models-introducing-bytehub-98b548b98977/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nLearn how to use a feature store to streamline your data science workflow\n[Toby Coleman](https://towardsdatascience.com/author/toby_coleman/)\nApril 27, 20213 min read\n  * [![](../images/009.jpg)](https://towardsdatascience.com/fine-tuning-pretrained-nlp-models-with-huggingfaces-trainer-6326a4456e7b/)\n## [Fine-tuning pretrained NLP models with Huggingface's Trainer](https://towardsdatascience.com/fine-tuning-pretrained-nlp-models-with-huggingfaces-trainer-6326a4456e7b/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nA simple way to fine-tune pretrained NLP models without native Pytorch or Tensorflow\n[Vincent Tan](https://towardsdatascience.com/author/vincenttzc/)\nMarch 25, 20215 min read\n  * [![](../images/010.png)](https://towardsdatascience.com/pytest-for-machine-learning-a-simple-example-based-tutorial-a3df3c58cf8/)\n## [PyTest for Machine Learning - a simple example-based tutorial](https://towardsdatascience.com/pytest-for-machine-learning-a-simple-example-based-tutorial-a3df3c58cf8/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nWe show how to use PyTest for writing effective test functions for a simple machine learning module.\n[Tirthajyoti Sarkar](https://towardsdatascience.com/author/tirthajyoti/)\nApril 24, 20219 min read\n  * [![](../images/011.png)](https://towardsdatascience.com/retain-customers-with-time-to-event-modeling-driven-intervention-de517a39c6e3/)\n## [Retain Customers with Time to Event Modeling Driven Intervention](https://towardsdatascience.com/retain-customers-with-time-to-event-modeling-driven-intervention-de517a39c6e3/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nHands-on Tutorials Pinpointing customer churn at the right time using XGBoost By Charles Frenzel, Baichuan...\n[Charles Frenzel](https://towardsdatascience.com/author/charles-frenzel/)\nJune 3, 202114 min read\n  * [![](../images/012.png)](https://towardsdatascience.com/the-forceful-and-insistent-application-of-gender-stereotypes-by-google-translate-d6b79cbee48/)\n## [The Forceful and Insistent Application of Gender Stereotypes by Google Translate](https://towardsdatascience.com/the-forceful-and-insistent-application-of-gender-stereotypes-by-google-translate-d6b79cbee48/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nHow does one of the most common language translation tools used across the world perpetuate bias?\n[Sourojit Ghosh(G)](https://towardsdatascience.com/author/sourojitg/)\nDecember 6, 20215 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500) How Relevance Models Foreshadowed Transformers for NLP ](https://towardsdatascience.com/how-relevance-models-foreshadowed-transformers-for-nlp/ \"How Relevance Models Foreshadowed Transformers for NLP\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500) Does Your Company Have a Data Strategy? ](https://towardsdatascience.com/does-your-company-have-a-data-strategy-e8944dbec4ae/ \"Does Your Company Have a Data Strategy?\")\n\n\n",
  "metadata": {
    "title": "Advanced Topic Modeling with LLMs | Towards Data Science",
    "description": "A deep dive into topic modeling by leveraging representation models and generative AI with BERTopic",
    "keywords": null,
    "author": "Alex Davis",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "Advanced Topic Modeling with LLMs",
    "og:description": "A deep dive into topic modeling by leveraging representation models and generative AI with BERTopic",
    "og:url": "https://towardsdatascience.com/advanced-topic-modeling-with-llms/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/thumbnail.png",
    "og:image:width": "630",
    "og:image:height": "378",
    "og:image:type": "image/png",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "Alex Davis",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "11 min read",
    "article:published_time": "2025-07-21T12:30:36.000Z",
    "article:modified_time": "2025-07-21T12:30:36.000Z",
    "article:author": "https://towardsdatascience.com/author/adavis08/"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 202,
    "error": ""
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_000.txt",
      "chars": 548
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_001.txt",
      "chars": 197
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_002.txt",
      "chars": 77
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_003.txt",
      "chars": 204
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_004.txt",
      "chars": 195
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_005.txt",
      "chars": 480
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_006.txt",
      "chars": 357
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_007.txt",
      "chars": 179
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_008.txt",
      "chars": 48
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_009.txt",
      "chars": 320
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_010.txt",
      "chars": 78
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_011.txt",
      "chars": 251
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_012.txt",
      "chars": 655
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_013.txt",
      "chars": 174
    },
    {
      "language": "txt",
      "file": "attachments/ea9a30f54726/code/block_014.txt",
      "chars": 323
    }
  ],
  "images": [
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T18:01:51Z"
    },
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T18:01:51Z"
    },
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T18:01:51Z"
    },
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T18:02:34Z"
    }
  ],
  "audio": [],
  "videos": [
    {
      "url": "https://www.youtube.com/c/TowardsDataScience",
      "kind": "channel_reference",
      "status": "reference_only"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/latest/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/editors-pick/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/the-variable/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/shipai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/submissions/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/large-language-models/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/adavis08/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/topic-modeling-open-source-research-with-the-openalex-api-5191c7db9156/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/a-guide-to-clustering-algorithms-e28af85da0b7/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/deep-dives/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/llm-applications/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/natural-lanugage-processing/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/topic-modeling/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/how-to-analyze-and-optimize-your-llms-in-3-steps/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/oieivind/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/statistics-bootcamp-8-a-tale-of-two-means-ecec013ae414/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/statistics/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/askline1/"
    },
    {
      "type": "external",
      "href": "https://write.insightmediagroup.io"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/company/towards-data-science/"
    },
    {
      "type": "external",
      "href": "https://x.com/TDataScience"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/ai-engineer"
    },
    {
      "type": "external",
      "href": "https://openalex.org/"
    },
    {
      "type": "external",
      "href": "https://huggingface.co/spaces/mteb/leaderboard"
    },
    {
      "type": "external",
      "href": "https://maartengr.github.io/BERTopic/getting_started/representation/representation.html"
    },
    {
      "type": "external",
      "href": "https://maartengr.github.io/BERTopic/getting_started/visualization/visualization.html"
    },
    {
      "type": "external",
      "href": "https://maartengr.github.io/BERTopic/getting_started/topicsovertime/topicsovertime.html"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/in/alexdavis2020/"
    },
    {
      "type": "external",
      "href": "https://www.facebook.com/sharer/sharer.php?title=Advanced+Topic+Modeling+with+LLMs&u=https%3A%2F%2Ftowardsdatascience.com%2Fadvanced-topic-modeling-with-llms%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/shareArticle?mini=true&title=Advanced+Topic+Modeling+with+LLMs&url=https%3A%2F%2Ftowardsdatascience.com%2Fadvanced-topic-modeling-with-llms%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/share?text=Advanced+Topic+Modeling+with+LLMs&url=https%3A%2F%2Ftowardsdatascience.com%2Fadvanced-topic-modeling-with-llms%2F"
    },
    {
      "type": "external",
      "href": "https://www.youtube.com/c/TowardsDataScience"
    },
    {
      "type": "external",
      "href": "https://www.threads.net/@towardsdatascience"
    },
    {
      "type": "external",
      "href": "https://bsky.app/profile/towardsdatascience.com"
    },
    {
      "type": "external",
      "href": "https://thenewstack.io"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh"
    },
    {
      "type": "external",
      "href": "https://insightmediagroup.io/creator-network"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-20T17:31:02Z",
  "source_url": "https://towardsdatascience.com/advanced-topic-modeling-with-llms/",
  "delivery_status": "unverified",
  "discovery_status": "http_403",
  "missing_reason": "源页面未重新核验:http_403；已按保留正文补采图片",
  "repair_error": "",
  "actual_video_files": [],
  "expected_saved_body_images": 4,
  "image_discovery": "saved_markdown",
  "source_body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Large Language Models](https://towardsdatascience.com/category/artificial-intelligence/large-language-models/)\n# Advanced Topic Modeling with LLMs\nA deep dive into topic modeling by leveraging representation models and generative AI with BERTopic\n[Alex Davis](https://towardsdatascience.com/author/adavis08/)\nJuly 21, 202511 min read\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/thumbnail.png)\n## Introduction\nThis article is a continuation of topic modeling open-source intelligence (OSINT) from the OpenAlex API. In a previous article, I give an introduction into topic modeling, the data used, and a traditional NLP approach using Latent Dirichlet Allocation (LDA).\n_See the previous article here:_\n[![](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/10Ij2ZNwGNOMufJDLgPagOw.jpeg)Topic Modeling Open-Source Research with the OpenAlex APIAn overview of topic modeling global research through the OpenAlex API and visualizing resultsAlex Davis · 9 min read](https://towardsdatascience.com/topic-modeling-open-source-research-with-the-openalex-api-5191c7db9156/)\nThis article uses a more advanced approach of topic modeling by leveraging representation models, generative AI, and other advanced techniques. **We leverage BERTopic to bring several models together into one pipeline, visualize our topics, and explore variations of topic models.**\nLearn this step by step with the interactive [AI Engineer](https://roadmap.sh/ai-engineer) roadmap.\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-159.png)\nImage by Author\n _The data used comes from the OpenAlex API (_[_https://openalex.org/_](https://openalex.org/)_). This is a dataset/catalogue of open-source research from around the world. The data is freely accessible under a No Rights Reserved license (CC0 license)._\n···\n## The BERTopic Pipeline\nUsing a traditional approach to topic modeling can be difficult, needing to build your own pipeline to clean your data, tokenize, lemmatize, create features, etc. Traditional models like LDA or LSA are also computationally expensive and often yield poor results.\n**BERTopic leverages the transformer architecture through embedding models, and incorporates other components like dimensionality reduction and topic representation models, to create high-performing topic models.** BERTopic also provides variations of models to fit a variety of data and use cases, visualizations to explore results, and more.\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-160.png)\nImage by Author\n**The biggest advantage of BERTopic is its modularity.** Seen above, the pipeline is comprised of several different models:\n  1. Embedding model\n  2. Dimensionality Reduction model\n  3. Clustering model\n  4. Tokenizer\n  5. Weighting Scheme\n  6. Representation model (optional)\n\n\nTherefore, we can experiment with different models in each component, each with its own parameters. For example, we can try different embedding models, switch the dimensionality reduction from PCA to UMAP, or try fine-tuning the parameters on our clustering model. This is a huge advantage that allows us to fit a topic model to our data and use case.\n···\nFirst, we need to import to necessary modules. Most of these are to build the components of our BERTopic model.\npython\n\n```\n#import packages for data management\nimport pickle\n\n#import packages for topic modeling\nfrom bertopic import BERTopic\nfrom bertopic.representation import KeyBERTInspired\nfrom bertopic.vectorizers import ClassTfidfTransformer\nfrom sentence_transformers import SentenceTransformer\nfrom umap.umap_ import UMAP\nfrom hdbscan import HDBSCAN\nfrom sklearn.feature_extraction.text import CountVectorizer\n\n#import packages for data manipulation and visualization\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom scipy.cluster import hierarchy as sch\n```\n\n## Embedding Model\nThe main component of the BERTopic model is the embedding model. First, we initialize the model using the sentence transformer. You can then specify the embedding model you would like to use.\nIn this case, I am using a relatively small model (~30 million parameters). While we can probably get better results using larger embedding models, I decided to use a smaller model to emphasize speed in this pipeline.  _You can find and compare embedding models based on their size, performance, intended use, etc. by using the MTEB leaderboard from Hugging Face (_[_https://huggingface.co/spaces/mteb/leaderboard_](https://huggingface.co/spaces/mteb/leaderboard) _)._\npython\n\n```\n#initalize embedding model\nembedding_model = SentenceTransformer('thenlper/gte-small')\n\n#calculate embeddings\nembeddings = embedding_model.encode(data['all_text'].tolist(), show_progress_bar=True)\n```\n\nOnce we run our model, we can use the .shape function to see the size of the vectors produced. Below, we can see that each embedding contains 384 values which make up the meaning of each document.\npython\n\n```\n#invesigate shape and size of vectors\nembeddings.shape\n\n#output: (6102, 384)\n```\n\n## Dimensionality Reduction Model\nThe next component of the BERTopic model is the dimensionality reduction model. As high-dimensional data can be troublesome to model, we can use a dimensionality reduction model to represent the embeddings in a lower dimensional representation without losing too much information.\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-179.png)\nImage by Author\nThere are several different types of dimensionality reduction models, with Principal Component Analysis (PCA) being the most popular. In this case, we will use a Uniform Manifold Approximation and Projection (UMAP) model. **The UMAP model is a non-linear model and is likely to better handle the complex relationships in our data better than PCA.**\npython\n\n```\n#initialize dimensionality reduction model and reduce embeddings\numap_model = UMAP(n_neighbors=5, min_dist=0.0, metric='cosine', random_state=42)\nreduced_embeddings = umap_model.fit_transform(embeddings)\n```\n\nIt is important to note that dimensionality reduction is not a solve-all for high-dimensional data. Dimensionality reduction presents a tradeoff between speed and accuracy as information is lost. These models need to be well-thought out and experimented with to avoid losing too much information while maintaining speed and scalability.\n## Clustering Model\nThe third step is to use the reduced embeddings and create clusters. While clustering is not usually necessary for topic modeling, **we can leverage density-based clustering models to isolate outliers and eliminate noise in our data**. Below, we initialize the Hierarchical Density-Based Spatial Clustering of Applications with Noise (HDBSCAN) model and create our clusters.\npython\n\n```\n#initialize clustering model and cluster\nhdbscan_model = HDBSCAN(min_cluster_size=30, metric='euclidean', cluster_selection_method='eom').fit(reduced_embeddings)\nclusters = hdbscan_model.labels_\n```\n\nA density-based approach gives us a few advantages. Documents are not forced into clusters that they shouldn’t be assigned to, therefore isolating outliers and reducing noise in our data. Also, as opposed to centroid-based models, we do not specify the number of clusters, and clusters are more likely to be well-defined.\n_See my guide to clustering algorithms:_\n[![](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/09/1r2w63oyDRGSs1hH_pS-9Ng.png)A Guide to Clustering AlgorithmsAn overview of clustering and the different families of clustering algorithms.Alex Davis · 5 min read](https://towardsdatascience.com/a-guide-to-clustering-algorithms-e28af85da0b7/)\nSee the code below to visualize the results of the clustering model.\npython\n\n```\n#create dataframe of reduced embeddings and clusters\ndf = pd.DataFrame(reduced_embeddings, columns = ['x', 'y'])\ndf['Cluster'] = [str(c) for c in clusters]\n\n#split between clusters and outliers\nto_plot = df.loc[df.Cluster != '-1', :]\noutliers = df.loc[df.Cluster == '-1', :]\n\n#plot clusters\nplt.scatter(outliers.x, outliers.y, alpha = 0.05, s = 2, c = 'grey')\nplt.scatter(to_plot.x, to_plot.y, alpha = 0.6, s = 2, c = to_plot.Cluster.astype(int), cmap = 'tab20b')\nplt.axis('off')\n```\n\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-180.png)\nImage by Author\nWe can see well-defined clusters that do not overlap. We can also see some smaller clusters group together to make up higher-level topics. Lastly, we can see several documents are greyed out and identified as outliers.\n···\n## Creating a BERTopic Pipeline\nWe now have the necessary components to build our BERTopic pipeline (embedding model, dimensionality reduction model, clustering model). We can use the models we have initialized and fit them to our data using the BERTopic function.\npython\n\n```\n#use models above to BERTopic pipeline\ntopic_model = BERTopic(\n  embedding_model=embedding_model,          # Step 1 - Extract embeddings\n  umap_model=umap_model,                    # Step 2 - Reduce dimensionality\n  hdbscan_model=hdbscan_model,              # Step 3 - Cluster reduced embeddings\n  verbose = True).fit(data['all_text'].tolist(), embeddings)\n```\n\nSince I know I ingested papers about human-machine interfaces (augmented reality, virtual reality), let’s see which topic align to the term “augmented reality”.\npython\n\n```\n#topics most similar to 'augmented reality'\ntopic_model.find_topics(\"augmented reality\")\n\n#output: ([18, 3, 16, 24, 12], [0.9532771, 0.9498462, 0.94966936, 0.9451431, 0.9417263])\n```\n\nFrom the output above, we can see that topics 18, 3, 16, 24, and 12 highly align to the term “augmented reality”. **All these topic should (hopefully) contribute to the broader theme of augmented reality, but each cover a different aspect.**\nTo confirm this, let’s investigate the topic representations. **A topic representation is a list of terms that aims to properly represent the underlying theme of the topic.** For example, the terms “cake”, “candles”, “family”, and “presents” may collectively represent the topic of birthdays or birthday parties.\nWe can use the get_topic() function to investigate the representation of topic 18.\npython\n\n```\n#investigate topic 18\ntopic_model.get_topic(18)\n```\n\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-181.png)\nImage by Author\nIn the above representation, we see some useful terms like “reality”, “virtual”, “augmented”, etc. However, this is not useful as a whole, as we see several stop words like “and” and “the”. This is because BERTopic uses Bag of Words as the default way to represent topics. This representation may also match other representations about augmented reality.\n**Next, we will improve our BERTopic pipeline to create more meaningful topic representations that are give us more insight into these themes.**\n···\n## Improving Topic Representations\nWe can improve the topic representations by adding a weighting scheme, which will highlight the most important terms and better differentiate our topics.\nThis does not replace the Bag of Words model, but improves upon it. Below we add a TF-IDF model to better determine the importance of each term. We use the update_topics() function to update our pipeline.\npython\n\n```\n#initialize tokenizer model\nvectorizer_model = CountVectorizer(stop_words=\"english\")\n\n#initialize ctfidf model to weight terms\nctfidf_model = ClassTfidfTransformer()\n\n#add tokenizer and ctfidf to pipeline\ntopic_model.update_topics(data['all_text'].tolist(), vectorizer_model=vectorizer_model, ctfidf_model=ctfidf_model)\n```\n\npython\n\n```\n#investigate how topic representations have changed\ntopic_model.get_topic(18)\n```\n\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-182.png)\nImage by Author\nWith TF-IDF, these topic representations are much more useful. We can see that the meaningless stop words are gone, other terms appear that help describe the topic, and terms are reordered by their importance.\nBut we do not have to stop here. Thanks to countless new developments in the world of AI and NLP, there are methods we can leverage to fine-tune these representations.\nTo fine-tune, we can take one of two approaches:\n  1. A representation model\n  2. A generative model\n\n\n## Fine-Tuning with a Representation Model\nFirst, let’s add the KeyBERTInspired model as our representation model. **This leverages BERT to compare the semantic similarity of the TF-IDF representations with the documents themselves to better determine the relevance of each term, rather than the importance.**\n_See all representation model options here:_[_https://maartengr.github.io/BERTopic/getting_started/representation/representation.html#keybertinspired_](https://maartengr.github.io/BERTopic/getting_started/representation/representation.html#keybertinspired)\npython\n\n```\n#initilzae representation model and add to pipeline\nrepresentation_model = KeyBERTInspired()\ntopic_model.update_topics(data['all_text'].tolist(), vectorizer_model=vectorizer_model, ctfidf_model=ctfidf_model, representation_model=representation_model)\n```\n\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-183.png)\nImage by Author\nHere, we see a fairly major change in the terms, with some additional terms and acronyms. Comparing this to the TF-IDF representation, we again get a better understanding of what this topic is about. Also notice that the scores changed from the TF-IDF weights, which did not have any meaning without context, to scores between 0–1. These new scores represent the semantic similarity scores.\n## Topic Model Visualizations\nBefore we move to generative models for fine-tuning, let’s explore some of the visualizations that BERTopic offers. Visualizing topic models is crucial in understanding your data and how the model is working.\nFirst, we can visualize our topics in a 2-dimensional space, allowing us to see the size of topics and what other topics are similar. Below, we can see we have many topics, with clusters of topics making up larger themes. We can also see a topic that is large and isolated, indicating that there is a lot of similar research regarding crispr.\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-184.png)\nImage by Author\nLet’s zoom into these clusters of topics to see how they break down higher-level themes. Below, we zoom into topics regarding augmented and virtual reality and see how some topics cover different domains and applications.\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-185.png)\nImage by Author\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-186.png)\nImage by Author\nWe can also quickly visualize the most important or most relevant terms in each topic. Again, this is dependent on your approach to the topic representations.\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-187.png)\nImage by Author\nWe can also use a heatmap to explore the similarity between topics.\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-188.png)\nImage by Author\nThese are just a few of the visualizations that BERTopic offers.  _See the full list here:_[_https://maartengr.github.io/BERTopic/getting_started/visualization/visualization.html_](https://maartengr.github.io/BERTopic/getting_started/visualization/visualization.html)\n## Leveraging Generative Models\nFor our last step of fine-tuning our topic representations, we can leverage generative AI to produce representations that are coherent descriptions of the topic.\n**BERTopic offers an easy way to leverage OpenAI’s GPT models to interact with the topic model.** We first establish a prompt that shows the model the data and the current representation of the topics. We then ask it to generate a short label for each topic.\nWe then initialize the client and model, and update our pipeline.\npython\n\n```\nimport openai\nfrom bertopic.representation import OpenAI\n\n#promt for GPT to create topic labels\nprompt = \"\"\"\nI have a topic that contains the following documents:\n[DOCUMENTS]\n\nThe topic is described by the following key words: [KEYWORDS]\n\nBased on the information above, extract a short topic label in the following format:\ntopic: <short topic label>\n\"\"\"\n\n#import GPT\nclient = openai.OpenAI(api_key='API KEY')\n\n#add GPT as representation model\nrepresentation_model = OpenAI(client, model = 'gpt-3.5-turbo', exponential_backoff=True, chat=True, prompt=prompt)\ntopic_model.update_topics(data['all_text'].tolist(), representation_model=representation_model)\n```\n\nNow, let’s go back to the augmented reality topic.\npython\n\n```\n#investigate how topic representations have changed\ntopic_model.get_topic(18)\n\n#output: [('Comparative analysis of virtual and augmented reality for immersive analytics',1)]\n```\n\nThe topic representation now reads “Comparative analysis of virtual and augmented reality for immersive analytics”. **The topic is now much more clear, as we can see the objectives, technologies, and domain included in these documents.**\nBelow is the full list of our new topic representations.\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-189.png)\nImage by Author\nIt does not take much code to see how powerful generative AI is in supporting our topic model and its representations. It is of course extremely important to dig deeper and validate these outputs as you build your model and to do plenty of experimentation with different models, parameters, and approaches.\n## Leveraging Topic Models Variations\nLastly, BERTopic provides several variations of topic models to provide solutions for different data and use cases. These include time-series, hierarchical, supervised, semi-supervised, and many more.\n_See the full list and documentation here:_[_https://maartengr.github.io/BERTopic/getting_started/topicsovertime/topicsovertime.html_](https://maartengr.github.io/BERTopic/getting_started/topicsovertime/topicsovertime.html)\nLet’s quickly explore one of these possibilities with hierarchical topic modeling. Below, we create a linkage function using scipy, which establishes distances between our topics. We can easily fit it to our data and visualize the hierarchy of topics.\npython\n\n```\n#create linkages between topics\nlinkage_function = lambda x: sch.linkage(x, 'single', optimal_ordering=True)\nhierarchical_topics = topic_model.hierarchical_topics(data['all_text'], linkage_function=linkage_function)\n\n#visualize topic model hierarchy\ntopic_model.visualize_hierarchy(hierarchical_topics=hierarchical_topics)\n```\n\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/07/image-190.png)\nImage by Author\nIn the visualization above, we can see how topics put themselves together to create broader and broader topics. For example, we see topics 25 and 30 come together to form “Smart Cities and Sustainable Development”. This model provides an awesome capability of being able to zoom in and out and deciding how broad or narrow we would like our topics to be.\n···\n## Conclusion\nIn this article, we got to see the power of BERTopic for topic modeling. BERTopics use of transformers and embedding models dramatically improves results from traditional approaches. The BERTopic pipeline also offers both power and modularity, leveraging several models and allowing you to plug-in other models to fit your data. All of these models can be fine-tuned and put together to create a powerful topic model.\nYou can also integrate representation and generative models to improve topic representations and improve interpretability. BERTopic also offers several visualizations to truly explore your data and validate your model. Lastly, BERTopic offers several variations of topic modeling, like time-series or hierarchical topic modeling, to better fit your use case.\n···\n_I hope you have enjoyed my article! Please feel free to comment, ask questions, or request other topics._\n_Connect with me on LinkedIn:_[_https://www.linkedin.com/in/alexdavis2020/_](https://www.linkedin.com/in/alexdavis2020/)\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657658380_gf1kgl.jpeg)\nWritten By\n## [Alex Davis](https://towardsdatascience.com/author/adavis08/)\n[See all from Alex Davis](https://towardsdatascience.com/author/adavis08/)\n[Deep Dives](https://towardsdatascience.com/tag/deep-dives/)[Llm Applications](https://towardsdatascience.com/tag/llm-applications/)[Machine Learning](https://towardsdatascience.com/tag/machine-learning/)[Natural Lanugage Processing](https://towardsdatascience.com/tag/natural-lanugage-processing/)[Topic Modeling](https://towardsdatascience.com/tag/topic-modeling/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fadvanced-topic-modeling-with-llms%2F&title=Advanced%20Topic%20Modeling%20with%20LLMs)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fadvanced-topic-modeling-with-llms%2F&title=Advanced%20Topic%20Modeling%20with%20LLMs)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fadvanced-topic-modeling-with-llms%2F&text=Advanced%20Topic%20Modeling%20with%20LLMs)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/09/image-121.jpg)](https://towardsdatascience.com/how-to-analyze-and-optimize-your-llms-in-3-steps/)\n## [How to Analyze and Optimize Your LLMs in 3 Steps](https://towardsdatascience.com/how-to-analyze-and-optimize-your-llms-in-3-steps/)\n[Large Language Models](https://towardsdatascience.com/category/artificial-intelligence/large-language-models/)\nLearn to enhance your LLMs with my 3 step process, inspecting, improving and iterating on your LLMs\n[Eivind Kjosbakken](https://towardsdatascience.com/author/oieivind/)\nSeptember 11, 20258 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/09/1Q8m3QmNcpiudEQNWL3p6LA.png)](https://towardsdatascience.com/statistics-bootcamp-8-a-tale-of-two-means-ecec013ae414/)\n## [Statistics Bootcamp 8: A Tale of Two Means](https://towardsdatascience.com/statistics-bootcamp-8-a-tale-of-two-means-ecec013ae414/)\n[Statistics](https://towardsdatascience.com/category/statistics/)\nLearn the math and methods behind the libraries you use daily as a data scientist\n[Adrienne Kline](https://towardsdatascience.com/author/askline1/)\nJanuary 4, 202312 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/04/picture-S2T.jpg)](https://towardsdatascience.com/building-a-scalable-and-accurate-audio-interview-transcription-pipeline-with-google-gemini/)\n## [Building a Scalable and Accurate Audio Interview Transcription Pipeline with Google Gemini](https://towardsdatascience.com/building-a-scalable-and-accurate-audio-interview-transcription-pipeline-with-google-gemini/)\n[Large Language Models](https://towardsdatascience.com/category/artificial-intelligence/large-language-models/)\nFrom prototype to production: real-world insights into building smarter transcription pipelines with LLMs.\n[Ugo Pradère](https://towardsdatascience.com/author/ugopradere/)\nApril 29, 202518 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2019/07/1YH_zfktV-QwoIB65qCWmAw-scaled.jpeg)](https://towardsdatascience.com/10-must-know-linux-commands-c6fc20c48312/)\n## [10 Must-Know Linux Commands](https://towardsdatascience.com/10-must-know-linux-commands-c6fc20c48312/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nAn introductory tutorial for Linux operating system\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nDecember 21, 20205 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/07/1aUmjaErpNi_qJxuF3ZtMWQ-scaled.jpeg)](https://towardsdatascience.com/build-better-time-series-models-introducing-bytehub-98b548b98977/)\n## [Build better time-series models: introducing ByteHub](https://towardsdatascience.com/build-better-time-series-models-introducing-bytehub-98b548b98977/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nLearn how to use a feature store to streamline your data science workflow\n[Toby Coleman](https://towardsdatascience.com/author/toby_coleman/)\nApril 27, 20213 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/03/0QQIQkO_uYhjiyKjf-scaled.jpg)](https://towardsdatascience.com/fine-tuning-pretrained-nlp-models-with-huggingfaces-trainer-6326a4456e7b/)\n## [Fine-tuning pretrained NLP models with Huggingface's Trainer](https://towardsdatascience.com/fine-tuning-pretrained-nlp-models-with-huggingfaces-trainer-6326a4456e7b/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nA simple way to fine-tune pretrained NLP models without native Pytorch or Tensorflow\n[Vincent Tan](https://towardsdatascience.com/author/vincenttzc/)\nMarch 25, 20215 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/04/12SYweCRRh6bJPPx8ofgyTQ.png)](https://towardsdatascience.com/pytest-for-machine-learning-a-simple-example-based-tutorial-a3df3c58cf8/)\n## [PyTest for Machine Learning - a simple example-based tutorial](https://towardsdatascience.com/pytest-for-machine-learning-a-simple-example-based-tutorial-a3df3c58cf8/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nWe show how to use PyTest for writing effective test functions for a simple machine learning module.\n[Tirthajyoti Sarkar](https://towardsdatascience.com/author/tirthajyoti/)\nApril 24, 20219 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/06/1q2qq0jcmApjMqDxmHcdCLQ.png)](https://towardsdatascience.com/retain-customers-with-time-to-event-modeling-driven-intervention-de517a39c6e3/)\n## [Retain Customers with Time to Event Modeling Driven Intervention](https://towardsdatascience.com/retain-customers-with-time-to-event-modeling-driven-intervention-de517a39c6e3/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nHands-on Tutorials Pinpointing customer churn at the right time using XGBoost By Charles Frenzel, Baichuan...\n[Charles Frenzel](https://towardsdatascience.com/author/charles-frenzel/)\nJune 3, 202114 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/12/1TCm38WIyZ4x-sHAzPrDI-w.png)](https://towardsdatascience.com/the-forceful-and-insistent-application-of-gender-stereotypes-by-google-translate-d6b79cbee48/)\n## [The Forceful and Insistent Application of Gender Stereotypes by Google Translate](https://towardsdatascience.com/the-forceful-and-insistent-application-of-gender-stereotypes-by-google-translate-d6b79cbee48/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nHow does one of the most common language translation tools used across the world perpetuate bias?\n[Sourojit Ghosh(G)](https://towardsdatascience.com/author/sourojitg/)\nDecember 6, 20215 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500) How Relevance Models Foreshadowed Transformers for NLP ](https://towardsdatascience.com/how-relevance-models-foreshadowed-transformers-for-nlp/ \"How Relevance Models Foreshadowed Transformers for NLP\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500) Does Your Company Have a Data Strategy? ](https://towardsdatascience.com/does-your-company-have-a-data-strategy-e8944dbec4ae/ \"Does Your Company Have a Data Strategy?\")\n\n\n",
  "body_base_path": "attachments/ea9a30f54726/pages/",
  "body_markdown_path": "attachments/ea9a30f54726/pages/archived-body.md",
  "local_html": "attachments/ea9a30f54726/pages/archived-body.html",
  "body_source": "prior_capture"
}