Example data
Connect with an Enterprise SQL client. The examples use a small document table and a separate label table. Expand the setup below to create them.Create the example tables
Create the example tables
curation_documents has six records describing four documents.
curation_labels has one label for each of three documents. row_id identifies
a record; doc_id identifies the document it describes.Run each statement separately in a scratch database or namespace. Create these
tables once for the whole section, using fresh names if they already exist.score is a sample quality score, not a search result score. Document 10 has
two versions. Document 30 has two records at the same version. Document 40
has no label. These cases let you check the effect of each operation.Keep one record per document
row_number() numbers rows within each group. PARTITION BY defines the group,
and ORDER BY determines which record comes first. This query selects the
latest version of each document, using row_id to break ties:
row_id.
Without a complete ordering, the selected row among ties is not determined by
the query.
Use rank() instead of row_number() when tied records should all survive,
and order only by the fields that define a tie. Adding a unique tie-breaker
would make every rank distinct. The outer query filters the calculated rank
because window functions are evaluated after the inner query’s WHERE clause.
Select the highest-scoring records per class
Deduplicate first, then rank the labeled documents within each class:1 to the maximum number you want per class. A class with fewer records
cannot supply the full cap.
This selects by score, not at random. For a random subset, use
sampling instead of ordering by score or ID.
Training and evaluation splits
Ranking can divide ordered records into groups, but ordering by ID does not make those groups random or representative.ntile() produces approximately
equal-sized buckets within a partition; small classes may not populate every
bucket.
Choose the split policy for the task. Keep related records, such as revisions
of one document or frames from one video, in the same split to avoid leakage.
A time-based evaluation may instead require a cutoff date. Save the final
assignments or resulting datasets so later updates do not silently change the
evaluation population.
Compare neighboring records
lag() and lead() read neighboring rows in the specified order. For example,
inspect how scores change across a document’s records: