Skip to content

Commit

Permalink
Add data util to mask data
Browse files Browse the repository at this point in the history
  • Loading branch information
szaman19 committed Mar 5, 2024
1 parent e904f87 commit 4058954
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import numpy as np


def random_zero_array(arr, p, mask_token):
"""
Randomly zero out elements of an array with probability p
"""
mask = np.random.choice([0, 1], size=arr.shape, p=[p, 1 - p])
return arr * mask + mask_token * (1 - mask)

0 comments on commit 4058954

Please sign in to comment.