class_docstr: Convert a collection of raw documents to a document id matrix.
  
  Attributes:
      _use_char: boolean. Whether to use char feature.
      _num_norm: boolean. Whether to normalize text.
      _word_vocab: dict. A mapping of words to feature indices.
      _char_vocab: dict. A mapping of chars to feature indices.
      _label_vocab: dict. A mapping of labels to feature indices.
class_docstr_tok: ["Convert","a","collection","of","raw","documents","to","a","document","id","matrix",".","Attributes",":","_use_char",":","boolean",".","Whether","to","use","char","feature",".","_num_norm",":","boolean",".","Whether","to","normalize","text",".","_word_vocab",":","dict",".","A","mapping","of","words","to","feature","indices",".","_char_vocab",":","dict",".","A","mapping","of","chars","to","feature","indices",".","_label_vocab",":","dict",".","A","mapping","of","labels","to","feature","indices","."]
docstr: Transform documents to document ids.
  
  Uses the vocabulary learned by fit.
  
  Args:
      X : iterable
      an iterable which yields either str, unicode or file objects.
      y : iterabl, label strings.
  
  Returns:
      features: document id matrix.
      y: label id matrix.
docstr_tok: ["Transform","documents","to","document","ids",".","Uses","the","vocabulary","learned","by","fit",".","Args",":","X",":","iterable","an","iterable","which","yields","either","str",",","unicode","or","file","objects",".","y",":","iterabl",",","label","strings",".","Returns",":","features",":","document","id","matrix",".","y",":","label","id","matrix","."]
code: def transform(self, X, y=None):
      """Transform documents to document ids.
  
      Uses the vocabulary learned by fit.
  
      Args:
          X : iterable
          an iterable which yields either str, unicode or file objects.
          y : iterabl, label strings.
  
      Returns:
          features: document id matrix.
          y: label id matrix.
      """
      word_ids = [self._word_vocab.doc2id(doc) for doc in X]
      word_ids = pad_sequences(word_ids, padding="post")
  
      if self._use_char:
          char_ids = [
              [self._char_vocab.doc2id(w) for w in doc] for doc in X
          ]
          char_ids = pad_nested_sequences(char_ids)
          features = [word_ids, char_ids]
      else:
          features = word_ids
  
      if y is not None:
          y = [self._label_vocab.doc2id(doc) for doc in y]
          y = pad_sequences(y, padding="post")
          y = to_categorical(y, self.label_size).astype(int)
          # In 2018/06/01, to_categorical is a bit strange.
          # >>> to_categorical([[1,3]], num_classes=4).shape
          # (1, 2, 4)
          # >>> to_categorical([[1]], num_classes=4).shape
          # (1, 4)
          # So, I expand dimensions when len(y.shape) == 2.
          y = y if len(y.shape) == 3 else np.expand_dims(y, axis=0)
          return features, y
      else:
          return features
  
imports: import re
  import numpy
  from allennlp.modules.elmo import Elmo, batch_to_ids
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.externals import joblib
  from keras.utils.np_utils import to_categorical
  from keras.preprocessing.sequence import pad_sequences
  from anago.utils import Vocabulary
label_desc: Use image node_id 3 for calling the IndexTransformer obj's underlying member method code with example usage: obj.transform(X, y) and returns: features,  y, features