<jupyter_start><jupyter_text>Vocab generator<jupyter_code>import os
from typing import List
from typing import Tuple
import logging
from collections import defaultdict
from collections import Counter
import json
import torch
import numpy as np

import sys
sys.path.append(os.path.join(os.path.dirname("__file__"), '..', '..', 'dataset'))
def isnotebook():
    try:
        shell = get_ipython().__class__.__name__
        if shell == 'ZMQInteractiveShell':
            return True   # Jupyter notebook or qtconsole
        elif shell == 'TerminalInteractiveShell':
            return False  # Terminal running IPython
        else:
            return False  # Other type (?)
    except NameError:
        return False      # Probably standard Python interpreter
if isnotebook():
    device = torch.device("cpu")
else:
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

FORMAT = "%(asctime)-15s %(message)s"
logging.basicConfig(format=FORMAT, level=logging.INFO,
                    datefmt="%Y-%m-%d %H:%M")
logger = logging.getLogger(__name__)

from ReaSCAN_dataset import *
condition = "p1"

path_to_data = f"../../../data-files-updated/ReaSCAN-compositional-{condition}/data-compositional-splits.txt"
logger.info(f"Reading dataset from file: {path_to_data}...")
data_json = json.load(open(path_to_data, "r"))
train_dataset = ReaSCANDataset(
    data_json=data_json, 
    save_directory=f"../../../data-files-updated/ReaSCAN-compositional-{condition}/", 
    k=0, 
    split="train", 
    generate_vocabulary=True
)
train_dataset.save_vocabularies(
    input_vocabulary_file="input_vocabulary.txt", 
    target_vocabulary_file="target_vocabulary.txt"
)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup