Two-table relationship

The two-table scenario includes a subject table and a linked table. Subject tables contain PII details about people, companies, or any other entities. Linked tables contain time-series or events data, one or many of which belong to a subject.

For example, the figure below shows the customers and purchases tables from the CDNOW dataset. The highlighted rows show the relationship between subject records from the customers table and their related events records from the purchases table.

MOSTLY AI - Two-table relationship - subject and linked table

To train a generator on a two-table dataset, you need to define the foreign key from the purchases table that points to the primary key to the users table.

If you use the web interface, add both tables to the generator and set their relationship.

Steps

  1. In MOSTLY AI, select Generators from the top menu.
  2. On the Generators page, click + New generator. MOSTLY AI - Generators page - Click New generator
  3. Upload the customers table.
    1. Click Upload file. MOSTLY AI - Generators page - Click Upload file
    2. Upload the customers table, leave its name as customers, and click Proceed.
      Step result: The table is now added to the generator. MOSTLY AI - Table baseball/players added
  4. Upload the purchases table.
    1. In the generator, click Add data. MOSTLY AI - Click Add data
    2. Click Upload files, upload the table, leave its name as purchases, and click Proceed.
      Step result: The table is now added to the generator.
  5. Set the relationship between the customers and purchases tables.
    1. Hover over the linked table (in this case purchases) and click Edit foreign keys. MOSTLY AI - Click Edit foreign keys
    2. In the drawer, click Add foreign key.
    3. For Foreign key, select the foreign key column for the purchases table. In this case, the users_id column.
    4. For Referenced table, select the table to which the foreign key points to. In this case, the customers table.
    5. For Referenced primary key, select the primary key column of the referenced table. In this case, the id column.
    6. Select the Is context checkbox.
    7. Click the confirmation button. MOSTLY AI - Click Edit foreign keys
  6. Click Close in the upper right to close the drawer.

Result

The two-table relationship foreign key is now set. The linked table purchases is now nested and indented under its subject table customers.

MOSTLY AI - Click Edit foreign keys

With the context relationship defined, the generator can capture the correlations and retain the referential integrity between the two tables during AI model training.

Optionally, you can click Relationship diagram to get an overview of all table relationships.

MOSTLY AI - Click Edit foreign keys

What's next

You can now train the generator on the CDNOW dataset with the default options. To do so, click Configure models and then Start training.