captchaboy commited on
Commit
9b0df90
1 Parent(s): 1910df1

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +11 -0
utils.py CHANGED
@@ -13,6 +13,7 @@ from torch.utils.data import ConcatDataset
13
 
14
  class CharsetMapper(object):
15
  """A simple class to map ids into strings.
 
16
  It works only when the character set is 1:1 mapping between individual
17
  characters and individual ids.
18
  """
@@ -22,6 +23,7 @@ class CharsetMapper(object):
22
  max_length=30,
23
  null_char=u'\u2591'):
24
  """Creates a lookup table.
 
25
  Args:
26
  filename: Path to charset file which maps characters to ids.
27
  max_sequence_length: The max length of ids and string.
@@ -37,8 +39,10 @@ class CharsetMapper(object):
37
 
38
  def _read_charset(self, filename):
39
  """Reads a charset definition from a tab separated text file.
 
40
  Args:
41
  filename: a path to the charset file.
 
42
  Returns:
43
  a dictionary with keys equal to character codes and values - unicode
44
  characters.
@@ -196,6 +200,12 @@ class Config(object):
196
  self.__setattr__(f'{prefix}{k}', v)
197
 
198
  assert os.path.exists(config_path), '%s does not exists!' % config_path
 
 
 
 
 
 
199
  self.global_workdir = os.path.join(self.global_workdir, self.global_name)
200
 
201
  def __getattr__(self, item):
@@ -245,6 +255,7 @@ def onehot(label, depth, device=None):
245
  Args:
246
  label: shape (n1, n2, ..., )
247
  depth: a scalar
 
248
  Returns:
249
  onehot: (n1, n2, ..., depth)
250
  """
 
13
 
14
  class CharsetMapper(object):
15
  """A simple class to map ids into strings.
16
+
17
  It works only when the character set is 1:1 mapping between individual
18
  characters and individual ids.
19
  """
 
23
  max_length=30,
24
  null_char=u'\u2591'):
25
  """Creates a lookup table.
26
+
27
  Args:
28
  filename: Path to charset file which maps characters to ids.
29
  max_sequence_length: The max length of ids and string.
 
39
 
40
  def _read_charset(self, filename):
41
  """Reads a charset definition from a tab separated text file.
42
+
43
  Args:
44
  filename: a path to the charset file.
45
+
46
  Returns:
47
  a dictionary with keys equal to character codes and values - unicode
48
  characters.
 
200
  self.__setattr__(f'{prefix}{k}', v)
201
 
202
  assert os.path.exists(config_path), '%s does not exists!' % config_path
203
+ with open(config_path) as file:
204
+ config_dict = yaml.load(file, Loader=yaml.FullLoader)
205
+ with open('configs/template.yaml') as file:
206
+ default_config_dict = yaml.load(file, Loader=yaml.FullLoader)
207
+ __dict2attr(default_config_dict)
208
+ __dict2attr(config_dict)
209
  self.global_workdir = os.path.join(self.global_workdir, self.global_name)
210
 
211
  def __getattr__(self, item):
 
255
  Args:
256
  label: shape (n1, n2, ..., )
257
  depth: a scalar
258
+
259
  Returns:
260
  onehot: (n1, n2, ..., depth)
261
  """