Package: bunkatopics
Please read our Documentation:The Origin of BunkaBunkatopicsBunkatopics is a package designed for Topic Modeling Visualization, Frame Analysis, and Retrieval Augmented Generation (RAG) tasks, harnessing the power of Large Language Models (LLMs). Its primary goal is to assist developers in gaining insights from unstructured data, potentially facilitating data cleansing and optimizing LLMs through fine-tuning processes.
Bunkatopics is constructed using well-known libraries like langchain, chroma, and transformers, enabling seamless integration into various environments.Discover the different Use Case:Content Overview: The Medium website offers a wealth of content across various categories such as Data Science, Technology, Programming, Poetry, Cryptocurrency, Machine Learning, Life, and more. While these categories facilitate data searching, they may not provide a granular overview. For instance, within the Technology category, what specific topics does Medium cover?Fine-Tuning: To achieve precise fine-tuning, it's crucial to exercise control over the data, filtering what is relevant and discarding what isn't. Bunka is a valuable tool for accomplishing this task.Framing Analysis: Data can be analyzed in countless ways, contingent on your objectives and interests. We've developed a tool that enables you to visualize data by semantically customizing your own axes.Discover different examples using our Google Colab NotebooksThemeGoogle Colab LinkVisual Topic Modeling with BunkaCleaning dataset for fine-tuning LLM using BunkaUnderstanding a dataset using Frame Analysis with BunkaFull Introduction to Topic Modeling, Data Cleaning and Frame Analysis with Bunka.Installation via PippipinstallbunkatopicsInstallation via Git Clonegitclonehttps://github.com/charlesdedampierre/BunkaTopics.gitcdBunkaTopics
pipinstall-e.Quick StartUploading Sample DataTo get started, let's upload a sample of Medium Articles into Bunkatopics:fromdatasetsimportload_datasetdocs=load_dataset("bunkalab/medium-sample-technology")["train"]["title"]Choose Your Embedding ModelBunkatopics offers seamless integration with Huggingface's extensive collection of embedding models. You can select from a wide range of models, but be mindful of their size. Please refer to the langchain documentation for details on available models.frombunkatopicsimportBunkafromlangchain_community.embeddingsimportHuggingFaceEmbeddings# Choose your embedding modelembedding_model=HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")# We recommend starting with a small model# Initialize Bunka with your chosen model and language preferencebunka=Bunka(embedding_model=embedding_model,language='english')# You can choose any language you prefer# Fit Bunka to your text databunka.fit(full_docs)>>>bunka.get_topics(n_clusters=15,name_length=3)# Specify the number of terms to describe each topicTopics are described by the most specific terms belonging to the cluster.topic_idtopic_namesizepercentbt-12technology - Tech - Children - student - days32210.73bt-11blockchain - Cryptocurrency - sense - Cryptocurrencies - Impact2839.43bt-7gadgets - phone - Device - specifications - screen2588.6bt-8software - Kubernetes - ETL - REST - Salesforce2588.6bt-1hackathon - review - Recap - Predictions - Lessons2578.57bt-4Reality - world - cities - future - Lot2468.2bt-14Product - Sales - day - dream - routine2418.03bt-0Words - Robots - discount - NordVPN - humans2086.93bt-2Internet - Overview - security - Work - Development2026.73bt-13Course - Difference - Step - science - Point1926.4bt-6quantum - Cars - Way - Game - quest1625.4bt-3Objects - Strings - app - Programming - Functions1193.97bt-5supply - chain - revolution - Risk - community1193.97bt-9COVID - printing - Car - work - app892.97bt-10Episode - HD - Secrets - TV441.47Visualize Your TopicsFinally, let's visualize the topics that Bunka has computed for your text data:bunka.visualize_topics(width=800,height=800,colorscale='YIGnBu')Topic Modeling with GenAI Summarization of TopicsExplore the power of Generative AI for summarizing topics!
We use the 7B-instruct model ofMistral AIfrom the huggingface hub using the langchain framework.fromlangchain.llmsimportHuggingFaceHub# Define the repository ID for Mistral-7B-v0.1repo_id='mistralai/Mistral-7B-v0.1'# Using Mistral AI to Summarize the Topicsllm=HuggingFaceHub(repo_id='mistralai/Mistral-7B-v0.1',huggingfacehub_api_token="HF_TOKEN")# Obtain clean topic names using Generative Modelbunka.get_clean_topic_name(generative_model=llm)bunka.visualize_topics(width=800,height=800,colorscale='Portland')Finally, let's visualize again the topics. We can chose from different colorscale.bunka.visualize_topics(width=800,height=800)YlGnBuPortlanddeltaBluesWe can now access the newly made topics>>>bunka.df_topics_topic_idtopic_namesizepercentbt-1Cryptocurrency Impact34512.32bt-3Data Management Technologies2438.68bt-14Everyday Life2308.21bt-0Digital Learning Campaign2258.04bt-12Business Development2237.96bt-2Technology Devices2127.57bt-10Market Predictions Recap2017.18bt-4Comprehensive Learning Journey1876.68bt-6Future of Work1856.61bt-11Internet Discounts1756.25bt-5Technological Urban Water Management1726.14bt-9Electric Vehicle Technology1455.18bt-8Programming Concepts1164.14bt-13Quantum Technology Industries1053.75bt-7High Definition Television (HDTV)361.29Manually Cleaning the topicsAre you happy with the topics yes ? Let's change them manually. Click on Apply changes when you are done. In the example, we changed the topicCryptocurrency ImpacttoCryptocurrencyandInternet DiscountstoAdvertising.The new topics will also appear on the Map.bunka.manually_clean_topics()Removing Data based on topics for fine-tuning purposesYou have the flexibility to construct a customized dataset by excluding topics that do not align with your interests. For instance, in the provided example, we omitted topics associated withAdvertisingandHigh-Definition television, as these clusters primarily contain promotional content that we prefer not to include in our model's training data.>>>bunka.clean_data_by_topics()>>>bunka.df_cleaned_doc_idcontenttopic_idtopic_name873ba315Invisibilize Data With JavaScriptbt-8Programming Concepts1243d58fWhy End-to-End Testing is Important for Your Teambt-3Data Management Technologies45fb8166This Tiny Wearable Device Uses Your Body Heat...bt-2Technology Devicesa122d1d2Digital Policy Salon: The Next Frontierbt-0Digital Learning Campaign1bbcfc1cPreparing Hardware for Outdoor Creative Technology Installationsbt-5Technological Urban Water Management79580c34Angular Or React ?bt-8Programming Conceptsaf0b08a2Ed-Tech Startups Are Cashing in on Parents’ Insecuritiesbt-0Digital Learning Campaign2255c350Former Google CEO Wants to Create a Government-Funded University to Train A.I. Codersbt-6Future of Workd2bc4b33Applying Action & The Importance of Ideasbt-12Business Development5219675eWhy You Should (not?) Use Signalbt-2Technology Devices............Bourdieu MapThe Bourdieu map provides a 2-Dimensional unsupervised scale to visualize various texts. Each region on the map represents a distinct topic, characterized by its most specific terms. Clusters are formed, and their names are succinctly summarized using Generative AI.The significance of this visualization lies in its ability to define axes, thereby creating continuums that reveal data distribution patterns. This concept draws inspiration from the work of the renowned French sociologist Bourdieu, who employed 2-Dimensional maps to project items and gain insights.fromlangchain.llmsimportHuggingFaceHub# Define the HuggingFaceHub instance with the repository ID and API tokenllm=HuggingFaceHub(repo_id='mistralai/Mistral-7B-v0.1',huggingfacehub_api_token="HF_TOKEN")## Bourdieu Figbourdieu_fig=bunka.visualize_bourdieu(llm=llm,x_left_words=["This is about business"],x_right_words=["This is about politics"],y_top_words=["this is about startups"],y_bottom_words=["This is about governments"],height=800,width=800,clustering=True,topic_n_clusters=10,density=False,convex_hull=True,radius_size=0.2,label_size_ratio_clusters=80)# Display the Bourdieu mapbourdieu_fig.show()positive/negative vs humans/machinespolitics/business vs humans/machinespolitics/business vs     positive/negativepolitics/business vs startups/governmentsFront-endThis is a beta feature. First, git clone the repositorygitclonehttps://github.com/charlesdedampierre/BunkaTopics.gitcdBunkaTopics
pipinstall-e.Then carry out a Topic Modeling and launch the serveur:frombunkatopicsimportBunkafromlangchain_community.embeddingsimportHuggingFaceEmbeddings# Choose your embedding modelembedding_model=HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")# We recommend starting with a small model# Initialize Bunka with your chosen model and language preferencebunka=Bunka(embedding_model=embedding_model,language='english')# You can choose any language you prefer# Fit Bunka to your text databunka.fit(full_docs)bunka.get_topics(n_clusters=15,name_length=3)# Specify the number of terms to describe each topicbunka.start_server()# A serveur will open on your computer at http://localhost:3000/