saulpw/aipl

!cross ordering

dovinmu opened this issue · 2 comments

I want to run a series of items through a number of models, but I want to load each model exactly once and then do all the inferences on it before moving to the next one. I have this example script:

# get list of models we're testing
!read
data/simple-models.txt
!split>model sep=\n
!global models

# get our task. prompt and examples are strings, data is a list of objects with key "datum"
!read
data/simple-task.json
!json-parse
!ref data
!cross <models

!format
{model}: {datum}
!print

But it prints out the following:

model1: datum1
model2: datum1
model3: datum1
model1: datum2
model2: datum2
model3: datum2
model1: datum3
model2: datum3
model3: datum3

Here is simple-task.json

{
    "prompt": "prompt",
    "example_datum": "example_datum",
    "example_response": "example_response",
    "data": [
        {
          "datum": "datum1"
        },
        {
          "datum": "datum2"
        },
        {
          "datum": "datum3"
        }
    ]
}

and simple-models.txt:

model1
model2
model3
saulpw commented

So, simply reversing the order of the tables will get the result you want. Here's an updated .aipl script (with data inline):

!json-parse
{
    "prompt": "prompt",
    "example_datum": "example_datum",
    "example_response": "example_response",
    "data": [
        { "datum": "datum1" },
        { "datum": "datum2" },
        { "datum": "datum3" }
    ]
}
!ref data
!global models

!literal
model1
model2
model3
!split>model

!cross <models
!format
{model}: {datum}
!print

okay, this works (after fixing the !global call and adding in a !cross)

# example of using !cross on model and datum so it's ordered sorted by model, so we load each model only once
!json-parse
{
    "prompt": "prompt",
    "example_datum": "example_datum",
    "example_response": "example_response",
    "data": [
        { "datum": "datum1" },
        { "datum": "datum2" },
        { "datum": "datum3" }
    ]
}
!ref data
!global data

!literal
model1
model2
model3
!split>model

!cross <data
!format
{model}: {datum}
!print
model1: datum1
model1: datum2
model1: datum3
model2: datum1
model2: datum2
model2: datum3
model3: datum1
model3: datum2
model3: datum3

thanks!