text: __author__ = 'Alex Ozerin'
  
  import os
  import re
  from glob import glob
  
  DATADIR = '../data'  # unzipped train and test data
  OUTDIR = './model-k'  # just a random name
  # Data Loading
  
  POSSIBLE_LABELS = 'yes no up down left right on off stop go silence unknown'.split()
  id2name = {i: name for i, name in enumerate(POSSIBLE_LABELS)}
  name2id = {name: i for i, name in id2name.items()}
  
  
  def load_data(data_dir):
      """ Return 2 lists of tuples:
      [(class_id, user_id, path), ...] for train
      [(class_id, user_id, path), ...] for validation
      """
      # Just a simple regexp for paths with three groups:
      # prefix, label, user_id
      pattern = re.compile("(.+\/)?(\w+)\/([^_]+)_.+wav")
      all_files = glob(os.path.join(data_dir, 'train/audio/*/*wav'))
  
      with open(os.path.join(data_dir, 'train/validation_list.txt'), 'r') as fin:
          validation_files = fin.readlines()
      valset = set()
      for entry in validation_files:
          r = re.match(pattern, entry)
          if r:
              valset.add(r.group(3))
  
      possible = set(POSSIBLE_LABELS)
      train, val = [], []
      for entry in all_files:
          r = re.match(pattern, entry)
          if r:
              label, uid = r.group(2), r.group(3)
              if label == '_background_noise_':
                  label = 'silence'
              if label not in possible:
                  label = 'unknown'
  
              label_id = name2id[label]
  
              sample = (label_id, uid, entry)
              if uid in valset:
                  val.append(sample)
              else:
                  train.append(sample)
  
      print('There are {} train and {} val samples'.format(len(train), len(val)))
      return train, val
  
  
  trainset, valset = load_data(DATADIR)
  