cyrilzhang commited on
Commit
62bbe75
·
1 Parent(s): 5cf21c3

Update ace.py

Browse files
Files changed (1) hide show
  1. ace.py +25 -4
ace.py CHANGED
@@ -19,6 +19,7 @@ import json
19
  import os
20
 
21
  import datasets
 
22
 
23
 
24
  _CITATION = """\
@@ -49,6 +50,7 @@ class MockupDataset(datasets.GeneratorBasedBuilder):
49
  data_config['size'] = 100
50
 
51
  self.data_config = data_config
 
52
 
53
  def _info(self):
54
  features = datasets.Features(
@@ -79,8 +81,27 @@ class MockupDataset(datasets.GeneratorBasedBuilder):
79
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
80
  def _generate_examples(self, split):
81
  for i in range(self.data_config['size']):
82
- print('generator iter', i)
83
  yield i, {
84
- "x": [0]*self.data_config['length'],
85
- "y": [1]*self.data_config['length']
86
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  import os
20
 
21
  import datasets
22
+ import numpy as np
23
 
24
 
25
  _CITATION = """\
 
50
  data_config['size'] = 100
51
 
52
  self.data_config = data_config
53
+ self.sampler = AutomatonSampler(name, data_config)
54
 
55
  def _info(self):
56
  features = datasets.Features(
 
81
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
82
  def _generate_examples(self, split):
83
  for i in range(self.data_config['size']):
84
+ x, y = self.sampler.sample()
85
  yield i, {
86
+ "x": x,
87
+ "y": y
88
+ }
89
+
90
+ class AutomatonSampler:
91
+ def __init__(self, name, data_config):
92
+ self.name = name
93
+ self.data_config = data_config
94
+
95
+ if 'seed' in self.data_config:
96
+ self.np_rng = np.random.default_rng(self.data_config['seed'])
97
+ else:
98
+ self.np_rng = np.random.default_rng()
99
+
100
+ self.T = self.data_config['length']
101
+
102
+ def f(self, x):
103
+ return np.cumsum(x) % 2
104
+
105
+ def sample(self):
106
+ x = self.np_rng.binomial(1,0.5,size=self.T)
107
+ return x, self.f(x)