|
| 1 | +# ESAE |
| 2 | + |
| 3 | +## Installation |
| 4 | + |
| 5 | +Please ensure that you have [Conda](https://conda.io/projects/conda/en/latest/user-guide/install/index.html) installed on your system, as it is required for managing dependencies in this project. |
| 6 | + |
| 7 | +To create and activate the Conda environment using the provided `environment.yml` file, please run the following command: |
| 8 | + |
| 9 | +```sh |
| 10 | +conda env create -f environment.yml |
| 11 | +conda activate esae |
| 12 | +``` |
| 13 | + |
| 14 | +Before proceeding, please update the system paths specified in `source/__init__.py` to match your configuration. These paths are used for storing the datasets, model checkpoints, and many others. |
| 15 | + |
| 16 | +```python |
| 17 | +from pathlib import Path |
| 18 | + |
| 19 | +workspace = Path("/data/user_data/haok/esae") |
| 20 | +workspace.mkdir(mode=0o770, parents=True, exist_ok=True) |
| 21 | + |
| 22 | +import os |
| 23 | + |
| 24 | +os.environ["HF_HOME"] = "/data/user_data/haok/huggingface" |
| 25 | +``` |
| 26 | + |
| 27 | +## Overview |
| 28 | + |
| 29 | +To train a Sparse Autoencoder (SAE), the first step is to download the dataset and compute the embeddings that will later be reconstructed. Initialize all datasets in this repository using the following command: |
| 30 | + |
| 31 | +```sh |
| 32 | +python3 -m source.dataset.msMarco |
| 33 | +``` |
| 34 | + |
| 35 | +### Running Experiments |
| 36 | + |
| 37 | +To experiment with different hyperparameters or model configurations, refer to the experiments in the `source/model/archive` directory. Each file in this directory contains a specific model setup. |
| 38 | + |
| 39 | +If you want to create a new experiment, you can do so by adding a new file with your desired hyperparameters and configurations. Once ready, run the following command, replacing {version} with your file name: |
| 40 | + |
| 41 | +```sh |
| 42 | +python3 -m source.model.{version} |
| 43 | +``` |
| 44 | + |
| 45 | +For example, if your new experiment file is under `source/model/240825A.py`, you would run: |
| 46 | + |
| 47 | +```sh |
| 48 | +python3 -m source.model.240825A |
| 49 | +``` |
| 50 | + |
| 51 | +Model checkpoints are automatically saved under `{workspace}/model/{version}/state/`, where workspace is the path specified in `source/__init__.py`. This makes it easy to manage and retrieve your experiment results. |
| 52 | + |
| 53 | +### Evaluating Performance |
| 54 | + |
| 55 | +## Quality Assurance |
| 56 | + |
| 57 | +### Standardized Interface |
| 58 | + |
| 59 | +To ensure a clean and reusable codebase, this repository follows best practices by defining the interfaces in `source/interface.py`. All core components implement standardized interfaces that promote consistency and modularity. For instance, the Dataset class defines a blueprint that any dataset must follow by implementing the didIter method. This method enables the client to iterate over all document IDs in batches. |
| 60 | + |
| 61 | +Here's an example: |
| 62 | + |
| 63 | +```python |
| 64 | +from abc import ABC, abstractmethod |
| 65 | +from typing import Iterator, List |
| 66 | + |
| 67 | +class Dataset(ABC): |
| 68 | + name: DatasetName |
| 69 | + |
| 70 | + @abstractmethod |
| 71 | + def didIter(self, batchSize: int) -> Iterator[List[int]]: |
| 72 | + """ |
| 73 | + Iterate over the document IDs. |
| 74 | +
|
| 75 | + :param batchSize: The batch size for each iteration. |
| 76 | + :return: The iterator over the document IDs. |
| 77 | + """ |
| 78 | + raise NotImplementedError |
| 79 | +``` |
| 80 | + |
| 81 | +### Testing Locally |
| 82 | + |
| 83 | +To ensure matainability, this codebase is fully type-checked using mypy and thoroughly tested with pytest. As new components are integrated into the interface, please ensure that corresponding test cases are added. Place your test cases under the relevant directories to keep the test suite comprehensive and organized. |
| 84 | + |
| 85 | +You can run the following commands to perform these checks: |
| 86 | + |
| 87 | +```sh |
| 88 | +mypy source |
| 89 | +pytest source |
| 90 | +``` |
0 commit comments