# Shuffled Documents

*English translation by SOTA – AI Community of the Indonesian original: pages 20–22 of [EKKA_2025_coding_problems.pdf](https://ioai.toki.id/assets/soal2025/EKKA_2025_coding_problems.pdf), the printed Colab notebooks of the programming problems of the OSN 2025 AI Exhibition final. The other pages of that PDF print the Monte Carlo Simulation, Cinema Ticket EDA and Face or Flag notebooks, which have their own translations. The printed documents are the task data and stay in Indonesian. Organisers who would like this translation removed can email sota.ai.community@gmail.com.*

*Printed notebook: Paragraph_Nama.ipynb – Colab, 9 October 2025.*

## Acak Dokumen (Shuffled Documents)

Aji has been assigned to send documents containing important information that will become part of an effort to document human knowledge and experience, in case this civilisation one day disappears. These documents contain Indonesian-language writing on various topics, and **each is guaranteed** to consist of 2 paragraphs. For security reasons, the first and second paragraphs are stored in different lists, namely the lists `first` and `second`.

However, Ammar played a prank on Aji's computer system, and the list of second paragraphs has now been shuffled! In other words, the partner of `first[i]` is no longer guaranteed to be `second[i]`. Now Aji is asking for your help to restore the original pairs of these documents!

## Reading the Data

The code fragment below is there to help download the file. It does not need to be changed; just run it!

```python
from datasets import load_dataset

def read_wikipair_texts(base):
    ds = load_dataset(base)

    first  = [str(x) for x in list(ds["first_part"]["text"])  if x is not None]
    second = [str(x) for x in list(ds["second_part"]["text"]) if x is not None]

    return first, second
```

The following is the process for downloading the data. In this case, we use the development set, or **dev** data, which contains only 25 documents.

These are **NOT** the documents that will be used for scoring.

```python
first, second = read_wikipair_texts("afaji/wikipair-dev")
```

Let us look at an example.

You can see that the `first` and `second` data do not match as pairs! Your task is to match them up again.

```python
import textwrap

print("First 1\n", textwrap.fill(first[0], width=80))
print("First 2\n", textwrap.fill(first[1], width=80))
print("---")
print("Second 1\n", textwrap.fill(second[0], width=80))
print("Second 2\n", textwrap.fill(second[1], width=80))
```

Output (dataset text, in Indonesian):

```text
First 1
 Teknik pembuatan batik tradisional melibatkan penggunaan canting untuk
menggambar motif halus dan cap (temple) untuk mencetak motif berulang secara
lebih cepat. Motif-motif batik sarat makna, mulai dari motif keraton yang
melambangkan status dan aturan adat hingga motif rakyat yang mencerminkan
kehidupan sehari-hari dan alam. Batik juga memiliki fungsi ritual dan simbolis,
banyak dipakai dalam upacara adat, pernikahan, dan kegiatan resmi. Perawatan,
pewarnaan alami, dan keterampilan pengerjaan menjadi bagian penting dalam
menjaga kualitas batik tradisional.
First 2
 Olimpiade Sains Nasional (OSN) adalah kompetisi tahunan yang bertujuan
mengembangkan bakat dan kemampuan siswa dalam berbagai bidang sains. Kegiatan
ini diselenggarakan oleh Kementerian Pendidikan, Kebudayaan, Riset, dan
Teknologi bekerja sama dengan dinas pendidikan provinsi dan kabupaten/kota. OSN
terbuka bagi siswa jenjang SD, SMP, dan SMA yang tertarik menguji kemampuan
akademik di bidang seperti matematika, fisika, kimia, biologi, komputer, dan
ilmu kebumian. Kompetisi ini juga berfungsi sebagai sarana seleksi untuk
pembinaan lebih lanjut dan representasi daerah di tingkat nasional maupun
internasional.
---
Second 1
 Kesempatan muncul ketika Jepang menyerah kepada Sekutu pada Agustus 1945,
menciptakan kekosongan kekuasaan di Indonesia. Pemuda nasionalis menekan tokoh
seperti Soekarno dan Hatta untuk segera memproklamasikan kemerdekaan, termasuk
insiden Rengasdengklok yang memicu percepatan rencana. Pada 17 Agustus 1945,
Soekarno membacakan Proklamasi Kemerdekaan Republik Indonesia yang
ditandatangani bersama Mohammad Hatta. Proklamasi itu kemudian diikuti
pembentukan pemerintahan awal dan komite persiapan kemerdekaan.
Second 2
 Thailand merupakan sebuah monarki konstitusional dengan raja sebagai kepala
negara dan perdana menteri sebagai kepala pemerintahan. Sejarahnya mencakup
kerajaan-kerajaan besar seperti Sukhothai dan Ayutthaya, dan wilayah ini pernah
dikenal dengan nama Siam. Berbeda dengan banyak negara tetangga, Thailand
berhasil mempertahankan kemerdekaan dari kolonialisasi Barat selama era
imperialisme. Politik modern Thailand telah mengalami sejumlah perubahan
konstitusional dan periode ketidakstabilan, termasuk kudeta militer dan
demonstrasi pro-demokrasi.
```

For example, for the dev data, the partner of `first[0]` is `second[11]`. This can be seen below:

```python
print(textwrap.fill(first[0], width=80))
print()
print(textwrap.fill(second[11], width=80))
```

Output (dataset text, in Indonesian):

```text
Teknik pembuatan batik tradisional melibatkan penggunaan canting untuk
menggambar motif halus dan cap (temple) untuk mencetak motif berulang secara
lebih cepat. Motif-motif batik sarat makna, mulai dari motif keraton yang
melambangkan status dan aturan adat hingga motif rakyat yang mencerminkan
kehidupan sehari-hari dan alam. Batik juga memiliki fungsi ritual dan simbolis,
banyak dipakai dalam upacara adat, pernikahan, dan kegiatan resmi. Perawatan,
pewarnaan alami, dan keterampilan pengerjaan menjadi bagian penting dalam
menjaga kualitas batik tradisional.

Pada masa kolonial batik mendapat perhatian luas dan mengalami perubahan
produksi serta pasar karena permintaan ekspor dan pengaruh luar. Setelah
kemerdekaan, batik terus berkembang baik sebagai identitas nasional maupun
komoditas ekonomi, dengan munculnya perancang kontemporer yang menggabungkan
unsur tradisi dan modernitas. Pada 2009 batik Indonesia diakui oleh UNESCO
sebagai Warisan Budaya Takbenda, yang meningkatkan upaya pelestarian dan
promosi. Saat ini batik tetap hidup melalui pendidikan, industri kreatif, dan
inisiatif pelestarian yang melibatkan komunitas pengrajin.
```

## YOUR TASK

Determine the correct pairs between the paragraphs in the lists first and second. Complete the following function: given the lists first_list and second_list, return a list of indices.

The value at position `i` in the answer list must be the index in second of the partner of `first[i]`.

For example, for the **dev** data, the output at position `0` is `11`

```python
import random

# TODO: COMPLETE THIS FUNCTION
# given a first paragraph text and a list of second paragraphs, return the most likely pair index
def predict_pair(first_list: list[str], second_list: list[str]):
  answer = []
  N = len(first_list)
  for i in range(N):
    answer.append(random.randint(0, N - 1))

  return answer
```

## Making Predictions on the Dev Data

The function fragment below makes predictions on all the data and, if the labels are given, also computes the accuracy.

```python
def run_and_evaluate(first, second, golds):
  preds = predict_pair(first, second)

  # print accuracy from a list of gold label
  if golds is not None:
    correct = 0
    for i in range(len(preds)):
      if preds[i] == golds[i]:
        correct += 1
    print("Accuracy:", 100 * correct / len(preds), "%")
```

Let us call the evaluation function. Note that the answer key is available only for the **dev** data.

```python
# golds is indexed from 1 - N, so we offset by 1
golds = [(int(x) - 1) for x in load_dataset("afaji/wikipair-dev-answer")['answer']['label']]

run_and_evaluate(first, second, golds)
```

```text
Accuracy: 4.0 %
```

## SCORING: Making Predictions on the Test Data

Your actual task is to match the documents in the **test** data, which contains 300 documents in total.

However, for security reasons, and so that Ammar does not play pranks again, Aji will only open access to this data in the last hour of the competition! In the meantime, you can experiment with the **dev** data above first!

So the following part of the program can only be run in the last hour!

```python
first_test, second_test = read_wikipair_texts("afaji/wikipair-test")
run_and_evaluate(first_test, second_test, None)
```

Output in the printed notebook (last line of the traceback):

```text
DatasetNotFoundError: Dataset 'afaji/wikipair-test' doesn't exist on the Hub or cannot be accessed.
```

## Scoring

The participant with the best accuracy will receive a perfect score (100). The baseline accuracy is 0%. Participants whose accuracy is equal to or lower than the baseline will receive 0.

Otherwise, participants receive a normalised score:

100 * (participant_accuracy - baseline) / (best_participant - baseline)

The baseline is 0%
