class_docstr: Objects of this class realize the translation matrix which maps the source language to the target language.
  The main methods are:
  
  We map it to the other language space by computing z = Wx, then return the
  word whose representation is close to z.
  
  For details on use, see the tutorial notebook [3]_
  
  Examples
  --------
  .. sourcecode:: pycon
  
      >>> from gensim.models import KeyedVectors
      >>> from gensim.test.utils import datapath
      >>> en = datapath("EN.1-10.cbow1_wind5_hs0_neg10_size300_smpl1e-05.txt")
      >>> it = datapath("IT.1-10.cbow1_wind5_hs0_neg10_size300_smpl1e-05.txt")
      >>> model_en = KeyedVectors.load_word2vec_format(en)
      >>> model_it = KeyedVectors.load_word2vec_format(it)
      >>>
      >>> word_pairs = [
      ...     ("one", "uno"), ("two", "due"), ("three", "tre"), ("four", "quattro"), ("five", "cinque"),
      ...     ("seven", "sette"), ("eight", "otto"),
      ...     ("dog", "cane"), ("pig", "maiale"), ("fish", "cavallo"), ("birds", "uccelli"),
      ...     ("apple", "mela"), ("orange", "arancione"), ("grape", "acino"), ("banana", "banana")
      ... ]
      >>>
      >>> trans_model = TranslationMatrix(model_en, model_it)
      >>> trans_model.train(word_pairs)
      >>> trans_model.translate(["dog", "one"], topn=3)
      OrderedDict([('dog', [u'cane', u'gatto', u'cavallo']), ('one', [u'uno', u'due', u'tre'])])
  
  
  References
  ----------
  .. [3] https://github.com/RaRe-Technologies/gensim/blob/3.2.0/docs/notebooks/translation_matrix.ipynb
class_docstr_tok: ["Objects","of","this","class","realize","the","translation","matrix","which","maps","the","source","language","to","the","target","language",".","The","main","methods","are",":","We","map","it","to","the","other","language","space","by","computing","z","=","Wx",",","then","return","the","word","whose","representation","is","close","to","z",".","For","details","on","use",",","see","the","tutorial","notebook","[","3","]","_","Examples","--","--","--","--","..","sourcecode",":",":","pycon",">",">",">","from","gensim.models","import","KeyedVectors",">",">",">","from","gensim.test.utils","import","datapath",">",">",">","en","=","datapath","(","``","EN.1-10.cbow1_wind5_hs0_neg10_size300_smpl1e-05.txt","''",")",">",">",">","it","=","datapath","(","``","IT.1-10.cbow1_wind5_hs0_neg10_size300_smpl1e-05.txt","''",")",">",">",">","model_en","=","KeyedVectors.load_word2vec_format","(","en",")",">",">",">","model_it","=","KeyedVectors.load_word2vec_format","(","it",")",">",">",">",">",">",">","word_pairs","=","[","...","(","``","one","''",",","``","uno","''",")",",","(","``","two","''",",","``","due","''",")",",","(","``","three","''",",","``","tre","''",")",",","(","``","four","''",",","``","quattro","''",")",",","(","``","five","''",",","``","cinque","''",")",",","...","(","``","seven","''",",","``","sette","''",")",",","(","``","eight","''",",","``","otto","''",")",",","...","(","``","dog","''",",","``","cane","''",")",",","(","``","pig","''",",","``","maiale","''",")",",","(","``","fish","''",",","``","cavallo","''",")",",","(","``","birds","''",",","``","uccelli","''",")",",","...","(","``","apple","''",",","``","mela","''",")",",","(","``","orange","''",",","``","arancione","''",")",",","(","``","grape","''",",","``","acino","''",")",",","(","``","banana","''",",","``","banana","''",")","...","]",">",">",">",">",">",">","trans_model","=","TranslationMatrix","(","model_en",",","model_it",")",">",">",">","trans_model.train","(","word_pairs",")",">",">",">","trans_model.translate","(","[","``","dog","''",",","``","one","''","]",",","topn=3",")","OrderedDict","(","[","(","'dog","'",",","[","u'cane","'",",","u'gatto","'",",","u'cavallo","'","]",")",",","(","'one","'",",","[","u'uno","'",",","u'due","'",",","u'tre","'","]",")","]",")","References","--","--","--","--","--","..","[","3","]","https",":","\/\/github.com\/RaRe-Technologies\/gensim\/blob\/3.2.0\/docs\/notebooks\/translation_matrix.ipynb"]
docstr: Translate the word from the source language to the target language.
  
  Parameters
  ----------
  source_words : {str, list of str}
      Single word or a list of words to be translated
  topn : int, optional
      Number of words that will be returned as translation for each `source_words`
  gc : int, optional
      Define translation algorithm, if `gc == 0` - use standard NN retrieval,
      otherwise, use globally corrected neighbour retrieval method (as described in [1]_).
  sample_num : int, optional
      Number of words to sample from the source lexicon, if `gc == 1`, then `sample_num` **must** be provided.
  source_lang_vec : :class:`~gensim.models.keyedvectors.KeyedVectors`, optional
      New source language vectors for translation, by default, used the model's source language vector.
  target_lang_vec : :class:`~gensim.models.keyedvectors.KeyedVectors`, optional
      New target language vectors for translation, by default, used the model's target language vector.
  
  Returns
  -------
  :class:`collections.OrderedDict`
      Ordered dict where each item is `word`: [`translated_word_1`, `translated_word_2`, ...]
docstr_tok: ["Translate","the","word","from","the","source","language","to","the","target","language",".","Parameters","--","--","--","--","--","source_words",":","{","str",",","list","of","str","}","Single","word","or","a","list","of","words","to","be","translated","topn",":","int",",","optional","Number","of","words","that","will","be","returned","as","translation","for","each","`","source_words","`","gc",":","int",",","optional","Define","translation","algorithm",",","if","`","gc","==","0","`","-","use","standard","NN","retrieval",",","otherwise",",","use","globally","corrected","neighbour","retrieval","method","(","as","described","in","[","1","]","_",")",".","sample_num",":","int",",","optional","Number","of","words","to","sample","from","the","source","lexicon",",","if","`","gc","==","1","`",",","then","`","sample_num","`","*","*","must","*","*","be","provided",".","source_lang_vec",":",":","class",":","`","~gensim.models.keyedvectors.KeyedVectors","`",",","optional","New","source","language","vectors","for","translation",",","by","default",",","used","the","model","'s","source","language","vector",".","target_lang_vec",":",":","class",":","`","~gensim.models.keyedvectors.KeyedVectors","`",",","optional","New","target","language","vectors","for","translation",",","by","default",",","used","the","model","'s","target","language","vector",".","Returns","--","--","--","-",":","class",":","`","collections.OrderedDict","`","Ordered","dict","where","each","item","is","`","word","`",":","[","`","translated_word_1","`",",","`","translated_word_2","`",",","...","]"]
code: def translate(
      self,
      source_words,
      topn=5,
      gc=0,
      sample_num=None,
      source_lang_vec=None,
      target_lang_vec=None,
  ):
      """Translate the word from the source language to the target language.
  
      Parameters
      ----------
      source_words : {str, list of str}
          Single word or a list of words to be translated
      topn : int, optional
          Number of words that will be returned as translation for each `source_words`
      gc : int, optional
          Define translation algorithm, if `gc == 0` - use standard NN retrieval,
          otherwise, use globally corrected neighbour retrieval method (as described in [1]_).
      sample_num : int, optional
          Number of words to sample from the source lexicon, if `gc == 1`, then `sample_num` **must** be provided.
      source_lang_vec : :class:`~gensim.models.keyedvectors.KeyedVectors`, optional
          New source language vectors for translation, by default, used the model's source language vector.
      target_lang_vec : :class:`~gensim.models.keyedvectors.KeyedVectors`, optional
          New target language vectors for translation, by default, used the model's target language vector.
  
      Returns
      -------
      :class:`collections.OrderedDict`
          Ordered dict where each item is `word`: [`translated_word_1`, `translated_word_2`, ...]
  
      """
      if isinstance(source_words, str):
          # pass only one word to translate
          source_words = [source_words]
  
      # If the language word vector not provided by user, use the model's
      # language word vector as default
      if source_lang_vec is None:
          warnings.warn(
              "The parameter source_lang_vec isn't specified, "
              "use the model's source language word vector as default."
          )
          source_lang_vec = self.source_lang_vec
  
      if target_lang_vec is None:
          warnings.warn(
              "The parameter target_lang_vec isn't specified, "
              "use the model's target language word vector as default."
          )
          target_lang_vec = self.target_lang_vec
  
      # If additional is provided, bootstrapping vocabulary from the source language word vector model.
      if gc:
          if sample_num is None:
              raise RuntimeError(
                  "When using the globally corrected neighbour retrieval method, "
                  "the `sample_num` parameter(i.e. the number of words sampled from source space) must be provided."
              )
          lexicon = set(source_lang_vec.index_to_key)
          addition = min(sample_num, len(lexicon) - len(source_words))
          lexicon = self.random_state.choice(
              list(lexicon.difference(source_words)), addition
          )
          source_space = Space.build(
              source_lang_vec, set(source_words).union(set(lexicon))
          )
      else:
          source_space = Space.build(source_lang_vec, source_words)
      target_space = Space.build(
          target_lang_vec,
      )
  
      # Normalize the source vector and target vector
      source_space.normalize()
      target_space.normalize()
  
      # Map the source language to the target language
      mapped_source_space = self.apply_transmat(source_space)
  
      # Use the cosine similarity metric
      sim_matrix = -np.dot(target_space.mat, mapped_source_space.mat.T)
  
      # If `gc=1`, using corrected retrieval method
      if gc:
          srtd_idx = np.argsort(np.argsort(sim_matrix, axis=1), axis=1)
          sim_matrix_idx = np.argsort(srtd_idx + sim_matrix, axis=0)
      else:
          sim_matrix_idx = np.argsort(sim_matrix, axis=0)
  
      # Translate the words and for each word return the `topn` similar words
      translated_word = OrderedDict()
      for idx, word in enumerate(source_words):
          translated_target_word = []
          # Search the most `topn` similar words
          for j in range(topn):
              map_space_id = sim_matrix_idx[
                  j, source_space.word2index[word]
              ]
              translated_target_word.append(
                  target_space.index2word[map_space_id]
              )
          translated_word[word] = translated_target_word
      return translated_word
  
imports: import warnings
  from collections import OrderedDict
  import numpy
  from gensim import utils
label_desc: Use image node_id 5 for calling the TranslationMatrix obj's underlying member method code with example usage: obj.translate(source_words, topn, gc, sample_num, source_lang_vec, target_lang_vec) and returns: translated_word