In May of 2023, a period that is of course ancient history for ChatGPT, I wrote in Getting ChatGPT to turn a flat vocabulary list into a hierarchical taxonomy about how I used ChatGPT to turn a flat list of animal names, stored in a SKOS taxonomy, into a hierarchical SKOS taxonomy — one that indicated that “Bears” had a broader value of “Mammals”, “Apes” had a broader value of “Primates”, and so forth. The blog entry explains how adding hierarchy adds value to certain information assets, so automating the generation of a hierarchy automates the generation of value. The free version of ChatGPT did OK with this task; my friend Paul Prescod had more luck with the version that he was paying for.

Recently, having forgotten about my 2023 experiment with its very artificial sample data, I tried a more useful version of this experiment with a real-world example that would benefit the website that hosts these blog entries: my blog’s very flat list of categories that I assign to the entries. This list has always been generated by Hugo, the blog publishing software that I use.

What

I had ChatGPT sort and arrange the category names into an HTML version that used nested bulleted lists to show hierarchy, with each entry (not including the entries created just to group some existing ones) linking to the appropriate blog entries. You can see this generated HTML and also see it plugged in to my blog’s stylesheet at bobdc blog entry category hierarchy; take a look and try out some of the links!

With the hard part of identifying the relationships all done, it was easy to tell ChatGPT to output the same hierarchy in another syntax in addition to HTML bulleted lists: SKOS Turtle. The HTML version enhances my web site by making it easier for people to navigate to blog entries that would interest them, and the SKOS version can do even more, because it’s a knowledge graph. This is valuable for two reasons:

  • Augmenting your LLM prompts with your own specialized data (a practice known as Retrieval Augmented Generation, or RAG), can give you better answers. It turns out that the best way to do this is with specialized data stored as (knowledge) graphs, so we call this GraphRAG. Using an LLM to generate a knowledge graph that improves your future use of that LLM creates a positive feedback loop that can make your LLM usage and your data better and better.

  • As Aboard’s Paul Ford recently wrote in the Aboard newsletter Triple Threat, an LLM can populate a knowledge graph and you can then do structured queries of that knowledge graph. As he wrote there, “You can use the new AI to feed the old [RDF-based] AI good data, and then use the old AI to answer questions for the new AI so the new AI doesn’t make things up all the time.” (It is unfortunate that he shows an example of a SPARQL query of Wikidata and calls it “horrible”. People who have read my book Learning SPARQL know that SPARQL queries are often simple and straightforward; queries of a complicated data model like Wikidata are going to be complicated because of that complicated data model. To understand this better, see my quote of Dan Brickley and Libby Miller’s book Validating RDF Data in my blog entry What is RDF? You can see another example of misguided complaints about SPARQL syntax at Hey CNN, SPARQL isn’t so difficult.)

How

To keep this blog entry from getting too long, I put the key prompts and responses from my interaction with ChatGPT in a separate file. As with a lot of LLM prompt usage, I did an extended series of interactions until I got what I wanted and then told ChatGPT “Show me the prompt that would have worked as the first prompt of this session to get this same output with that same input.”

Next

The output needs a few corrections — for example, removing “Turtle” as a subcategory of “XML”. If I was going to re-run the generation prompt as part of a production system, I would find a way to automate that.

I should try it with another LLM such as Claude to see what the differences might be, especially if this was going to be part of a production system. Loading the SKOS version into a triplestore and then trying a few SPARQL queries on it might also inspire some ideas about how to generate an even better SKOS version of this data. But, compared with my 2013 attempt to have ChatGPT generate a hierarchy with the very artificial input data of a set of animal names that I manually threw together, having it generate a hierarchy from real metadata that can help a system do its job better was great to see.


Comments? Reply to my Mastodon or Bluesky posts announcing this blog entry.