Skip to content

Misc Scripts

Patrick Hammer edited this page Jul 25, 2021 · 12 revisions

Concept filter Allows to filter for the highest k useful concepts and their beliefs:

./NAR shell InspectionOnExit < nalfile.nal  | python3 concept_usefulness_filter.py 10

Memory export and import in another instance

Training an instance for 5K steps, then exporting the 5 best concepts:

./NAR pong2 5000 InspectionOnExit | python3 concept_usefulness_filter.py 5 > PongKnowledge

Using this knowledge, the new instance will play perfectly immediately:

./NAR shell pong2 < PongKnowledge

Graph export Together with the previous it allows to visualize and output the most useful concepts:

./NAR shell InspectionOnExit < nalfile.nal | python3 concept_usefulness_filter.py 10 | python3 concepts_to_graph.py

Derivation priority filter Allows to show only derivations above a certain priority threshold:

./NAR shell | python3 DerivationPriorityFilter.py 0.8

Python interface The interface file is available in /misc/Python/NAR.py From there:

>>> import NAR as nar
>>> print(nar.AddInput("<a --> b>."))
{'input': [{'occurrenceTime': 'eternal', 'punctuation': '.', 'term': '<a --> b>', 'truth': {'frequency': '1.000000,', 'confidence': '0.900000'}}], 'derivations': [], 'answers': [], 'executions': []}
>>> print(nar.AddInput("<?1 --> b>?"))
{'input': [{'occurrenceTime': 'eternal', 'punctuation': '?', 'term': '<?1 --> b>'}], 'derivations': [], 'answers': [{'occurrenceTime': 'eternal', 'punctuation': '0', 'term': '<a --> b>', 'truth': {'frequency': '1.000000,', 'confidence': '0.900000'}}], 'executions': []}
>>> print(nar.AddInput("*stats"))
{'countConceptsMatchedTotal': 1.0, 'countConceptsMatchedMax': 1.0, 'countConceptsMatchedAverage': 0.0, 'currentTime': 2.0, 'total_concepts': 1.0, 'Maximum_chain_length_in_concept_hashtable': 1.0, 'Maximum_chain_length_in_atoms_hashtable': 1.0}
>>> nar.Exit()

Example of processing toothbrush.nal with UDPNAR (Continuous run of ONA):
Run with --verbose to see the steps of the demo
Run with --iterations to get an average of real-time required for handling toothbrush.nal

python3 toothbrush_demo.py --verbose
python3 toothbrush_demo.py --iterations 20

IRC interface
Run via irc_nar.py, needs Python 2.

English to Narsese

python3 english_to_narsese.py | ./NAR shell

Please see the description at the beginning of the script for more details.

ConceptNet knowledge channel

python3 concept_net_narsese.py | ./NAR shell

This will query the channel whenever a question is asked to the system. It can also be configured to query on belief inputs as well.

And it can be combined with the English to Narsese channel and syntax highlighting:

python3 english_to_narsese.py EternalOutput | python3 concept_net_narsese.py | ./NAR shell | python3 colorize.py

whereby EternalOutput makes sure the outputs created by the language channel aren't events but encoded as time-independent knowledge. This can also be controlled at runtime by receiving the *eternal=false / *eternal=true command from STDIN.

Example questions about relations present in ConceptNet:

a cat is an animal?
whiskers are part of cats?
cats are made of fur?

Vision Channel

Vision based on YOLOv4, as the robot experiment uses, example:

python3 vision_to_narsese.py | ./NAR shell | python3 colorize.py

or combined with language input and syntax highlighting:

python3 english_to_narsese.py | python3 vision_to_narsese.py | ./NAR shell | python3 colorize.py

Clone this wiki locally