forked from shawntan/neural-turing-machines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
27 lines (23 loc) · 1.16 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import numpy as np
import random
np.random.seed(1234)
random.seed(1234)
def copy(input_size,max_size):
sequence_length = max_size
sequence = np.random.binomial(1,0.5,(sequence_length,input_size-1)).astype(np.uint8)
input_sequence = np.zeros((sequence_length*2+1,input_size),dtype=np.float32)
output_sequence = np.zeros((sequence_length*2+1,input_size),dtype=np.float32)
input_sequence[:sequence_length,:-1] = sequence
input_sequence[sequence_length,-1] = 1
output_sequence[sequence_length+1:,:-1] = sequence
return input_sequence,output_sequence
def repeat_copy(input_size,max_size,num_repeats):
sequence_length = max_size
sequence = np.random.binomial(1,0.5,(sequence_length,input_size-1)).astype(np.uint8)
input_sequence = np.zeros((sequence_length+1+sequence_length*num_repeats+1,input_size),dtype=np.float32)
output_sequence = np.zeros((sequence_length+1+sequence_length*num_repeats+1,input_size),dtype=np.float32)
input_sequence[:sequence_length,:-1] = sequence
input_sequence[sequence_length,-1] = num_repeats
output_sequence[sequence_length+1:-1,:-1] = np.tile(sequence, (num_repeats, 1))
output_sequence[-1,-1] = 1
return input_sequence,output_sequence