meg HF Staff commited on
Commit
31f2126
·
verified ·
1 Parent(s): 2befb5b

Experimenting with something....

Browse files
Files changed (1) hide show
  1. app.py +28 -29
app.py CHANGED
@@ -29,6 +29,34 @@ DEV_AMOUNT = 10
29
  READ_DISTRO = False
30
  GATED_IMAGENET = os.environ.get("GATED_IMAGENET")
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  def main(percentage=10):
34
  global randomize_subset
@@ -78,34 +106,5 @@ def main(percentage=10):
78
  print("That took %d seconds" % (end - start))
79
 
80
 
81
- def get_label_fractions(dataset):
82
- print("Getting label proportions.")
83
- if READ_DISTRO:
84
- with open("label_distro.json", "r+") as f:
85
- label_counts = json.loads(f.read())
86
- else:
87
- label_counts = Counter([example['label'] for example in dataset])
88
- # Don't overrwrite the distribution when devving.
89
- if not DEV:
90
- with open("label_distro.json", "w+") as f:
91
- f.write(json.dumps(label_counts))
92
- label_list = list(label_counts.keys())
93
- denom = sum(label_counts.values())
94
- label_fractions = [label_counts[key]/denom for key in label_counts]
95
- return label_list, label_fractions
96
-
97
-
98
- def randomize_labels(examples, indices):
99
- # What set of examples should be randomized in this batch?
100
- # This is the intersection of the batch indices and the indices we randomly selected to change the labels of.
101
- batch_subset = list(set(indices) & randomize_subset)
102
- # If this batch has indices that we're changing the label of....
103
- if batch_subset != []:
104
- # Change the label to a random integer between 0 and 9
105
- for n in range(len(indices)):
106
- index = indices[n]
107
- examples["label"][n] = new_random_labels.pop() if index in batch_subset else examples["label"][n]
108
- return examples
109
-
110
  demo = gr.Interface(fn=main, inputs="text", outputs="text")
111
  demo.launch()
 
29
  READ_DISTRO = False
30
  GATED_IMAGENET = os.environ.get("GATED_IMAGENET")
31
 
32
+ def get_label_fractions(dataset):
33
+ print("Getting label proportions.")
34
+ if READ_DISTRO:
35
+ with open("label_distro.json", "r+") as f:
36
+ label_counts = json.loads(f.read())
37
+ else:
38
+ label_counts = Counter([example['label'] for example in dataset])
39
+ # Don't overrwrite the distribution when devving.
40
+ if not DEV:
41
+ with open("label_distro.json", "w+") as f:
42
+ f.write(json.dumps(label_counts))
43
+ label_list = list(label_counts.keys())
44
+ denom = sum(label_counts.values())
45
+ label_fractions = [label_counts[key]/denom for key in label_counts]
46
+ return label_list, label_fractions
47
+
48
+
49
+ def randomize_labels(examples, indices):
50
+ # What set of examples should be randomized in this batch?
51
+ # This is the intersection of the batch indices and the indices we randomly selected to change the labels of.
52
+ batch_subset = list(set(indices) & randomize_subset)
53
+ # If this batch has indices that we're changing the label of....
54
+ if batch_subset != []:
55
+ # Change the label to a random integer between 0 and 9
56
+ for n in range(len(indices)):
57
+ index = indices[n]
58
+ examples["label"][n] = new_random_labels.pop() if index in batch_subset else examples["label"][n]
59
+ return examples
60
 
61
  def main(percentage=10):
62
  global randomize_subset
 
106
  print("That took %d seconds" % (end - start))
107
 
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  demo = gr.Interface(fn=main, inputs="text", outputs="text")
110
  demo.launch()