GrammaticalFramework / gf-core

Grammatical Framework core: compiler, shell & runtimes
https://www.grammaticalframework.org
Other
131 stars 35 forks source link

complete function returns non-deterministic results #158

Open Saibo-creator opened 1 year ago

Saibo-creator commented 1 year ago

Hello, Today I noticed two wired behaviors while using complete function with GF.

The following code are executed with pyg==1.0

Strange Behavior Reproduction 1

Take this PGF file as example: https://listenmaa.fi/b/Foods.pgf

In python interpreter, run the following command line by line

import pgf
grammar = pgf.readPGF("Foods.pgf")
lang = grammar.languages["FoodsEng"]
x = lang.complete("that fish is very delicious")
print([t for t in x] )
# [(4.9416422843933105, 'very', 'Quality', 'Very'),
# (6.887552261352539, 'very', 'Quality', 'Very')]

# Do it again
x = lang.complete("that fish is very delicious")
print([t for t in x] )

# [(4.9416422843933105, 'very', 'Quality', 'Very'),
# (6.887552261352539, 'very', 'Quality', 'Very')]

# Do it again
x = lang.complete("that fish is very delicious")
print([t for t in x] )
# [(6.887552261352539, 'very', 'Quality', 'Very')]

# Do it again
x = lang.complete("that fish is very delicious")
print([t for t in x] )
# []

# Do it again
x = lang.complete("that fish is very delicious")
print([t for t in x] )
# [(6.887552261352539, 'very', 'Quality', 'Very')]

It seems the completion results change every time, and if I restart the python interpreter and do it again , it also changes.

Strange Behavior Reproduction 2

If I put the above code into a python script, say run.py and execute it with python interpreter.

The results will always be empty list;

[]
[]
[]
[]
[]

This seems to be deterministic, but it doesn't align with the above behavior.

How would you interpret these two behavior ?