Ejemplo n.º 1
0
def choice_1_COL_RANGE_FIRST(dict_nouns):
  def _reset_params():
    Parameters.PARAMETERS_CHOICE_0_1.CHOICE_1_COL_RANGE_FIRST = 1.00
  def _change_params_for_step(cur_step,alpha):
    _reset_params()
    Parameters.PARAMETERS_CHOICE_0_1.CHOICE_1_COL_RANGE_FIRST += cur_step*alpha

  _reset_params()
  _alpha = 0.05
  _max_step = 8
  _current_step = 0

  global __continue
  if __continue == 1:
    return
    _current_step = 8
    _change_params_for_step(_current_step, _alpha)
    __continue = 1

  while _current_step <= _max_step:
    SimilarityWordnetOxford.similarityWords(dict_nouns)
    _current_step += 1

    _change_params_for_step(_current_step, _alpha)

  _reset_params()
Ejemplo n.º 2
0
def jaccard_weight(dict_nouns):
  def _reset_params():
    Parameters.PARAMETERS.JACCARD_WEIGHT = 0.01
  def _change_params_for_step(cur_step, alpha):
    _reset_params()
    Parameters.PARAMETERS.JACCARD_WEIGHT += cur_step*alpha

  _reset_params()
  _alpha = 0.02
  _max_step = 20
  _current_step = 0

  _best_result = 0
  _best_params = Parameters.get_current_params()

  while _current_step <= _max_step:
    (precision, recall, accuracy) = SimilarityWordnetOxford.similarityWords(dict_nouns)
    if accuracy > _best_result:
      _best_result = accuracy
      _best_params = Parameters.get_current_params()
    _current_step += 1

    _change_params_for_step(_current_step,_alpha)

  _reset_params()
  return (_best_result,_best_params)
Ejemplo n.º 3
0
def choice_1_COL_RANGE_FIRST(dict_nouns):
  def _reset_params():
    Parameters.PARAMETERS_CHOICE_0_1.CHOICE_1_COL_RANGE_FIRST = 1.01
  def _change_params_for_step(cur_step,alpha):
    _reset_params()
    Parameters.PARAMETERS_CHOICE_0_1.CHOICE_1_COL_RANGE_FIRST += cur_step*alpha

  _reset_params()
  _alpha = 0.02
  _max_step = 10
  _current_step = 0

  _best_result = 0
  _best_params = Parameters.get_current_params()

  while _current_step <= _max_step:
    (precision, recall, accuracy) = SimilarityWordnetOxford.similarityWords(dict_nouns)
    if accuracy > _best_result:
      _best_result = accuracy
      _best_params = Parameters.get_current_params()
    _current_step += 1

    _change_params_for_step(_current_step, _alpha)

  _reset_params()
  return (_best_result,_best_params)
Ejemplo n.º 4
0
def nbest_similarity(dict_nouns):
  def _reset_params():
    Parameters.PARAMETERS.N_BEST_CALCULATE_SIMILARITY = 1
  def _change_params_for_step(cur_step, alpha):
    _reset_params()
    Parameters.PARAMETERS.N_BEST_CALCULATE_SIMILARITY += cur_step*alpha

  _reset_params()
  _alpha = 1
  _max_step = 9
  _current_step = 0

  _best_result = 0
  _best_params = Parameters.get_current_params()

  while _current_step <= _max_step:
    (precision, recall, accuracy) = SimilarityWordnetOxford.similarityWords(dict_nouns)
    if accuracy > _best_result:
      _best_result = accuracy
      _best_params = Parameters.get_current_params()

    _current_step += 1

    _change_params_for_step(_current_step,_alpha)

  _reset_params()

  return (_best_result,_best_params)
Ejemplo n.º 5
0
def feature_POS(dict_nouns):
  def _reset_params():
    Parameters.PARAMETERS.POS_FEATURE_n = 1
    Parameters.PARAMETERS.POS_FEATURE_v = 0
  def _change_params_for_step(cur_step):
    _reset_params()
    if cur_step == 1:
      Parameters.PARAMETERS.POS_FEATURE_v = 1

  _reset_params()
  _max_step = 1
  _current_step = 0

  _best_result = 0
  _best_params = Parameters.get_current_params()

  while _current_step <= _max_step:
    (precision, recall, accuracy) = SimilarityWordnetOxford.similarityWords(dict_nouns)
    if accuracy > _best_result:
      _best_result = accuracy
      _best_params = Parameters.get_current_params()
    _current_step += 1

    _change_params_for_step(_current_step)

  _reset_params()
  return (_best_result,_best_params)
Ejemplo n.º 6
0
def feature_dict(dict_nouns):
  def _reset_params():
    Parameters.PARAMETERS.DICT_OX_FEATURE_RELATION_sd = 1
    Parameters.PARAMETERS.DICT_OX_FEATURE_RELATION_d = 1
    Parameters.PARAMETERS.DICT_OX_FEATURE_RELATION_xh = 1
    Parameters.PARAMETERS.DICT_OX_FEATURE_RELATION_x = 1
  def _change_params_for_step(cur_step):
    _reset_params()
    if cur_step == 1:
      Parameters.PARAMETERS.DICT_OX_FEATURE_RELATION_xh = 0
    elif cur_step == 2:
      Parameters.PARAMETERS.DICT_OX_FEATURE_RELATION_x = 0
    elif cur_step == 3:
      Parameters.PARAMETERS.DICT_OX_FEATURE_RELATION_xh = 0
      Parameters.PARAMETERS.DICT_OX_FEATURE_RELATION_x = 0

  _reset_params()
  _max_step = 3
  _current_step = 0

  _best_result = 0
  _best_params = Parameters.get_current_params()

  while _current_step <= _max_step:
    (precision, recall, accuracy) = SimilarityWordnetOxford.similarityWords(dict_nouns)
    if accuracy > _best_result:
      _best_result = accuracy
      _best_params = Parameters.get_current_params()
    _current_step += 1

    _change_params_for_step(_current_step)

  _reset_params()
  return (_best_result,_best_params)
Ejemplo n.º 7
0
def feature_wn(dict_nouns):
  def _reset_params():
    Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_definition = 1
    Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hypernyms = 0
    Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hyponyms = 0
    Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_part_meronyms = 0
    Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_member_holonyms = 0
  def _change_params_for_step(cur_step):
    _reset_params()
    if cur_step == 1:
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hypernyms = 1
    elif cur_step == 2:
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hyponyms = 1
    elif cur_step == 3:
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_part_meronyms = 1
    elif cur_step == 4:
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_member_holonyms = 1
    elif cur_step == 5:
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hypernyms = 1
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hyponyms = 1
    elif cur_step == 6:
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hypernyms = 1
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_part_meronyms = 1
    elif cur_step == 7:
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hypernyms = 1
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_member_holonyms = 1
    elif cur_step == 8:
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hypernyms = 1
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hyponyms = 1
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_part_meronyms = 1
    elif cur_step == 9:
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hypernyms = 1
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hyponyms = 1
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_member_holonyms = 1
    elif cur_step == 10:
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hypernyms = 1
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_hyponyms = 1
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_part_meronyms = 1
      Parameters.PARAMETERS.DICT_WN_FEATURE_RELATION_member_holonyms = 1


  _reset_params()
  _max_step = 10
  _current_step = 0

  _best_result = 0
  _best_params = Parameters.get_current_params()

  while _current_step <= _max_step:
    (precision, recall, accuracy) = SimilarityWordnetOxford.similarityWords(dict_nouns)
    if accuracy > _best_result:
      _best_result = accuracy
      _best_params = Parameters.get_current_params()
    _current_step += 1

    _change_params_for_step(_current_step)

  _reset_params()
  return (_best_result,_best_params)
Ejemplo n.º 8
0
def get_Ox_means(key, key_lemmas):
  means = []
  for noun in key_lemmas:
    if not __dict_Ox__.has_key(noun):
      filted_dict = SimilarityWordnetOxford.cal_similarity_for_word(noun)
      __dict_Ox__[noun] = filted_dict

  for noun in key_lemmas:
    if __dict_Ox__[noun].has_key(key):
      means = __dict_Ox__[noun][key]
      break

  return means
Ejemplo n.º 9
0
def train_with_random(dict_nouns):
  _best_result = 0;
  _best_params = Parameters.get_current_params()

  for i in range(0,1000):
    # random_all_feature
    Parameters.random_params_values()
    # calculate_result -> current best
    (precision, recall, accuracy) = SimilarityWordnetOxford.similarityWords(dict_nouns)
    if accuracy > _best_result:
      _best_result = accuracy
      _best_params = Parameters.get_current_params()

    (best_result_loop, best_params_loop) = train_from_base(dict_nouns)

    if best_result_loop>= _best_result:
        _best_result = best_result_loop
        _best_params = best_params_loop
        Parameters.set_params_from_arr(_best_params)
        WriteParametersAndResult.append_params_and_result_to_file(_best_params)