def main(*args, **kwargs):
  """ NuPIC NLP main entry point. """
  (options, args) = parser.parse_args()
  if options.max_terms.lower() == 'all':
    max_terms = sys.maxint
  else:
    max_terms = int(options.max_terms)
  min_sparsity = float(options.min_sparsity)
  prediction_start = int(options.prediction_start)
  verbosity = 0
  if options.verbose:
    verbosity = 1

  retina = options.retina

  # Create the cache directory if necessary.
  if not os.path.exists(cache_dir):
    os.mkdir(cache_dir)

  builder = SDR_Builder(cept_app_key, cache_dir,
                        verbosity=verbosity,
                        retina=retina)

  def size_to_thresholds(sdr_size):
      """ scale minThreshold and activationThreshold according to sdr_size """
      factor = float(sdr_size) / (128*128)
      return 80*factor, 100*factor

  sdr_size = RETINA_SIZES[retina]['width'] * RETINA_SIZES[retina]['height']

  minThreshold, activationThreshold = size_to_thresholds(sdr_size)
  
  if options.predict_triples:
    # Instantiate TP with parameters for Fox demo
    nupic = Nupic_Word_Client(numberOfCols=sdr_size,
                              minThreshold=minThreshold,
                              activationThreshold=activationThreshold,
                              pamLength=10)
  else:
    nupic = Nupic_Word_Client(numberOfCols=sdr_size)
  if options.verbose:
    nupic.printParameters()
  runner = Association_Runner(builder, nupic,
                              max_terms, min_sparsity,
                              prediction_start, verbosity=verbosity)

  if len(args) is 0:
    print 'no input file provided!'
    exit(1)
  elif len(args) == 1:
    if options.predict_triples:
      if options.verbose: print "Predicting triples!"
      runner.direct_association_triples(args[0])
    else:
      runner.direct_association(args[0])
  else:
    if options.predict_triples:
      print "Please specify exactly one input file containing triples"
    else:
      runner.random_dual_association(args[0], args[1])
Exemple #2
0
def main(*args, **kwargs):
    """ NuPIC NLP main entry point. """
    (options, args) = parser.parse_args()
    if options.max_terms.lower() == 'all':
        max_terms = sys.maxint
    else:
        max_terms = int(options.max_terms)
    min_sparsity = float(options.min_sparsity)
    prediction_start = int(options.prediction_start)
    verbosity = 0
    if options.verbose:
        verbosity = 5

    # Create the cache directory if necessary.
    if not os.path.exists(cache_dir):
        os.mkdir(cache_dir)

    reader = NLTK_Reader(os.path.join(cache_dir, 'text'), verbosity=verbosity)
    builder = SDR_Builder(cept_app_key, cache_dir, verbosity=verbosity)
    nupic = Nupic_Word_Client()
    runner = Association_Runner(builder,
                                nupic,
                                max_terms,
                                min_sparsity,
                                prediction_start,
                                verbosity=verbosity)

    noun_pairs = reader.get_noun_pairs_from_all_texts()[:max_terms]

    runner.associate(noun_pairs)
def main(*args, **kwargs):
  """ NuPIC NLP main entry point. """
  (options, args) = parser.parse_args()
  if options.max_terms.lower() == 'all':
    max_terms = sys.maxint
  else:
    max_terms = int(options.max_terms)
  min_sparsity = float(options.min_sparsity)
  prediction_start = int(options.prediction_start)
  verbosity = 0
  if options.verbose:
    verbosity = 1

  # Create the cache directory if necessary.
  if not os.path.exists(cache_dir):
    os.mkdir(cache_dir)

  builder = SDR_Builder(cept_app_id, cept_app_key, cache_dir,
                        verbosity=verbosity)
  
  if options.predict_triples:
    # Instantiate TP with parameters for Fox demo
    nupic = Nupic_Word_Client(
                minThreshold=80, activationThreshold=100, pamLength=10)
  else:
    nupic = Nupic_Word_Client()
  if options.verbose:
    nupic.printParameters()
  runner = Association_Runner(builder, nupic,
                              max_terms, min_sparsity,
                              prediction_start, verbosity=verbosity)

  if len(args) is 0:
    print 'no input file provided!'
    exit(1)
  elif len(args) == 1:
    if options.predict_triples:
      if options.verbose: print "Predicting triples!"
      runner.direct_association_triples(args[0])
    else:
      runner.direct_association(args[0])
  else:
    if options.predict_triples:
      print "Please specify exactly one input file containing triples"
    else:
      runner.random_dual_association(args[0], args[1])
def main(*args, **kwargs):
    """ NuPIC NLP main entry point. """
    (options, args) = parser.parse_args()
    if options.max_terms.lower() == 'all':
        max_terms = sys.maxint
    else:
        max_terms = int(options.max_terms)
    min_sparsity = float(options.min_sparsity)
    prediction_start = int(options.prediction_start)
    verbosity = 0
    if options.verbose:
        verbosity = 1

    retina = options.retina

    # Create the cache directory if necessary.
    if not os.path.exists(cache_dir):
        os.mkdir(cache_dir)

    builder = SDR_Builder(cept_app_key,
                          cache_dir,
                          verbosity=verbosity,
                          retina=retina)

    def size_to_thresholds(sdr_size):
        """ scale minThreshold and activationThreshold according to sdr_size """
        factor = float(sdr_size) / (128 * 128)
        return 80 * factor, 100 * factor

    sdr_size = RETINA_SIZES[retina]['width'] * RETINA_SIZES[retina]['height']

    minThreshold, activationThreshold = size_to_thresholds(sdr_size)

    if options.predict_triples:
        # Instantiate TP with parameters for Fox demo
        nupic = Nupic_Word_Client(numberOfCols=sdr_size,
                                  minThreshold=minThreshold,
                                  activationThreshold=activationThreshold,
                                  pamLength=10)
    else:
        nupic = Nupic_Word_Client(numberOfCols=sdr_size)
    if options.verbose:
        nupic.printParameters()
    runner = Association_Runner(builder,
                                nupic,
                                max_terms,
                                min_sparsity,
                                prediction_start,
                                verbosity=verbosity)

    if len(args) is 0:
        print 'no input file provided!'
        exit(1)
    elif len(args) == 1:
        if options.predict_triples:
            if options.verbose: print "Predicting triples!"
            runner.direct_association_triples(args[0])
        else:
            runner.direct_association(args[0])
    else:
        if options.predict_triples:
            print "Please specify exactly one input file containing triples"
        else:
            runner.random_dual_association(args[0], args[1])