How to use openai - 10 common examples

To help you get started, we’ve selected a few openai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Separius / BERT-keras / tests / test_transformer.py View on Github external
n_transfer = 1 + 12 * 12

        def model(X, train=False, reuse=False):
            with tf.variable_scope('model', reuse=reuse):
                we = tf.get_variable("we", [n_vocab + TextEncoder.SPECIAL_COUNT + n_ctx, n_embd],
                                     initializer=tf.random_normal_initializer(stddev=0.02))
                we = dropout(we, embd_pdrop, train)
                h = embed(X, we)
                for layer in range(n_layer):
                    h = block(h, 'h%d' % layer, train=train, scale=True)
                return h

        X_train = tf.placeholder(tf.int32, [n_batch_train, n_ctx, 2])
        res = model(X_train)

        params = find_trainable_variables('model')
        sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True))
        sess.run(tf.global_variables_initializer())

        with open('openai/model/params_shapes.json') as f:
            shapes = json.load(f)
        offsets = np.cumsum([np.prod(shape) for shape in shapes])
        init_params = [np.load('openai/model/params_{}.npy'.format(n)) for n in range(10)]
        init_params = np.split(np.concatenate(init_params, 0), offsets)[:-1]
        init_params = [param.reshape(shape) for param, shape in zip(init_params, shapes)]
        init_params[0] = init_params[0][:n_ctx]
        init_params[0] = np.concatenate(
            [init_params[1], (np.random.randn(TextEncoder.SPECIAL_COUNT, n_embd) * 0.02).astype(np.float32),
             init_params[0]], 0)
        del init_params[1]

        sess.run([p.assign(ip) for p, ip in zip(params[:n_transfer], init_params[:n_transfer])])
github Separius / BERT-keras / tests / test_transformer.py View on Github external
def model(X, train=False, reuse=False):
            with tf.variable_scope('model', reuse=reuse):
                we = tf.get_variable("we", [n_vocab + TextEncoder.SPECIAL_COUNT + n_ctx, n_embd],
                                     initializer=tf.random_normal_initializer(stddev=0.02))
                we = dropout(we, embd_pdrop, train)
                h = embed(X, we)
                for layer in range(n_layer):
                    h = block(h, 'h%d' % layer, train=train, scale=True)
                return h
github Separius / BERT-keras / tests / test_transformer.py View on Github external
def model(X, train=False, reuse=False):
            with tf.variable_scope('model', reuse=reuse):
                we = tf.get_variable("we", [n_vocab + TextEncoder.SPECIAL_COUNT + n_ctx, n_embd],
                                     initializer=tf.random_normal_initializer(stddev=0.02))
                we = dropout(we, embd_pdrop, train)
                h = embed(X, we)
                for layer in range(n_layer):
                    h = block(h, 'h%d' % layer, train=train, scale=True)
                return h
github Separius / BERT-keras / tests / test_transformer.py View on Github external
def model(X, train=False, reuse=False):
            with tf.variable_scope('model', reuse=reuse):
                we = tf.get_variable("we", [n_vocab + TextEncoder.SPECIAL_COUNT + n_ctx, n_embd],
                                     initializer=tf.random_normal_initializer(stddev=0.02))
                we = dropout(we, embd_pdrop, train)
                h = embed(X, we)
                for layer in range(n_layer):
                    h = block(h, 'h%d' % layer, train=train, scale=True)
                return h
github vladfi1 / phillip / openai.py View on Github external
def __init__(self, conv, permutation):
    self.conv = conv
    self.permutation = permutation
    
    self.space = spaces.Tuple([conv.space for _ in permutation])
  
  def __call__(self, array):
    return [self.conv(array[i]) for i in self.permutation]

maxCharacter = 32 # should be large enough?

maxAction = 0x017E
numActions = 1 + maxAction

frameConv = RealConv(0, 100)
speedConv = RealConv(-10, 10) # generally around 0

player_spec = [
  ('percent', RealConv(0, 200)),
  ('facing', RealConv(-1, 1)),
  ('x', RealConv(-100, 100)),
  ('y', RealConv(-100, 100)),
  ('action_state', DiscreteConv(numActions, 'action_state')),
  ('action_frame', frameConv),
  ('character', DiscreteConv(maxCharacter, 'character')),
  ('invulnerable', boolConv),
  ('hitlag_frames_left', frameConv),
  ('hitstun_frames_left', frameConv),
  ('jumps_used', DiscreteConv(8, 'jumps_used')),
  ('charging_smash', boolConv),
  ('in_air', boolConv),
  ('speed_air_x_self', speedConv),
github vladfi1 / phillip / openai.py View on Github external
('y', RealConv(-100, 100)),
  ('action_state', DiscreteConv(numActions, 'action_state')),
  ('action_frame', frameConv),
  ('character', DiscreteConv(maxCharacter, 'character')),
  ('invulnerable', boolConv),
  ('hitlag_frames_left', frameConv),
  ('hitstun_frames_left', frameConv),
  ('jumps_used', DiscreteConv(8, 'jumps_used')),
  ('charging_smash', boolConv),
  ('in_air', boolConv),
  ('speed_air_x_self', speedConv),
  ('speed_ground_x_self', speedConv),
  ('speed_y_self', speedConv),
  ('speed_x_attack', speedConv),
  ('speed_y_attack', speedConv),
  ('shield_size', RealConv(0, 1)),
]

playerConv = StructConv(player_spec)

def gameSpec(self=0, enemy=1, swap=False):
  players = [self, enemy]
  if swap:
    players.reverse()
  
  return [
    ('players', ArrayConv(playerConv, players)),
    ('stage', DiscreteConv(32)),
  ]

game_spec = gameSpec()
gameConv = StructConv(game_spec)
github vladfi1 / phillip / openai.py View on Github external
self.space = spaces.Tuple([conv.space for _ in permutation])
  
  def __call__(self, array):
    return [self.conv(array[i]) for i in self.permutation]

maxCharacter = 32 # should be large enough?

maxAction = 0x017E
numActions = 1 + maxAction

frameConv = RealConv(0, 100)
speedConv = RealConv(-10, 10) # generally around 0

player_spec = [
  ('percent', RealConv(0, 200)),
  ('facing', RealConv(-1, 1)),
  ('x', RealConv(-100, 100)),
  ('y', RealConv(-100, 100)),
  ('action_state', DiscreteConv(numActions, 'action_state')),
  ('action_frame', frameConv),
  ('character', DiscreteConv(maxCharacter, 'character')),
  ('invulnerable', boolConv),
  ('hitlag_frames_left', frameConv),
  ('hitstun_frames_left', frameConv),
  ('jumps_used', DiscreteConv(8, 'jumps_used')),
  ('charging_smash', boolConv),
  ('in_air', boolConv),
  ('speed_air_x_self', speedConv),
  ('speed_ground_x_self', speedConv),
  ('speed_y_self', speedConv),
  ('speed_x_attack', speedConv),
  ('speed_y_attack', speedConv),
github vladfi1 / phillip / openai.py View on Github external
def __call__(self, array):
    return [self.conv(array[i]) for i in self.permutation]

maxCharacter = 32 # should be large enough?

maxAction = 0x017E
numActions = 1 + maxAction

frameConv = RealConv(0, 100)
speedConv = RealConv(-10, 10) # generally around 0

player_spec = [
  ('percent', RealConv(0, 200)),
  ('facing', RealConv(-1, 1)),
  ('x', RealConv(-100, 100)),
  ('y', RealConv(-100, 100)),
  ('action_state', DiscreteConv(numActions, 'action_state')),
  ('action_frame', frameConv),
  ('character', DiscreteConv(maxCharacter, 'character')),
  ('invulnerable', boolConv),
  ('hitlag_frames_left', frameConv),
  ('hitstun_frames_left', frameConv),
  ('jumps_used', DiscreteConv(8, 'jumps_used')),
  ('charging_smash', boolConv),
  ('in_air', boolConv),
  ('speed_air_x_self', speedConv),
  ('speed_ground_x_self', speedConv),
  ('speed_y_self', speedConv),
  ('speed_x_attack', speedConv),
  ('speed_y_attack', speedConv),
  ('shield_size', RealConv(0, 1)),
github vladfi1 / phillip / openai.py View on Github external
self.space = spaces.Tuple([conv.space for _ in permutation])
  
  def __call__(self, array):
    return [self.conv(array[i]) for i in self.permutation]

maxCharacter = 32 # should be large enough?

maxAction = 0x017E
numActions = 1 + maxAction

frameConv = RealConv(0, 100)
speedConv = RealConv(-10, 10) # generally around 0

player_spec = [
  ('percent', RealConv(0, 200)),
  ('facing', RealConv(-1, 1)),
  ('x', RealConv(-100, 100)),
  ('y', RealConv(-100, 100)),
  ('action_state', DiscreteConv(numActions, 'action_state')),
  ('action_frame', frameConv),
  ('character', DiscreteConv(maxCharacter, 'character')),
  ('invulnerable', boolConv),
  ('hitlag_frames_left', frameConv),
  ('hitstun_frames_left', frameConv),
  ('jumps_used', DiscreteConv(8, 'jumps_used')),
  ('charging_smash', boolConv),
  ('in_air', boolConv),
  ('speed_air_x_self', speedConv),
  ('speed_ground_x_self', speedConv),
  ('speed_y_self', speedConv),
  ('speed_x_attack', speedConv),
github vladfi1 / phillip / openai.py View on Github external
class ArrayConv:
  def __init__(self, conv, permutation):
    self.conv = conv
    self.permutation = permutation
    
    self.space = spaces.Tuple([conv.space for _ in permutation])
  
  def __call__(self, array):
    return [self.conv(array[i]) for i in self.permutation]

maxCharacter = 32 # should be large enough?

maxAction = 0x017E
numActions = 1 + maxAction

frameConv = RealConv(0, 100)
speedConv = RealConv(-10, 10) # generally around 0

player_spec = [
  ('percent', RealConv(0, 200)),
  ('facing', RealConv(-1, 1)),
  ('x', RealConv(-100, 100)),
  ('y', RealConv(-100, 100)),
  ('action_state', DiscreteConv(numActions, 'action_state')),
  ('action_frame', frameConv),
  ('character', DiscreteConv(maxCharacter, 'character')),
  ('invulnerable', boolConv),
  ('hitlag_frames_left', frameConv),
  ('hitstun_frames_left', frameConv),
  ('jumps_used', DiscreteConv(8, 'jumps_used')),
  ('charging_smash', boolConv),
  ('in_air', boolConv),