class_docstr: This class implements similarity based category classifiers.
class_docstr_tok: ["This","class","implements","similarity","based","category","classifiers","."]
docstr: Extract categories, features, feature weights, from corpus.
  Compute the weight for each feature token in each category
  The weight is computed as token_count / total_feature_count
docstr_tok: ["Extract","categories",",","features",",","feature","weights",",","from","corpus",".","Compute","the","weight","for","each","feature","token","in","each","category","The","weight","is","computed","as","token_count","\/","total_feature_count"]
code: def train(
      cls, corpus, sim_metric, feature_num=5, sim_model="weighted"
  ):
      """
      Extract categories, features, feature weights, from corpus.
      Compute the weight for each feature token in each category
      The weight is computed as token_count / total_feature_count
      """
      print("Training...")
      cat_word = {}
      for sent, cat in corpus:
          cat_word.setdefault(cat, []).extend(
              word_process(word_tokenize(sent))
          )
      features = {cat: Counter(cat_word[cat]) for cat in cat_word}
      labels = features.keys()
      cat_features = {}
      feature_weights = {}
      for c, f in six.iteritems(features):
          w_c_pairs = f.most_common(feature_num)
          words, counts = zip(*w_c_pairs)
          cat_features[c] = words
          total_count = float(sum(counts))
          word_weights = []
          for w, count in w_c_pairs:
              word_weights.append((w, count / total_count))
          feature_weights[c] = word_weights
      return cls(
          labels, cat_features, feature_weights, sim_metric, sim_model
      )
  
imports: from sematch.semantic.sparql import NameSPARQL, QueryGraph
  from sematch.semantic.similarity import YagoTypeSimilarity
  from sematch.utility import memoized
  from sematch.nlp import word_tokenize, word_process, Extraction
  import numpy
  import itertools
  from collections import Counter
  import six
  from six.moves import xrange
  from sklearn.svm import LinearSVC
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.pipeline import Pipeline
  from sklearn.preprocessing import LabelEncoder
  from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
  from sklearn.feature_extraction import DictVectorizer
  import time
label_desc: Use image node_id 3 for calling the SimClassifier obj's underlying member method code with example usage: obj.train(cls, corpus, sim_metric, feature_num, sim_model) and returns: cls