How to use data from this repo?
- User
How to use data from this repo?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
How to use data from this repo?
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
To use the data from the IDAO-2022 repository, follow these steps:
data directory.structures subdirectory. Each JSON file represents a crystal structure using the pymatgen library format.targets.csv. This file has two columns:
The repository provides a Python script (baseline.py) that demonstrates how to load and process the data. Here’s a breakdown of the relevant code:
import pandas as pd
from pathlib import Path
from pymatgen.core import Structure
def read_pymatgen_dict(file):
with open(file, "r") as f:
d = json.load(f)
return Structure.from_dict(d)
def prepare_dataset(dataset_path):
dataset_path = Path(dataset_path)
targets = pd.read_csv(dataset_path / "targets.csv", index_col=0)
struct = {
item.name.strip(".json"): read_pymatgen_dict(item)
for item in (dataset_path / "structures").iterdir()
}
data = pd.DataFrame(columns=["structures"], index=struct.keys())
data = data.assign(structures=struct.values(), targets=targets)
return train_test_split(data, test_size=0.25, random_state=666)
Explanation:
read_pymatgen_dict: This function reads a JSON file and converts it into a pymatgen Structure object.prepare_dataset: This function loads the targets from targets.csv and the structures from the structures directory, then combines them into a pandas DataFrame. It also splits the data into training and testing sets.The repository uses the MEGNet model, a graph neural network designed for materials, to predict the band gap energy.
The training process is defined in the main function of baseline.py:
def main(config):
train, test = prepare_dataset(config["datapath"])
model = prepare_model(
float(config["model"]["cutoff"]),
float(config["model"]["lr"]),
)
model.train(
train.structures,
train.targets,
validation_structures=test.structures,
validation_targets=test.targets,
epochs=int(config["model"]["epochs"]),
batch_size=int(config["model"]["batch_size"]),
)
Explanation:
prepare_model function initializes the MEGNet model with the specified parameters (e.g., cutoff distance, learning rate).model.train function trains the model using the training data and validates it using the testing data.After training, you can generate predictions on new data using the generate_submission.py script:
def main(config):
model = prepare_model(
float(config["model"]["cutoff"]), float(config["model"]["lr"])
)
model.load_weights(config['checkpoint_path'])
dataset_path = Path(config['test_datapath'])
struct = {item.name.strip('.json'): read_pymatgen_dict(item) for item in (dataset_path/'structures').iterdir()}
private_test = pd.DataFrame(columns=['id', 'structures'], index=struct.keys())
private_test = private_test.assign(structures=struct.values())
private_test = private_test.assign(predictions=model.predict_structures(private_test.structures))
private_test[['predictions']].to_csv('./submission.csv', index_label='id')
Explanation:
config.yaml) and uses it to predict the band gap energy for structures in the test dataset.submission.csv).python baseline.py
python generate_submission.py
pip install -r requirements.txt
config.yaml file:
model:
epochs: 800
batch_size: 128
lr: 2e-4
cutoff: 4
baseline.py.generate_submission.py.config.yaml file to adjust model parameters.If you have any further questions or encounter issues, feel free to reach out!