<jupyter_start><jupyter_text>> **How to run this notebook (command-line)?**1. Install the `reinvent_shared.v2.1` environment:`conda env create -f reinvent_shared.yml`2. Activate the environment:`conda activate reinvent_shared.v2.1`3. Execute `jupyter`:`jupyter notebook`4. Copy the link to a browser `REINVENT 2.0`: create model demoThe *create model* running mode can be used  when planning to train a new model from scratch. This mode is the first step of this process. During this step we only parse the training data and extract all relevant tockens that are used within the pool of smiles. This information is kept in model's vocabulary. However the model itself has not learned anything yet. The actual training is done in the second step when using *transfer learning* mode of `REINVENT 2.0`.To proceed, please update the following code block such that it reflects your system's installation and execute it.<jupyter_code># load dependencies
import os
import re
import json
import tempfile

# --------- change these path variables as required
reinvent_dir = os.path.expanduser("~/PycharmProjects/github_repositories/reinvent/")
reinvent_env = os.path.expanduser("~/miniconda3/envs/reinvent_shared.v2.1")
output_dir = os.path.expanduser("~/Desktop/REINVENT_create_model_demo")

# --------- do not change
# get the notebook's root path
try: ipynb_path
except NameError: ipynb_path = os.getcwd()

# if required, generate a folder to store the results
try:
    os.mkdir(output_dir)
except FileExistsError:
    pass<jupyter_output><empty_output><jupyter_text>Setting up the configuration`REINVENT` has an entry point that loads a specified `JSON` file on startup. `JSON` is a low-level data format that allows to specify a fairly large number of parameters in a cascading fashion very quickly. The parameters are structured into *blocks* which can in turn contain blocks or simple values, such as *True* or *False*, strings and numbers. In this tutorial, we will go through the different blocks step-by-step, explaining their purpose and potential values for given parameters. Note, that while we will write out the configuration as a `JSON` file in the end, in `python` we handle the same information as a simple `dict`.<jupyter_code># initialize the dictionary
configuration = {
    "version": 2,                          # we are going to use REINVENT's newest release
    "run_type": "create_model"              # other run types: "scoring", "validation",
                                           #                  "transfer_learning",
                                           #                  "reinforcement_learning" and
                                           #                  "sampling"
}
# add block to specify whether to run locally or not and
# where to store the results and logging
configuration["logging"] = {
    "sender": "http://127.0.0.1",          # only relevant if "recipient" is set to "remote"
    "recipient": "local",                  # either to local logging or use a remote REST-interface
    "logging_path": os.path.join(output_dir, "progress.log"), # where the run's output is stored
    "job_name": "Create model demo",       # set an arbitrary job name for identification
    "job_id": "demo"                       # only relevant if "recipient" is set to "remote"
}<jupyter_output><empty_output><jupyter_text>We will need to specify a path to an agent (parameter `model_path`), which can be a prior or trained agent. For the purpose of this notebook, we will use a prior shipped with the `REINVENT 2.0` repository.<jupyter_code># provide your input dataset that will be used for training 
#we use a purged dataset provided with this repo

input_SMILES_path = os.path.join(reinvent_dir, "data/chembl.filtered.smi") 
output_model_path = os.path.join(output_dir, "empty_model.ckpt")

# add the "parameters" block
configuration["parameters"] = {
    "output_model_path": output_model_path,
    "input_smiles_path": input_SMILES_path,
    "num_layers": 3,
    "layer_size": 512,
    "cell_type": "lstm",              # use lstm cell. The options are "gru" and "lstm"
    "embedding_layer_size": 256,      
    "dropout": 0.,
    "max_sequence_length": 256,
    "layer_normalization": False,
    "standardize": False              # standardization is set to false for efficientcy
                                      # we assume the data is being standardized during purging
                                      # for details check the Data Preparation notebook
  }
# write the configuration file to the disc
configuration_JSON_path = os.path.join(output_dir, "create_model_config.json")
with open(configuration_JSON_path, 'w') as f:
    json.dump(configuration, f, indent=4, sort_keys=True)<jupyter_output><empty_output><jupyter_text>Run `REINVENT`Now it is time to execute `REINVENT` locally. The execution time will vary dependent on the size of your dataset.The resulting file will be `empty_model.ckpt` wich can be used as an input for the `transfer learning` mode where the same smiles dataset should be used to train on for multiple epochs.The command-line execution looks like this:``` activate envionmentconda activate reinvent_shared.v2.1 execute REINVENTpython /input.py .json```<jupyter_code>%%capture captured_err_stream --no-stderr

# execute REINVENT from the command-line
!python {reinvent_dir}input.py {configuration_JSON_path}<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08197932053175776, 'fraction_numerical': 0.007016248153618907, 'mean_word_length': 3.4694719471947195, 'pattern_counts': {'":': 17, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '486638', 'license': 'MIT', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1447, 'n_words': 595, 'path': 'notebooks/Create_Model_Demo.ipynb', 'repo_name': 'shouti-fredchang/ReinventCommunity', 'size': '5416'}