Function Repository Resource:

GenerateRelatedTopics

Source Notebook

Generate a list of related topics from a starting topic

Contributed by: Phileas Dazeley-Gaist

ResourceFunction["GenerateRelatedTopics"][topic]

generates a single idea related to topic.

ResourceFunction["GenerateRelatedTopics"][topic,n]

generate a list of n ideas related to topic.

ResourceFunction["GenerateRelatedTopics"][{topic1,topic2,},n]

generates n ideas related to the list {topic1,topic2,}.

ResourceFunction["GenerateRelatedTopics"][topic,Automatic]

generates an LLM-determined number of ideas related to topic.

ResourceFunction["GenerateRelatedTopics"][{topic1,topic2,},Automatic]

generates an LLM-determined number of related ideas to {topic1,topic2,}.

Details and Options

ResourceFunction["GenerateRelatedTopics"] inherits options from LLMFunction, and additionally takes the following options:
"TopicFormat""A few keywords "qualitatively specifies the text format of related topics
"TopicKind""Relevant ideas"qualitatively specifies the type of related topics
LLMEvaluator can be set to an LLMConfiguration object or an association as with LLMFunction.
When n is set to Automatic, the LLM could fail to format the list of related ideas appropriately, resulting in an error. This issue was not observed in practice during the development of this function.

Examples

Basic Examples (4) 

Generate a single idea related to a topic:

In[1]:=
ResourceFunction["GenerateRelatedTopics"]["Machine learning"]
Out[1]=

Generate three ideas related to a topic:

In[2]:=
ResourceFunction["GenerateRelatedTopics"]["Anthropology", 3]
Out[2]=

Generate three related ideas from a list of topics:

In[3]:=
ResourceFunction["GenerateRelatedTopics"][{"NASA", "NOAA"}, 3]
Out[3]=

Let the LLM choose how many related ideas to list:

In[4]:=
ResourceFunction["GenerateRelatedTopics"]["Jazz", Automatic]
Out[4]=

Options (4) 

TopicFormat (2) 

Specify the format for LLM-generated ideas:

In[5]:=
ResourceFunction["GenerateRelatedTopics"]["Quantum Physics", 2, "TopicFormat" -> "A short paragraph."]
Out[5]=

Since the format is specified qualitatively, it is quite flexible and open-ended:

In[6]:=
ResourceFunction["GenerateRelatedTopics"]["Astronomy", 3, "TopicFormat" -> "A pictorial description using only emojis"]
Out[6]=

TopicKind (2) 

Provide additional detail specifying the nature or related ideas to generate:

In[7]:=
ResourceFunction["GenerateRelatedTopics"]["Quantum Physics", 5, "TopicKind" -> "A related field"]
Out[7]=

Since the format is specified qualitatively, it is quite flexible and open-ended:

In[8]:=
ResourceFunction["GenerateRelatedTopics"]["Astronomy", 3, "TopicKind" -> "Area of major debate among scholars"]
Out[8]=

Applications (7) 

Generate research topic ideas:

In[9]:=
ResourceFunction["GenerateRelatedTopics"]["Origami mathematics", 3,
 "TopicFormat" -> "One descriptive sentence",
 "TopicKind" -> "Research topics"]
Out[9]=

Generate interdisciplinary research topic ideas:

In[10]:=
ResourceFunction[
 "GenerateRelatedTopics"][{"Physics", "Mathematics", "Ecology", "Sociology", "Geography"}, 3,
 "TopicFormat" -> "One descriptive sentence",
 "TopicKind" -> "Interdisciplinary research topics"]
Out[10]=

Generate fictional story elements based on a theme:

In[11]:=
ResourceFunction["GenerateRelatedTopics"]["Time Travel", 5, "TopicKind" -> "Fictional story elements"]
Out[11]=

Generate "hot takes":

In[12]:=
ResourceFunction["GenerateRelatedTopics"]["Back to the Future II", 3,
 "TopicFormat" -> "Short sentence (at least 10 words)",
 "TopicKind" -> "Very hot spicy takes"]
Out[12]=

Generate creative themes for a party or event:

In[13]:=
ResourceFunction["GenerateRelatedTopics"]["Party", 5, "TopicKind" -> "Unusual and fun themes"]
Out[13]=

Generate creative pet names:

In[14]:=
ResourceFunction["GenerateRelatedTopics"]["Chameleon", 5, "TopicKind" -> "Creative pet names"]
Out[14]=

List famous quotes related to a topic (you'll want to check that these are real):

In[15]:=
ResourceFunction[
 "GenerateRelatedTopics"]["Mindfulness and pragmatism", 3, "TopicFormat" -> "The quote, followed by attribution (name and last name) in parentheses", "TopicKind" -> "Famous quotes"]
Out[15]=

Properties and Relations (1) 

GenerateRelatedTopics defines and calls an LLMFunction to generate its output. Since LLMFunction defaults to using 0 as the temperature setting in the LLMEvaluator, GenerateRelatedTopics will consistently return the same output for a given input by default. To make GenerateRelatedTopics nondeterministic, you can set the temperature with the LLMEvaluator option like so:

In[16]:=
ResourceFunction[
 "GenerateRelatedTopics"]["Hitchhiker's Guide to the Galaxy - Don't Panic!", LLMEvaluator -> <|"Temperature" -> 0.7|>]
Out[16]=
In[17]:=
ResourceFunction[
 "GenerateRelatedTopics"]["Hitchhiker's Guide to the Galaxy - Don't Panic!", LLMEvaluator -> <|"Temperature" -> 0.7|>]
Out[17]=

Possible Issues (1) 

Different LLM services have varying rate limits on API calls. If the number of related topics requested exceeds the allowed rate limit for your specific LLM service or model, the function might not be able to generate all the requested topics in a single function call. This may result in incomplete output and error messages.

To mitigate this, consider adjusting the number of topics requested, using an LLM service with higher rate limits, or using multiple delayed function calls:

In[18]:=
DeleteCases[
 ResourceFunction["GenerateRelatedTopics"]["Machine learning", 50], _Failure]
Out[18]=
In[19]:=
% // Length
Out[19]=

Neat Examples (1) 

Use an LLM to generate a graph of related ideas (this may take a while to evaluate):

In[20]:=
AbsoluteTiming[
 Graph[#, VertexLabels -> Thread[VertexList[#1] -> (Framed[#1, Background -> White, RoundingRadius -> 5] &) /@ VertexList[#1]], VertexSize -> 0.1`] &@
  NestGraph[LLMRelatedIdeas[#, Automatic] &, "Pizza", 2]]
Out[20]=

Publisher

Phileas Dazeley-Gaist

Requirements

Wolfram Language 14.0 (January 2024) or above

Version History

  • 1.0.0 – 04 April 2025

Related Resources

License Information