class_docstr: Wrapper of the scikit-learn TfidfVectorizer
class_docstr_tok: ["Wrapper","of","the","scikit-learn","TfidfVectorizer"]
docstr: Restrict the vectorizer vocabulary to the given ngrams
  
  Args:
      ngrams (iterable of str or tuples of str): ngrams to keep
  
  Returns:
      :class:`.TfidfVectorizer`: The vectorizer with limited vocabulary
docstr_tok: ["Restrict","the","vectorizer","vocabulary","to","the","given","ngrams","Args",":","ngrams","(","iterable","of","str","or","tuples","of","str",")",":","ngrams","to","keep","Returns",":",":","class",":","`",".TfidfVectorizer","`",":","The","vectorizer","with","limited","vocabulary"]
code: def limit_vocabulary(self, ngrams):
      """Restrict the vectorizer vocabulary to the given ngrams
  
      Args:
          ngrams (iterable of str or tuples of str): ngrams to keep
  
      Returns:
          :class:`.TfidfVectorizer`: The vectorizer with limited vocabulary
      """
      import scipy.sparse as sp
  
      ngrams = set(ngrams)
      vocab = self.vocabulary
      existing_ngrams = set(vocab)
      extra_values = ngrams - existing_ngrams
  
      if extra_values:
          raise ValueError(
              "Invalid ngrams %s, expected values in word_pairs"
              % sorted(extra_values)
          )
  
      new_ngrams, new_index = zip(
          *sorted((ng, vocab[ng]) for ng in ngrams)
      )
  
      self._tfidf_vectorizer.vocabulary_ = {
          ng: new_i for new_i, ng in enumerate(new_ngrams)
      }
      # pylint: disable=protected-access
      # The new_idf_data is valid because the previous _idf_diag was indexed
      # with sorted ngrams and new_index is also indexed with sorted ngrams
      new_idf_data = self._tfidf_vectorizer._tfidf._idf_diag.data[
          list(new_index)
      ]
      self._tfidf_vectorizer._tfidf._idf_diag = sp.spdiags(
          new_idf_data,
          diags=0,
          m=len(new_index),
          n=len(new_index),
          format="csr",
      )
      # pylint: enable=protected-access
      return self
  
imports: from __future__ import division, unicode_literals
  import json
  from builtins import str, zip
  from copy import deepcopy
  from pathlib import Path
  from future.utils import iteritems
  from snips_nlu.common.utils import json_string, fitted_required, replace_entities_with_placeholders, check_persisted_path
  from snips_nlu.constants import DATA, ENTITY, ENTITY_KIND, LANGUAGE, NGRAM, TEXT, ENTITIES
  from snips_nlu.dataset import get_text_from_chunks, validate_and_format_dataset
  from snips_nlu.entity_parser.builtin_entity_parser import is_builtin_entity
  from snips_nlu.exceptions import _EmptyDatasetUtterancesError, LoadingError
  from snips_nlu.languages import get_default_sep
  from snips_nlu.pipeline.configs import FeaturizerConfig
  from snips_nlu.pipeline.configs.intent_classifier import CooccurrenceVectorizerConfig, TfidfVectorizerConfig
  from snips_nlu.pipeline.processing_unit import ProcessingUnit
  from snips_nlu.preprocessing import stem, tokenize_light
  from snips_nlu.resources import get_stop_words, get_word_cluster
  from snips_nlu.slot_filler.features_utils import get_all_ngrams
label_desc: Use image node_id 10 for calling the TfidfVectorizer obj's underlying member method code with example usage: obj.limit_vocabulary(ngrams) and returns: self