Download tasks/adsorption_laboratory/solution/reference/main.py from Tokenwave-AI/REE: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/datasets/Tokenwave-AI/REE/resolve/main/tasks/adsorption_laboratory/solution/reference/main.py
- Command line
-
hf download hf://datasets/Tokenwave-AI/REE/tasks/adsorption_laboratory/solution/reference/main.py
-
curl -L -o main.py https://huggingface.co/datasets/Tokenwave-AI/REE/resolve/main/tasks/adsorption_laboratory/solution/reference/main.py
1.32 kB
| """Fit the published forest on practice training data plus this instance.""" | |
| import sys | |
| import time | |
| from runtime import featurize, load_pool, make_model, record_id | |
| from interface.data import load, write | |
| import numpy as np | |
| def main(): | |
| start = time.monotonic() | |
| train, query = load(sys.argv[1]) | |
| pool_x, pool_y, pool_ids = load_pool() | |
| features = featurize(train + query, workers=4) | |
| # During practice rehearsal the current cohort is already in the pool. | |
| # Include each of its training rows once, with its current supplied label. | |
| current_ids = {record_id(row) for row in train} | |
| keep = np.fromiter((value not in current_ids for value in pool_ids), dtype=bool) | |
| x = np.concatenate((pool_x[keep], features[:len(train)])) | |
| y = np.concatenate((pool_y[keep], [row['response'] for row in train])) | |
| print(f'fit: {int(keep.sum())} pooled + {len(train)} current = {len(y)} rows; ' | |
| f'{len(pool_y)-int(keep.sum())} overlapping rows excluded', file=sys.stderr, flush=True) | |
| model = make_model(workers=4) | |
| model.fit(x, y) | |
| predictions = model.predict(features[len(train):]) if query else np.empty(0) | |
| write(sys.argv[2], query, predictions) | |
| print(f'prediction complete: {time.monotonic()-start:.3f}s', file=sys.stderr, flush=True) | |
| if __name__ == '__main__': | |
| main() | |