class_docstr: Implements a recurrent DQN designed to produce melody sequences.
class_docstr_tok: ["Implements","a","recurrent","DQN","designed","to","produce","melody","sequences","."]
docstr: Applies a penalty for playing notes not in a specific key.
  
  Args:
    action: One-hot encoding of the chosen action.
    penalty_amount: The amount the model will be penalized if it plays
      a note outside the key.
    key: The numeric values of notes belonging to this key. Defaults to
      C-major if not provided.
  Returns:
    Float reward value.
docstr_tok: ["Applies","a","penalty","for","playing","notes","not","in","a","specific","key",".","Args",":","action",":","One-hot","encoding","of","the","chosen","action",".","penalty_amount",":","The","amount","the","model","will","be","penalized","if","it","plays","a","note","outside","the","key",".","key",":","The","numeric","values","of","notes","belonging","to","this","key",".","Defaults","to","C-major","if","not","provided",".","Returns",":","Float","reward","value","."]
code: def reward_key(self, action, penalty_amount=-1.0, key=None):
      """Applies a penalty for playing notes not in a specific key.
  
      Args:
        action: One-hot encoding of the chosen action.
        penalty_amount: The amount the model will be penalized if it plays
          a note outside the key.
        key: The numeric values of notes belonging to this key. Defaults to
          C-major if not provided.
      Returns:
        Float reward value.
      """
      if key is None:
          key = rl_tuner_ops.C_MAJOR_KEY
  
      reward = 0
  
      action_note = np.argmax(action)
      if action_note not in key:
          reward = penalty_amount
  
      return reward
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import os
  import random
  import urllib
  from magenta.models.rl_tuner import note_rnn_loader
  from magenta.models.rl_tuner import rl_tuner_eval_metrics
  from magenta.models.rl_tuner import rl_tuner_ops
  import matplotlib.pyplot
  from note_seq import melodies_lib
  from note_seq import midi_io
  import numpy
  import scipy.special
  from six.moves import range
  from six.moves import reload_module
  from six.moves import urllib
  import tensorflow.compat.v1
label_desc: Use image node_id 20 for calling the RLTuner obj's underlying member method code with example usage: obj.reward_key(action, penalty_amount, key) and returns: reward