Datasets:

Languages:
English
Size:
< 1K
ArXiv:
Libraries:
Datasets
License:
asahi417 commited on
Commit
954cbd4
1 Parent(s): 6584ee1
experiments/baseline_lm_lc.py CHANGED
@@ -94,7 +94,7 @@ print(df)
94
  df = df.pivot(columns="relation_type", index="model", values="correlation")
95
  df = df.T[models].T
96
  df['average'] = df.mean(1)
97
- df.to_csv("experiments/results/lm_lc/lm.csv")
98
  df = (100 * df).round()
99
  print(df.to_markdown())
100
  print(df.to_latex(escape=False))
 
94
  df = df.pivot(columns="relation_type", index="model", values="correlation")
95
  df = df.T[models].T
96
  df['average'] = df.mean(1)
97
+ df.to_csv("results/lm_lc/lm.csv")
98
  df = (100 * df).round()
99
  print(df.to_markdown())
100
  print(df.to_latex(escape=False))
experiments/baseline_lm_qa.py CHANGED
@@ -91,7 +91,7 @@ models = df['model'].unique()
91
  df = df.pivot(columns="relation_type", index="model", values="correlation")
92
  df = df.T[models].T
93
  df['average'] = df.mean(1)
94
- df.to_csv("experiments/results/lm_qa/lm.csv")
95
  df = (100 * df).round()
96
  print(df.to_markdown())
97
  print(df.to_latex(escape=False))
 
91
  df = df.pivot(columns="relation_type", index="model", values="correlation")
92
  df = df.T[models].T
93
  df['average'] = df.mean(1)
94
+ df.to_csv("results/lm_qa/lm.csv")
95
  df = (100 * df).round()
96
  print(df.to_markdown())
97
  print(df.to_latex(escape=False))
experiments/baseline_oracle.py CHANGED
@@ -27,4 +27,4 @@ df = df.T
27
  df['average'] = df.mean(axis=1).round(1)
28
  print(df.to_markdown())
29
  print(df.to_latex())
30
- df.to_csv("experiments/results/oracle.csv")
 
27
  df['average'] = df.mean(axis=1).round(1)
28
  print(df.to_markdown())
29
  print(df.to_latex())
30
+ df.to_csv("results/oracle.csv")
experiments/baseline_relbert.py CHANGED
@@ -17,7 +17,7 @@ data = load_dataset("cardiffnlp/relentless", split="test")
17
  full_result = []
18
 
19
  for lm in ['base', 'large']:
20
- os.makedirs(f"./experiments/results/relbert/relbert-roberta-{lm}", exist_ok=True)
21
  scorer = None
22
  for d in data:
23
  ppl_file = f"experiments/results/relbert/relbert-roberta-{lm}/ppl.{d['relation_type'].replace(' ', '_').replace('/', '__')}.jsonl"
@@ -61,7 +61,7 @@ for lm in ['base', 'large']:
61
  df = pd.DataFrame(full_result)
62
  df = df.pivot(columns="relation_type", index="model", values="correlation")
63
  df['average'] = df.mean(1)
64
- df.to_csv("experiments/results/relbert/relbert.csv")
65
  df = (100 * df).round()
66
  print(df.to_markdown())
67
  print(df.to_latex())
 
17
  full_result = []
18
 
19
  for lm in ['base', 'large']:
20
+ os.makedirs(f"results/relbert/relbert-roberta-{lm}", exist_ok=True)
21
  scorer = None
22
  for d in data:
23
  ppl_file = f"experiments/results/relbert/relbert-roberta-{lm}/ppl.{d['relation_type'].replace(' ', '_').replace('/', '__')}.jsonl"
 
61
  df = pd.DataFrame(full_result)
62
  df = df.pivot(columns="relation_type", index="model", values="correlation")
63
  df['average'] = df.mean(1)
64
+ df.to_csv("results/relbert/relbert.csv")
65
  df = (100 * df).round()
66
  print(df.to_markdown())
67
  print(df.to_latex())
experiments/baseline_relbert_misc.py DELETED
@@ -1,67 +0,0 @@
1
- import os
2
- import json
3
- import pandas as pd
4
- from statistics import mean
5
- from datasets import load_dataset
6
- from relbert import RelBERT
7
-
8
-
9
- def cosine_similarity(a, b):
10
- norm_a = sum(map(lambda x: x * x, a)) ** 0.5
11
- norm_b = sum(map(lambda x: x * x, b)) ** 0.5
12
- return sum(map(lambda x: x[0] * x[1], zip(a, b))) / (norm_a * norm_b)
13
-
14
-
15
- # load dataset
16
- data = load_dataset("cardiffnlp/relentless_full", split="test")
17
- full_result = []
18
-
19
- for lm in ['relbert-roberta-base-nce-t-rex', 'relbert-roberta-base-nce-nell']:
20
- os.makedirs(f"./experiments/results/relbert/{lm}", exist_ok=True)
21
- scorer = None
22
- for d in data:
23
- ppl_file = f"experiments/results/relbert/{lm}/ppl.{d['relation_type'].replace(' ', '_').replace('/', '__')}.jsonl"
24
- anchor_embeddings = [(a, b) for a, b in d['positive_examples']]
25
- option_embeddings = [(x, y) for x, y in d['pairs']]
26
-
27
- if not os.path.exists(ppl_file):
28
-
29
- if scorer is None:
30
- scorer = RelBERT(f"relbert/{lm}")
31
- anchor_embeddings = scorer.get_embedding(d['positive_examples'])
32
- option_embeddings = scorer.get_embedding(d['pairs'], batch_size=64)
33
- similarity = [[cosine_similarity(a, b) for b in anchor_embeddings] for a in option_embeddings]
34
- output = [{"similarity": s} for s in similarity]
35
- with open(ppl_file, "w") as f:
36
- f.write("\n".join([json.dumps(i) for i in output]))
37
-
38
- with open(ppl_file) as f:
39
- similarity = [json.loads(i)['similarity'] for i in f.read().split("\n") if len(i) > 0]
40
-
41
- true_rank = d['ranks']
42
- assert len(true_rank) == len(similarity), f"Mismatch in number of examples: {len(true_rank)} vs {len(similarity)}"
43
- prediction = [max(s) for s in similarity]
44
- rank_map = {p: n for n, p in enumerate(sorted(prediction, reverse=True), 1)}
45
- prediction_max = [rank_map[p] for p in prediction]
46
-
47
- prediction = [min(s) for s in similarity]
48
- rank_map = {p: n for n, p in enumerate(sorted(prediction, reverse=True), 1)}
49
- prediction_min = [rank_map[p] for p in prediction]
50
-
51
- prediction = [mean(s) for s in similarity]
52
- rank_map = {p: n for n, p in enumerate(sorted(prediction, reverse=True), 1)}
53
- prediction_mean = [rank_map[p] for p in prediction]
54
-
55
- tmp = pd.DataFrame([true_rank, prediction_max, prediction_min, prediction_mean]).T
56
- cor_max = tmp.corr("spearman").values[0, 1]
57
- cor_min = tmp.corr("spearman").values[0, 2]
58
- cor_mean = tmp.corr("spearman").values[0, 3]
59
- full_result.append({"model": f"RelBERT\textsubscript{'{'}{lm.upper()}{'}'}", "relation_type": d['relation_type'], "correlation": cor_max})
60
-
61
- df = pd.DataFrame(full_result)
62
- df = df.pivot(columns="relation_type", index="model", values="correlation")
63
- df['average'] = df.mean(1)
64
- df.to_csv("experiments/results/relbert/relbert_misc.csv")
65
- df = (100 * df).round()
66
- print(df.to_markdown())
67
- print(df.to_latex())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
experiments/results/oracle.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,competitor/rival of,friend/ally of,influenced by,known for,similar to,average
2
+ Avg.\ of others,0.7743314787749431,0.7854235774817461,0.7150896845459409,0.8236406723889734,0.8064321816808586,0.8