{ "cells": [ { "cell_type": "markdown", "id": "local-0", "metadata": {}, "source": [ "# 2026-2 RAG · RTX 5070 Ti 후속 평가\n", "\n", "1차 제출과 같은 공식 BM25 후보를 사용해 BGE 가중치의 효과를 분리합니다.\n", "같은 파인튜닝 BGE 순위에서 1차 답변 프롬프트와 근거 중심 프롬프트를 비교합니다.\n", "정답은 순위나 답변을 만드는 데 사용하지 않으며, 마지막 채점에서만 사용합니다.\n", "\n", "[전처리 코퍼스·PID 매핑·BM25 색인](https://huggingface.co/datasets/EllaNAM/rag-assignment-processed-bm25/tree/45666fd968034ff46d875613d08f5bd070462e96) · `45666fd968034ff46d875613d08f5bd070462e96`\n", "\n", "완성된 Windows 전처리 코퍼스와 BM25 색인에서 동일한 비교를 실행합니다.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "local-1", "metadata": { "execution": { "iopub.execute_input": "2026-12-04T13:23:42.996796Z", "iopub.status.busy": "2026-12-04T13:23:42.996796Z", "iopub.status.idle": "2026-12-04T13:23:49.051742Z", "shell.execute_reply": "2026-12-04T13:23:49.051742Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\hjn40\\Documents\\Codex\\2026-12-04\\zip-2026-2-rag-windows-pc\\work\\submission\\Source Code\\.venv-win\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "NVIDIA GeForce RTX 5070 Ti 12.8\n" ] } ], "source": [ "from pathlib import Path\n", "import os\n", "import sys\n", "\n", "PROJECT = Path.cwd()\n", "if not (PROJECT / 'src').is_dir():\n", " PROJECT = PROJECT / 'Source Code'\n", "sys.path.insert(0, str(PROJECT))\n", "sys.path.insert(0, str(PROJECT / 'src'))\n", "ROOT = Path(os.environ.get('RAG_WORK_ROOT', 'D:/project/rag-assignment-2026-2'))\n", "os.environ.setdefault('HF_HUB_CACHE', str(ROOT / 'hf' / 'hub'))\n", "os.environ.setdefault('HF_HUB_DISABLE_IMPLICIT_TOKEN', '1')\n", "os.environ.setdefault('JAX_PLATFORMS', 'cpu')\n", "\n", "import torch\n", "from local_followup import prepare, rank, generate, compare\n", "\n", "LIMIT = None # Dev 1,000문항. 실행 점검은 8 등으로 설정합니다.\n", "USE_PROCESSED = True # True면 완성된 로컬 전처리 색인을 별도 평가합니다.\n", "ARTIFACT_REPO = 'EllaNAM/rag-assignment-processed-bm25'\n", "ARTIFACT_REVISION = '45666fd968034ff46d875613d08f5bd070462e96'\n", "probe = torch.ones((16, 16), device='cuda', dtype=torch.float16)\n", "assert (probe @ probe)[0, 0].item() == 16\n", "print(torch.cuda.get_device_name(), torch.version.cuda)\n", "del probe\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "local-2", "metadata": { "execution": { "iopub.execute_input": "2026-12-04T13:23:49.053750Z", "iopub.status.busy": "2026-12-04T13:23:49.053750Z", "iopub.status.idle": "2026-12-04T13:23:49.068256Z", "shell.execute_reply": "2026-12-04T13:23:49.068256Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\r", "Load D:\\project\\rag-assignment-2026-2\\data\\dev_qa.jsonl...: 0it [00:00, ?it/s]" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\r", "Load D:\\project\\rag-assignment-2026-2\\data\\dev_qa.jsonl...: 1000it [00:00, 286378.81it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "1000 D:\\project\\rag-assignment-2026-2\\dev-followup\\processed\\ad2292d5950a\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "processed_root = ROOT / 'local-colab-artifacts'\n", "processed_files = ('processed_corpus.jsonl', 'pid_remap.json', 'bm25/sparse_index.json',\n", " 'bm25/data.csc.index.npy', 'bm25/indices.csc.index.npy',\n", " 'bm25/indptr.csc.index.npy', 'bm25/params.index.json', 'bm25/vocab.index.json')\n", "if USE_PROCESSED and not all((processed_root / name).is_file() for name in processed_files):\n", " if ARTIFACT_REVISION is None:\n", " raise RuntimeError('전처리 데이터의 검증된 공개 커밋을 매개변수에 입력하세요.')\n", " from huggingface_hub import snapshot_download\n", " snapshot_download(\n", " ARTIFACT_REPO, repo_type='dataset', revision=ARTIFACT_REVISION,\n", " local_dir=processed_root, token=False,\n", " allow_patterns=['processed_corpus.jsonl', 'pid_remap.json', 'bm25/*', 'build-info.json'],\n", " )\n", "qa, settings, output = prepare(ROOT, LIMIT, USE_PROCESSED)\n", "output.mkdir(parents=True, exist_ok=True)\n", "print(len(qa), output)\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "local-3", "metadata": { "execution": { "iopub.execute_input": "2026-12-04T13:23:49.068256Z", "iopub.status.busy": "2026-12-04T13:23:49.068256Z", "iopub.status.idle": "2026-12-04T13:25:56.589111Z", "shell.execute_reply": "2026-12-04T13:25:56.589111Z" } }, "outputs": [], "source": [ "# MiniLM 후보는 한 번만 계산해 두 BGE 모델에 공통으로 사용합니다.\n", "ranking = rank(qa, settings, output)\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "local-4", "metadata": { "execution": { "iopub.execute_input": "2026-12-04T13:25:56.589111Z", "iopub.status.busy": "2026-12-04T13:25:56.589111Z", "iopub.status.idle": "2026-12-04T13:33:10.928009Z", "shell.execute_reply": "2026-12-04T13:33:10.928009Z" } }, "outputs": [], "source": [ "# 리랭커가 GPU에서 내려간 상태에서 Qwen을 한 번만 올립니다.\n", "generate(qa, settings, output, ranking)\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "local-5", "metadata": { "execution": { "iopub.execute_input": "2026-12-04T13:33:10.930096Z", "iopub.status.busy": "2026-12-04T13:33:10.929098Z", "iopub.status.idle": "2026-12-04T13:33:34.054170Z", "shell.execute_reply": "2026-12-04T13:33:34.054170Z" } }, "outputs": [ { "data": { "text/html": [ "
| \n", " | questions | \n", "recall@100 | \n", "recall@5 | \n", "span_em | \n", "em | \n", "f1 | \n", "generation_seconds | \n", "
|---|---|---|---|---|---|---|---|
| experiment | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| first-prompt | \n", "1000 | \n", "0.894 | \n", "0.775 | \n", "0.485 | \n", "0.383 | \n", "0.506548 | \n", "213.922352 | \n", "
| evidence-prompt | \n", "1000 | \n", "0.894 | \n", "0.775 | \n", "0.449 | \n", "0.383 | \n", "0.485398 | \n", "205.577156 | \n", "