asahi417 commited on
Commit
9aa4bea
1 Parent(s): dcf770c
dataset/train.jsonl CHANGED
The diff for this file is too large to render. See raw diff
 
dataset/valid.jsonl CHANGED
The diff for this file is too large to render. See raw diff
 
process.py CHANGED
@@ -7,6 +7,9 @@ import requests
7
 
8
  from glob import glob
9
  import gdown
 
 
 
10
 
11
 
12
  def wget(url, cache_dir: str = './cache', gdrive_filename: str = None):
@@ -50,7 +53,6 @@ def get_training_data(return_validation_set: bool = False):
50
  pairs: dictionary of list (positive pairs, negative pairs)
51
  {'1b': [[0.6, ('office', 'desk'), ..], [[-0.1, ('aaa', 'bbb'), ...]]
52
  """
53
- top_n = 10
54
  cache_dir = 'cache'
55
  os.makedirs(cache_dir, exist_ok=True)
56
  remove_relation = None
@@ -98,7 +100,6 @@ def get_training_data(return_validation_set: bool = False):
98
  all_relation_type[relation_id] = relation_type
99
  parent = list(set([i[:-1] for i in all_relation_type.keys()]))
100
 
101
-
102
  # 1st level relation contrast (among parent relations)
103
  relation_pairs_1st = []
104
  for p in parent:
@@ -121,7 +122,8 @@ def get_training_data(return_validation_set: bool = False):
121
  relation_pairs_3rd = []
122
  for p in all_relation_type.keys():
123
  positive_pairs = positives[p]
124
- negative_pairs = negatives[p]
 
125
  for n in all_relation_type.keys():
126
  if p == n:
127
  continue
@@ -130,17 +132,18 @@ def get_training_data(return_validation_set: bool = False):
130
  "positives": positive_pairs, "negatives": negative_pairs, "relation_type": p, "level": "child"
131
  }]
132
 
 
133
  for n, anchor in enumerate(positive_pairs):
 
 
134
  for _n, posi in enumerate(positive_pairs):
135
- if n < _n:
136
- negative_pairs = positive_pairs[_n+1:]
137
- if len(negative_pairs) > 0:
138
- relation_pairs_3rd += [{
139
- "positives": [(anchor, posi)],
140
- "negatives": [(anchor, neg) for neg in negative_pairs],
141
- "relation_type": p,
142
- "level": "child_prototypical"
143
- }]
144
 
145
  return relation_pairs_1st + relation_pairs_2nd + relation_pairs_3rd
146
 
 
7
 
8
  from glob import glob
9
  import gdown
10
+ k = 10 # the 3rd level negative-distance ranking
11
+ m = 5 # the 3rd level negative-distance ranking
12
+ top_n = 10 # threshold of positive pairs in the 1st and 2nd relation
13
 
14
 
15
  def wget(url, cache_dir: str = './cache', gdrive_filename: str = None):
 
53
  pairs: dictionary of list (positive pairs, negative pairs)
54
  {'1b': [[0.6, ('office', 'desk'), ..], [[-0.1, ('aaa', 'bbb'), ...]]
55
  """
 
56
  cache_dir = 'cache'
57
  os.makedirs(cache_dir, exist_ok=True)
58
  remove_relation = None
 
100
  all_relation_type[relation_id] = relation_type
101
  parent = list(set([i[:-1] for i in all_relation_type.keys()]))
102
 
 
103
  # 1st level relation contrast (among parent relations)
104
  relation_pairs_1st = []
105
  for p in parent:
 
122
  relation_pairs_3rd = []
123
  for p in all_relation_type.keys():
124
  positive_pairs = positives[p]
125
+ negative_pairs = []
126
+ # negative_pairs = negatives[p]
127
  for n in all_relation_type.keys():
128
  if p == n:
129
  continue
 
132
  "positives": positive_pairs, "negatives": negative_pairs, "relation_type": p, "level": "child"
133
  }]
134
 
135
+ negative_pairs = positive_pairs + negatives[p]
136
  for n, anchor in enumerate(positive_pairs):
137
+ if n > m:
138
+ continue
139
  for _n, posi in enumerate(positive_pairs):
140
+ if n < _n and len(negative_pairs) > _n + k:
141
+ relation_pairs_3rd += [{
142
+ "positives": [(anchor, posi)],
143
+ "negatives": [(anchor, neg) for neg in negative_pairs[_n+k:]],
144
+ "relation_type": p,
145
+ "level": "child_prototypical"
146
+ }]
 
 
147
 
148
  return relation_pairs_1st + relation_pairs_2nd + relation_pairs_3rd
149
 
semeval2012_relational_similarity_v3.py CHANGED
@@ -4,7 +4,7 @@ import datasets
4
  logger = datasets.logging.get_logger(__name__)
5
  _DESCRIPTION = """[SemEVAL 2012 task 2: Relational Similarity](https://aclanthology.org/S12-1047/)"""
6
  _NAME = "semeval2012_relational_similarity_v3"
7
- _VERSION = "1.0.0"
8
  _CITATION = """
9
  @inproceedings{jurgens-etal-2012-semeval,
10
  title = "{S}em{E}val-2012 Task 2: Measuring Degrees of Relational Similarity",
 
4
  logger = datasets.logging.get_logger(__name__)
5
  _DESCRIPTION = """[SemEVAL 2012 task 2: Relational Similarity](https://aclanthology.org/S12-1047/)"""
6
  _NAME = "semeval2012_relational_similarity_v3"
7
+ _VERSION = "1.1.0"
8
  _CITATION = """
9
  @inproceedings{jurgens-etal-2012-semeval,
10
  title = "{S}em{E}val-2012 Task 2: Measuring Degrees of Relational Similarity",