import tensorflow as tf

from ..embedding import embeddings_to_embedding, ids_to_embeddings, embeddings
from ..linear import linear
from ..dropout import dropout



def char2doc(forward_document,
             backward_document,
             *,
             char_space_size,
             char_embedding_size,
             document_embedding_size,
             dropout_prob,
             hidden_layer_size,
             output_layer_size,
             context_vector_size):
  with tf.variable_scope("char2doc"):
    char_embeddings = embeddings(id_space_size=char_space_size,
                                 embedding_size=char_embedding_size)

    def char_ids_to_doc_embedding(document):
      return embeddings_to_embedding(
          ids_to_embeddings(document, char_embeddings),
          output_embedding_size=document_embedding_size,
          context_vector_size=context_vector_size)

    document_embedding = tf.concat(
        1,
        list(map(char_ids_to_doc_embedding,
                 [forward_document, backward_document])))

    hidden_layer = dropout(_activate(linear(_activate(document_embedding),
                                            hidden_layer_size)),
                           dropout_prob)
    return linear(hidden_layer, output_layer_size)


def _activate(tensor):
  return tf.nn.elu(tensor)

import tensorflow as tf

from ..embedding import id_sequence_to_embedding, embeddings
from ..linear import linear
from ..dropout import dropout



def char2doc(document,
             *,
             char_space_size,
             char_embedding_size,
             document_embedding_size,
             dropout_prob,
             hidden_layer_size,
             output_layer_size,
             context_vector_size):
  with tf.variable_scope("char2doc"):
    char_embeddings = embeddings(id_space_size=char_space_size,
                                 embedding_size=char_embedding_size)

    document_embedding = id_sequence_to_embedding(
        document,
        char_embeddings,
        output_embedding_size=document_embedding_size,
        context_vector_size=context_vector_size)

    hidden_layer = dropout(_activate(linear(_activate(document_embedding),
                                            hidden_layer_size)),
                           dropout_prob)
    return linear(hidden_layer, output_layer_size)


def _activate(tensor):
  return tf.nn.elu(tensor)

Use id_sequence_to_embedding and only forward document
Use id_sequence_to_embedding and only forward document

  import tensorflow as tf
  
- from ..embedding import embeddings_to_embedding, ids_to_embeddings, embeddings
+ from ..embedding import id_sequence_to_embedding, embeddings
  from ..linear import linear
  from ..dropout import dropout
  
  
  
- def char2doc(forward_document,
+ def char2doc(document,
-              backward_document,
               *,
               char_space_size,
               char_embedding_size,
               document_embedding_size,
               dropout_prob,
               hidden_layer_size,
               output_layer_size,
               context_vector_size):
    with tf.variable_scope("char2doc"):
      char_embeddings = embeddings(id_space_size=char_space_size,
                                   embedding_size=char_embedding_size)
  
-     def char_ids_to_doc_embedding(document):
-       return embeddings_to_embedding(
-           ids_to_embeddings(document, char_embeddings),
+     document_embedding = id_sequence_to_embedding(
+         document,
+         char_embeddings,
-           output_embedding_size=document_embedding_size,
+         output_embedding_size=document_embedding_size,
-           context_vector_size=context_vector_size)
+         context_vector_size=context_vector_size)
- 
-     document_embedding = tf.concat(
-         1,
-         list(map(char_ids_to_doc_embedding,
-                  [forward_document, backward_document])))
  
      hidden_layer = dropout(_activate(linear(_activate(document_embedding),
                                              hidden_layer_size)),
                             dropout_prob)
      return linear(hidden_layer, output_layer_size)
  
  
  def _activate(tensor):
    return tf.nn.elu(tensor)
  
Use id_sequence_to_embedding and only forward document
## Code Before:
import tensorflow as tf

from ..embedding import embeddings_to_embedding, ids_to_embeddings, embeddings
from ..linear import linear
from ..dropout import dropout



def char2doc(forward_document,
             backward_document,
             *,
             char_space_size,
             char_embedding_size,
             document_embedding_size,
             dropout_prob,
             hidden_layer_size,
             output_layer_size,
             context_vector_size):
  with tf.variable_scope("char2doc"):
    char_embeddings = embeddings(id_space_size=char_space_size,
                                 embedding_size=char_embedding_size)

    def char_ids_to_doc_embedding(document):
      return embeddings_to_embedding(
          ids_to_embeddings(document, char_embeddings),
          output_embedding_size=document_embedding_size,
          context_vector_size=context_vector_size)

    document_embedding = tf.concat(
        1,
        list(map(char_ids_to_doc_embedding,
                 [forward_document, backward_document])))

    hidden_layer = dropout(_activate(linear(_activate(document_embedding),
                                            hidden_layer_size)),
                           dropout_prob)
    return linear(hidden_layer, output_layer_size)


def _activate(tensor):
  return tf.nn.elu(tensor)

## Instruction:
Use id_sequence_to_embedding and only forward document
## Code After:
import tensorflow as tf

from ..embedding import id_sequence_to_embedding, embeddings
from ..linear import linear
from ..dropout import dropout



def char2doc(document,
             *,
             char_space_size,
             char_embedding_size,
             document_embedding_size,
             dropout_prob,
             hidden_layer_size,
             output_layer_size,
             context_vector_size):
  with tf.variable_scope("char2doc"):
    char_embeddings = embeddings(id_space_size=char_space_size,
                                 embedding_size=char_embedding_size)

    document_embedding = id_sequence_to_embedding(
        document,
        char_embeddings,
        output_embedding_size=document_embedding_size,
        context_vector_size=context_vector_size)

    hidden_layer = dropout(_activate(linear(_activate(document_embedding),
                                            hidden_layer_size)),
                           dropout_prob)
    return linear(hidden_layer, output_layer_size)


def _activate(tensor):
  return tf.nn.elu(tensor)
