Prolog and LLMs/GenAI?

The key are feature vectors. According to Geoffrey Hinton’s
own statements, there was a prototype of a Little Language
Model (lLM) in 1985, he mentions it in the middle of his talk here:

Will Digital Intelligence Replace Biological Intelligence?
Geoffrey Hinton - 2024
https://www.youtube.com/watch?v=Es6yuMlyfPw

He spends a few minutes in the talk to explain how feature vectors
can represent meaning of words. And I suspect his ILM has
been reflected in this paper, probably the ChatGPT LLM ancestor:

Learning Distributed Representations of Concepts
Geoffrey Hinton - 1986
https://www.cs.toronto.edu/~hinton/absps/families.pdf

Prologers should be familier with the example he uses, i.e. Family Trees.
BTW: The family tree of Geoffrey Hinton himself is also interesting,
he is great-great-grandson of the logician George Boole.

1 Like

Hi,

My name is Antonio Pisani, and my first experience with Prolog dates back to the early ’80s when I was in college. At the time, Philippe Roussel and Gérard Battani were teaching at my university, which made for an exciting introduction to the “new” language.

After a 30-year hiatus, I’ve returned to my software development roots. Over the past few months, I’ve been working on an interface between LangChain and Prolog, which you can check out here:

:link: GitHub Repository: LangChain-Prolog

For a quick example, take a look at this toy project:

:pushpin: Example: Travel Agent

I’d love to hear your feedback and would greatly appreciate any contributions!

1 Like

Everybody working on LLMs hopes fervently that this can be made to work but it won’t work. The “reasoning” has to happen before answers are generated, but what you (and others) propose to do is basically applying a filter to the already-generated text. Unfortunately nobody knows how to get LLMs to generate correct answers, with respect to some query, in any kind of reliable manner. You can filter wrong answers forever without ever finding a grain of truth, just like you can sieve the waters of the Klondike river forever without finding a grain of gold.

To be fair, “reasoning” as it’s used in LLM circles is nothing but the latest buzzword that will soon fall out of fashion and use (a few months ago it was all about “scaling” but now that’s gone the way of the dodo the community needs some other distant and incomprehensible vision to run after like an alcoholic chasing a mirage of the largest bottle of whisky in the world).

For the same reason whatever work is done to integrate LLMs with Prolog will not have any lasting effect. Maybe some new people will join the Prolog community, if they catch the logic programming bug by using Prolog-LLM integrations. Maybe not. But the LLM folks will soon get over their manic reasoning phase and move on to something else that won’t need any Prolog. So it will all just be wasted time and effort.

Better spend this energy on something else. For those in the logic progamming community interested in machine learning I recommend they bring themselves up to speed with the latest advances and directions in Inductive Logic Programming work, which they are perfectly placed to understand, appreciate, use and even contribute to.

2 Likes

I think it depends on the type of query. I think you can get them to generate correct responses for simple one step queries, in a structured form. Especially if the query is about some other block of text specified in the prompt, not referring to “internal knowledge” stored in the weights during training. And this kind of thing can be improved with fine tuning.

For example I asked Sonnet 3.0:
“”"
Identify all the fruits in the following text:
“For breakfast, Bob had eggs, toast, coffee and an apple.”
Format your response as a JSON list.
“”"

and it responded:
“”"
Here is the JSON list of fruits in the original text:
[“apple”]
“”"

What fruits are or even what a JSON list looks like is still internal knowledge stored in the weights. The point I think @stassa.p is making is that it giving the correct answer in this one case is essentially a coincidence, not evidence of understanding. It’s entirely possible some simple permutation of the input could make it output something wildly different (note that it included a JSON list in the output, but its response was not in fact a JSON list as requested!). You’re shaking a magic eight-ball and sometimes the “answers” seem to resonate.

1 Like

Thanks for sharing this, it looks interesting. I was able to install it and get the basic examples working.

1 Like

This is great, thank you for sharing! I see in your examples you show Prolog playing the role of a knowledge base in a RAG-type system, very cool and makes sense! There are some other cool features of Prolog that I think could be useful to LLMs, such as a reasoning agent for certain types of reasoning and/or constraint problems. While it’s already great to use Prolog as a knowledgebase for a RAG, have you thought of any other applications you could use your library for?

My initial idea was to use Prolog as a reasoning engine to control the reasoning process and workflow of LLM-based agents. However, I decided to take a simpler approach and integrate the library into an existing ecosystem (LangChain/LangGraph) rather than building a standalone solution.

As it stands today, the library can serve as a tool for an LLM-based agent to extend its knowledge or enhance its reasoning capabilities. Another potential use case is as a guardrail system, ensuring that LLM responses comply with specific restrictions to prevent inappropriate, dangerous, or off-topic interactions.

My goal is to develop real-world examples that demonstrate the library’s potential and spark interest in both the library itself and Prolog. Any help or collaboration in this effort would be greatly appreciated!

The prolog interface has already been included in LangChain documentation:

Does this mean that pip install langchain-prolog installs swi-prolog as well? Because I don’t see the documentation saying that dei-prolog needs to be installed as a prerequisite

No. SWI-Prolog is a prerequisite.

The read the docs langchain-prolog’s page and the github repository’s readme do mention it:

but the langchain documentation indeed fails to mention this. I will see if they agree to include it. Thank you for bringing this up.

1 Like

I developed a small demo to showcase how easy is to integrate Prolog with an LLM based application:

It runs in Google Colab and it does not require any local installation.

I’d love to hear your thoughts!

The translation from natural language to a prolog query is useful, assuming the knowledge base already exists.
Do you plan to add features for extracting prolog facts from text and asserting them into the knowledge base?
James

Knowledge graphs and ontological reasoning are promising for applying Prolog’s solution search capabilities. However, extracting knowledge from text and other types of media is the difficult part.

Some people are using LLMs, which shine in natural language ‘understanding,’ but the extracted knowledge typically requires validation to prevent hallucinations and incorrect relationships from being inserted into the database.

I think the most effective approach would be to use LLMs and Prolog as part of a pipeline where the LLM extracts initial structured knowledge, and a Prolog rule-based systems verify and constrains the output by linking to existing knowledge bases or applying a scoring system.

I am still figuring out what to prioritize, and this is on the shortlist, but it will take me a few months of research—because the last time I worked on something like this, ELIZA was still a thing.

Clicked on the on the link and this was the result.

Note: I do not use Google Colab.

Click on “ Open With” and select “Google Colaboratory”.

If you don’t see “Google Colaboratory” in the drop-down menu, select “Connect more apps” and you should see “Google Colaboratory” in the app list.

Fixed!

2 Likes