Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid compilation caused by categorical Aggregate with default=None #25

Open
langosco opened this issue Jan 25, 2024 · 1 comment
Open

Comments

@langosco
Copy link
Contributor

Raising a separate issue to track a problem mentioned in #11.

Programs containing multiple categorical aggregates can sometimes compile invalidly (i.e. the output of the compiled model doesn't match the output of the rasp program).

This probably happens because the value None is just propagated forward unchanged in the rasp program. In the compiled model, Nones are converted to 0s, on which further operations can be performed (if I'm not mistaken).

Example:

from tracr.rasp import rasp
from tracr.compiler import compiling, validating

sel = rasp.Select(rasp.indices, rasp.tokens, rasp.Comparison.EQ)
sop = rasp.Aggregate(sel, rasp.indices)
program = rasp.Aggregate(sel, sop)


model = compiling.compile_rasp_to_model(program, vocab={1,2,3,4}, max_seq_len=5, compiler_bos="BOS")
compiled_output = model.apply(["BOS", 1, 2, 3, 4]).decoded
rasp_output = program([1, 2, 3, 4])


# The output of the compiled model does not match the output of the RASP program:
print(rasp_output)  # [2.0, 3.0, None, None]
print(compiled_output) # ['BOS', 2, 3, 0, 1]

# The validator doesn't catch the error:
print(validating.validate(program, [1, 2, 3, 4])) # []
@langosco
Copy link
Contributor Author

langosco commented Mar 11, 2024

Here's a shorter example (a single Select-Aggregate) of a categorical aggregate compiling incorrectly:

example_program = rasp.categorical(rasp.Aggregate(
    rasp.Select(rasp.tokens, rasp.tokens, predicate=rasp.Comparison.FALSE),
    rasp.tokens,
))

compiled = compiling.compile_rasp_to_model(example_program, vocab=set(range(5)), max_seq_len=5)

print(example_program([1,2,3]))  # [None, None, None]
print(compiled.apply(["compiler_bos", 1,2,3]).decoded)  # ["compiler_bos", 1, 1, 1]

For general inputs, compiled will return the minimum of the input sequence (1 in the example above). IMO the desired behavior here would be to consistently return 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant