def make_module_spec(options, weight_file):
def module_fn():<EOL><INDENT>"""<STR_LIT>"""<EOL>_bos_id = <NUM_LIT><EOL>_eos_id = <NUM_LIT><EOL>_bow_id = <NUM_LIT><EOL>_eow_id = <NUM_LIT><EOL>_pad_id = <NUM_LIT><EOL>_max_word_length = <NUM_LIT:50><EOL>_parallel_iterations = <NUM_LIT:10><EOL>_max_batch_size = <NUM_LIT><EOL>id_dtype = tf.int32<EOL>id_nptype = np.int32<EOL>max_word_length = tf.constant(_max_word_length, dtype=id_dtype, name='<STR_LIT>')<EOL>version = tf.constant('<STR_LIT>', dtype=tf.string, name='<STR_LIT:version>')<EOL>def _make_bos_eos(c):<EOL><INDENT>r = np.zeros([_max_word_length], dtype=id_nptype)<EOL>r[:] = _pad_id<EOL>r[<NUM_LIT:0>] = _bow_id<EOL>r[<NUM_LIT:1>] = c<EOL>r[<NUM_LIT:2>] = _eow_id<EOL>return tf.constant(r, dtype=id_dtype)<EOL><DEDENT>bos_ids = _make_bos_eos(_bos_id)<EOL>eos_ids = _make_bos_eos(_eos_id)<EOL>def token2ids(token):<EOL><INDENT>with tf.name_scope("<STR_LIT>"):<EOL><INDENT>char_ids = tf.decode_raw(token, tf.uint8, name='<STR_LIT>')<EOL>char_ids = tf.cast(char_ids, tf.int32, name='<STR_LIT>')<EOL>char_ids = tf.strided_slice(char_ids, [<NUM_LIT:0>], [max_word_length - <NUM_LIT:2>],<EOL>[<NUM_LIT:1>], name='<STR_LIT>')<EOL>ids_num = tf.shape(char_ids)[<NUM_LIT:0>]<EOL>fill_ids_num = (_max_word_length - <NUM_LIT:2>) - ids_num<EOL>pads = tf.fill([fill_ids_num], _pad_id)<EOL>bow_token_eow_pads = tf.concat([[_bow_id], char_ids, [_eow_id], pads],<EOL><NUM_LIT:0>, name='<STR_LIT>')<EOL>return bow_token_eow_pads<EOL><DEDENT><DEDENT>def sentence_tagging_and_padding(sen_dim):<EOL><INDENT>with tf.name_scope("<STR_LIT>"):<EOL><INDENT>sen = sen_dim[<NUM_LIT:0>]<EOL>dim = sen_dim[<NUM_LIT:1>]<EOL>extra_dim = tf.shape(sen)[<NUM_LIT:0>] - dim<EOL>sen = tf.slice(sen, [<NUM_LIT:0>, <NUM_LIT:0>], [dim, max_word_length], name='<STR_LIT>')<EOL>bos_sen_eos = tf.concat([[bos_ids], sen, [eos_ids]], <NUM_LIT:0>, name='<STR_LIT>')<EOL>bos_sen_eos_plus_one = bos_sen_eos + <NUM_LIT:1><EOL>bos_sen_eos_pads = tf.pad(bos_sen_eos_plus_one, [[<NUM_LIT:0>, extra_dim], [<NUM_LIT:0>, <NUM_LIT:0>]],<EOL>"<STR_LIT>", name='<STR_LIT>')<EOL>return bos_sen_eos_pads<EOL><DEDENT><DEDENT>tokens = tf.placeholder(shape=(None, None), dtype=tf.string, name='<STR_LIT>')<EOL>sequence_len = tf.placeholder(shape=(None, ), dtype=tf.int32, name='<STR_LIT>')<EOL>tok_shape = tf.shape(tokens)<EOL>line_tokens = tf.reshape(tokens, shape=[-<NUM_LIT:1>], name='<STR_LIT>')<EOL>with tf.device('<STR_LIT>'):<EOL><INDENT>tok_ids = tf.map_fn(<EOL>token2ids,<EOL>line_tokens,<EOL>dtype=tf.int32, back_prop=False, parallel_iterations=_parallel_iterations,<EOL>name='<STR_LIT>')<EOL><DEDENT>tok_ids = tf.reshape(tok_ids, [tok_shape[<NUM_LIT:0>], tok_shape[<NUM_LIT:1>], -<NUM_LIT:1>], name='<STR_LIT>')<EOL>with tf.device('<STR_LIT>'):<EOL><INDENT>sen_ids = tf.map_fn(<EOL>sentence_tagging_and_padding,<EOL>(tok_ids, sequence_len),<EOL>dtype=tf.int32, back_prop=False, parallel_iterations=_parallel_iterations,<EOL>name='<STR_LIT>')<EOL><DEDENT>bilm = BidirectionalLanguageModel(options, str(weight_file),<EOL>max_batch_size=_max_batch_size)<EOL>embeddings_op = bilm(sen_ids)<EOL>elmo_output = weight_layers('<STR_LIT>', embeddings_op, l2_coef=<NUM_LIT:0.0>)<EOL>weighted_op = elmo_output['<STR_LIT>']<EOL>mean_op = elmo_output['<STR_LIT>']<EOL>word_emb = elmo_output['<STR_LIT>']<EOL>lstm_outputs1 = elmo_output['<STR_LIT>']<EOL>lstm_outputs2 = elmo_output['<STR_LIT>']<EOL>hub.add_signature("<STR_LIT>", {"<STR_LIT>": tokens, "<STR_LIT>": sequence_len},<EOL>{"<STR_LIT>": weighted_op,<EOL>"<STR_LIT:default>": mean_op,<EOL>"<STR_LIT>": word_emb,<EOL>"<STR_LIT>": lstm_outputs1,<EOL>"<STR_LIT>": lstm_outputs2,<EOL>"<STR_LIT:version>": version})<EOL>def_strings = tf.placeholder(shape=(None), dtype=tf.string)<EOL>def_tokens_sparse = tf.string_split(def_strings)<EOL>def_tokens_dense = tf.sparse_to_dense(sparse_indices=def_tokens_sparse.indices,<EOL>output_shape=def_tokens_sparse.dense_shape,<EOL>sparse_values=def_tokens_sparse.values,<EOL>default_value='<STR_LIT>'<EOL>)<EOL>def_mask = tf.not_equal(def_tokens_dense, '<STR_LIT>')<EOL>def_int_mask = tf.cast(def_mask, dtype=tf.int32)<EOL>def_sequence_len = tf.reduce_sum(def_int_mask, axis=-<NUM_LIT:1>)<EOL>def_tok_shape = tf.shape(def_tokens_dense)<EOL>def_line_tokens = tf.reshape(def_tokens_dense, shape=[-<NUM_LIT:1>], name='<STR_LIT>')<EOL>with tf.device('<STR_LIT>'):<EOL><INDENT>def_tok_ids = tf.map_fn(<EOL>token2ids,<EOL>def_line_tokens,<EOL>dtype=tf.int32, back_prop=False, parallel_iterations=_parallel_iterations,<EOL>name='<STR_LIT>')<EOL><DEDENT>def_tok_ids = tf.reshape(def_tok_ids, [def_tok_shape[<NUM_LIT:0>], def_tok_shape[<NUM_LIT:1>], -<NUM_LIT:1>], name='<STR_LIT>')<EOL>with tf.device('<STR_LIT>'):<EOL><INDENT>def_sen_ids = tf.map_fn(<EOL>sentence_tagging_and_padding,<EOL>(def_tok_ids, def_sequence_len),<EOL>dtype=tf.int32, back_prop=False, parallel_iterations=_parallel_iterations,<EOL>name='<STR_LIT>')<EOL><DEDENT>def_embeddings_op = bilm(def_sen_ids)<EOL>def_elmo_output = weight_layers('<STR_LIT>', def_embeddings_op, l2_coef=<NUM_LIT:0.0>, reuse=True)<EOL>def_weighted_op = def_elmo_output['<STR_LIT>']<EOL>def_mean_op = def_elmo_output['<STR_LIT>']<EOL>def_word_emb = def_elmo_output['<STR_LIT>']<EOL>def_lstm_outputs1 = def_elmo_output['<STR_LIT>']<EOL>def_lstm_outputs2 = def_elmo_output['<STR_LIT>']<EOL>hub.add_signature("<STR_LIT:default>", {"<STR_LIT>": def_strings},<EOL>{"<STR_LIT>": def_weighted_op,<EOL>"<STR_LIT:default>": def_mean_op,<EOL>"<STR_LIT>": def_word_emb,<EOL>"<STR_LIT>": def_lstm_outputs1,<EOL>"<STR_LIT>": def_lstm_outputs2,<EOL>"<STR_LIT:version>": version})<EOL><DEDENT>return hub.create_module_spec(module_fn)<EOL>
Makes a module spec.

    Args:
      options: LM hyperparameters.
      weight_file: location of the hdf5 file with LM weights.

    Returns:
      A module spec object used for constructing a TF-Hub module.