|
import os |
|
import matplotlib as mpl |
|
import matplotlib.pyplot as plt |
|
import pandas as pd |
|
from random import shuffle, seed |
|
|
|
|
|
model_size = { |
|
"T5\textsubscript{SMALL}": [60, "T5"], |
|
"T5\textsubscript{BASE}": [200, "T5"], |
|
"T5\textsubscript{LARGE}": [770, "T5"], |
|
"T5\textsubscript{XL}": [3000, "T5"], |
|
"T5\textsubscript{XXL}": [11000, "T5"], |
|
"Flan-T5\textsubscript{SMALL}": [60, "Flan-T5"], |
|
"Flan-T5\textsubscript{BASE}": [200, "Flan-T5"], |
|
"Flan-T5\textsubscript{LARGE}": [770, "Flan-T5"], |
|
"Flan-T5\textsubscript{XL}": [3000, "Flan-T5"], |
|
"Flan-T5\textsubscript{XXL}": [11000, "Flan-T5"], |
|
"OPT\textsubscript{125M}": [125, "OPT"], |
|
"OPT\textsubscript{350M}": [350, "OPT"], |
|
"OPT\textsubscript{1.3B}": [1300, "OPT"], |
|
"OPT\textsubscript{2.7B}": [2700, "OPT"], |
|
"OPT\textsubscript{6.7B}": [6700, "OPT"], |
|
"OPT\textsubscript{13B}": [13000, "OPT"], |
|
"OPT\textsubscript{30B}": [30000, "OPT"], |
|
"OPT\textsubscript{66B}": [66000, "OPT"], |
|
"OPT-IML\textsubscript{1.3B}": [1300, "OPT-IML"], |
|
"OPT-IML\textsubscript{30B}": [30000, "OPT-IML"], |
|
} |
|
lm_list = ['T5', 'Flan-T5', 'OPT', 'OPT-IML'] |
|
|
|
|
|
df_oracle = pd.read_csv("experiments/results/oracle.csv", index_col=0) |
|
|
|
|
|
os.makedirs('experiments/figures/main', exist_ok=True) |
|
plt.rcParams.update({'font.size': 18}) |
|
|
|
|
|
def main(target_relation: str = "average", prompt_type: str = "lc"): |
|
df = pd.read_csv(f"experiments/results/lm_{prompt_type}/lm.csv") |
|
df.index = df.pop("model") |
|
df = (df * 100).round(1) |
|
df = df[[i in model_size for i in df.index]] |
|
df["size"] = [model_size[i][0] * 1000000 for i in df.index] |
|
df["lm"] = [model_size[i][1] for i in df.index] |
|
|
|
df_target = df[[target_relation, "size", "lm"]] |
|
out = df_target.pivot_table(index='size', columns='lm', aggfunc='mean') |
|
out.columns = [i[1] for i in out.columns] |
|
out = out.reset_index() |
|
out = out[['size'] + lm_list] |
|
|
|
styles = ['o-', '^--', 'X:', "P:"] |
|
seed(1) |
|
colors = list(mpl.colormaps['tab20b'].colors) |
|
shuffle(colors) |
|
|
|
ax = None |
|
for n, c in enumerate(lm_list): |
|
tmp = out[['size', c]].dropna().reset_index() |
|
ax = tmp.plot.line(y=c, |
|
x='size', |
|
xlabel='', |
|
ylabel="", |
|
ax=ax, |
|
color=colors[n], |
|
style=styles[n], |
|
label=c, |
|
logx=True, |
|
grid=True, |
|
figsize=(4, 5)) |
|
|
|
if prompt_type == 'qa': |
|
ax.legend().remove() |
|
else: |
|
ax.legend(loc='lower right') |
|
|
|
plt.tight_layout() |
|
plt.savefig(f"experiments/figures/main/{prompt_type}.{target_relation.replace(' ', '_').replace('/', '-')}.png", bbox_inches="tight", dpi=600) |
|
|
|
|
|
if __name__ == '__main__': |
|
for p in ['lc', 'qa']: |
|
main('average', p) |
|
main("is competitor/rival of", p) |
|
main("is friend/ally of", p) |
|
main("is influenced by", p) |
|
main("is known for", p) |
|
main("is similar to", p) |
|
|