Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -999,103 +999,133 @@ with ui.navset_card_tab(id="tab"):
|
|
999 |
multiple=True,
|
1000 |
selected='compliment'
|
1001 |
)
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
#
|
1008 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1009 |
df = pd.read_csv('results - denseformer.csv')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1010 |
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
|
1017 |
|
1018 |
-
|
1019 |
-
|
1020 |
|
1021 |
-
# Define colors for sizes and shapes for loss types
|
1022 |
-
size_colors = {
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
}
|
1028 |
|
1029 |
-
loss_markers = {
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
}
|
1034 |
|
1035 |
-
# Create the plot
|
1036 |
-
fig, ax = plt.subplots(figsize=(10, 6))
|
1037 |
|
1038 |
-
# Plot each combination of size and loss type
|
1039 |
-
for size in filtered_df["param_type"].unique():
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
|
1044 |
-
# Customize the plot
|
1045 |
-
ax.set_xlabel("Epoch")
|
1046 |
-
ax.set_ylabel("Loss")
|
1047 |
-
ax.set_title("Training Loss by Size and Loss Type", fontsize=16)
|
1048 |
|
1049 |
-
# Create a legend for sizes
|
1050 |
-
size_legend = ax.legend(title="Size", loc="upper right")
|
1051 |
-
ax.add_artist(size_legend)
|
1052 |
|
1053 |
-
# Create a separate legend for loss types
|
1054 |
-
loss_legend_labels = ["Compliment", "Cross Entropy", "Headless"]
|
1055 |
-
loss_legend_handles = [plt.Line2D([0], [0], marker=loss_markers[loss_type], color='black', linestyle='None', markersize=8) for loss_type in loss_markers]
|
1056 |
-
loss_legend = ax.legend(loss_legend_handles, loss_legend_labels, title="Loss Type", loc="upper right")
|
1057 |
|
1058 |
-
plt.tight_layout()
|
1059 |
-
return fig
|
1060 |
|
1061 |
-
# Define colors for sizes and shapes for loss types
|
1062 |
-
size_colors = {
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
}
|
1068 |
-
loss_markers = {
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
}
|
1073 |
|
1074 |
-
# Create a relplot using Seaborn
|
1075 |
-
g = sns.relplot(
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
)
|
1086 |
|
1087 |
-
# Customize the plot
|
1088 |
-
g.set_xlabels("Epoch")
|
1089 |
-
g.set_ylabels("Loss")
|
1090 |
-
g.fig.suptitle("Training Loss by Size and Loss Type", fontsize=16)
|
1091 |
-
g.add_legend(title="Size")
|
1092 |
|
1093 |
-
# Create a separate legend for loss types
|
1094 |
-
loss_legend = plt.legend(title="Loss Type", loc="upper right", labels=["Compliment", "Cross Entropy", "Headless"])
|
1095 |
-
plt.gca().add_artist(loss_legend)
|
1096 |
|
1097 |
-
plt.tight_layout()
|
1098 |
-
return g.fig
|
1099 |
|
1100 |
|
1101 |
# @render.image
|
|
|
999 |
multiple=True,
|
1000 |
selected='compliment'
|
1001 |
)
|
1002 |
+
def plot_loss_rates(df, param_types, loss_types, model_types):
|
1003 |
+
# interplot each column to be same number of points
|
1004 |
+
x = np.linspace(0, 1, 1000)
|
1005 |
+
loss_rates = []
|
1006 |
+
labels = []
|
1007 |
+
#drop the column step
|
1008 |
+
df = df.drop(columns=['Step'])
|
1009 |
+
for param_type in param_types:
|
1010 |
+
for loss_type in loss_types:
|
1011 |
+
for model_type in model_types:
|
1012 |
+
y = df[df['param_type']==param_type && df['loss_type']==loss_type && df['model_type']==model_type]['loss'].dropna().astype('float', errors = 'ignore').dropna().values
|
1013 |
+
f = interp1d(np.linspace(0, 1, len(y)), y)
|
1014 |
+
loss_rates.append(f(x))
|
1015 |
+
labels.append(param_type +'_'+loss_type +'_'+model_type)
|
1016 |
+
fig, ax = plt.subplots()
|
1017 |
+
for i, loss_rate in enumerate(loss_rates):
|
1018 |
+
ax.plot(x, loss_rate, label=labels[i])
|
1019 |
+
ax.legend()
|
1020 |
+
ax.set_title(f'Loss rates for a {type} parameter model across context windows')
|
1021 |
+
ax.set_xlabel('Training steps')
|
1022 |
+
ax.set_ylabel('Loss rate')
|
1023 |
+
return fig
|
1024 |
+
|
1025 |
+
import matplotlib as mpl
|
1026 |
+
@render.plot()
|
1027 |
+
def plot_context_size_scaling():
|
1028 |
+
fig = None
|
1029 |
df = pd.read_csv('results - denseformer.csv')
|
1030 |
+
mpl.rcParams.update(mpl.rcParamsDefault)
|
1031 |
+
fig = plot_loss_rates(df, input.param_type(),input.loss_type(),input.model_type())
|
1032 |
+
return fig
|
1033 |
+
# @output
|
1034 |
+
# @render.plot
|
1035 |
+
# def plot_training_loss():
|
1036 |
+
# # if csv_file() is None:
|
1037 |
+
# # return None
|
1038 |
+
|
1039 |
+
# df = pd.read_csv('results - denseformer.csv')
|
1040 |
|
1041 |
+
# filtered_df = df[
|
1042 |
+
# (df["param_type"].isin(input.param_type()))
|
1043 |
+
# & (df["model_type"].isin(input.model_type()))
|
1044 |
+
# & (df["loss_type"].isin(input.loss_type()))
|
1045 |
+
# ]
|
1046 |
|
1047 |
|
1048 |
+
# if filtered_df.empty:
|
1049 |
+
# return None
|
1050 |
|
1051 |
+
# # Define colors for sizes and shapes for loss types
|
1052 |
+
# size_colors = {
|
1053 |
+
# "14": "blue",
|
1054 |
+
# "31": "green",
|
1055 |
+
# "70": "orange",
|
1056 |
+
# "160": "red"
|
1057 |
+
# }
|
1058 |
|
1059 |
+
# loss_markers = {
|
1060 |
+
# "compliment": "o",
|
1061 |
+
# "cross_entropy": "^",
|
1062 |
+
# "headless": "s"
|
1063 |
+
# }
|
1064 |
|
1065 |
+
# # Create the plot
|
1066 |
+
# fig, ax = plt.subplots(figsize=(10, 6))
|
1067 |
|
1068 |
+
# # Plot each combination of size and loss type
|
1069 |
+
# for size in filtered_df["param_type"].unique():
|
1070 |
+
# for loss_type in filtered_df["loss_type"].unique():
|
1071 |
+
# data = filtered_df[(filtered_df["param_type"] == size) & (filtered_df["loss_type"] == loss_type)]
|
1072 |
+
# ax.plot(data["epoch"], data["loss"], marker=loss_markers[loss_type], color=size_colors[size], label=f"{size} - {loss_type}")
|
1073 |
|
1074 |
+
# # Customize the plot
|
1075 |
+
# ax.set_xlabel("Epoch")
|
1076 |
+
# ax.set_ylabel("Loss")
|
1077 |
+
# # ax.set_title("Training Loss by Size and Loss Type", fontsize=16)
|
1078 |
|
1079 |
+
# # Create a legend for sizes
|
1080 |
+
# size_legend = ax.legend(title="Size", loc="upper right")
|
1081 |
+
# ax.add_artist(size_legend)
|
1082 |
|
1083 |
+
# # Create a separate legend for loss types
|
1084 |
+
# loss_legend_labels = ["Compliment", "Cross Entropy", "Headless"]
|
1085 |
+
# loss_legend_handles = [plt.Line2D([0], [0], marker=loss_markers[loss_type], color='black', linestyle='None', markersize=8) for loss_type in loss_markers]
|
1086 |
+
# loss_legend = ax.legend(loss_legend_handles, loss_legend_labels, title="Loss Type", loc="upper right")
|
1087 |
|
1088 |
+
# plt.tight_layout()
|
1089 |
+
# return fig
|
1090 |
|
1091 |
+
# # Define colors for sizes and shapes for loss types
|
1092 |
+
# size_colors = {
|
1093 |
+
# "14": "blue",
|
1094 |
+
# "31": "green",
|
1095 |
+
# "70": "orange",
|
1096 |
+
# "160": "red"
|
1097 |
+
# }
|
1098 |
+
# loss_markers = {
|
1099 |
+
# "compliment": "o",
|
1100 |
+
# "cross_entropy": "^",
|
1101 |
+
# "headless": "s"
|
1102 |
+
# }
|
1103 |
|
1104 |
+
# # Create a relplot using Seaborn
|
1105 |
+
# g = sns.relplot(
|
1106 |
+
# data=filtered_df,
|
1107 |
+
# x="epoch",
|
1108 |
+
# y="loss",
|
1109 |
+
# hue="param_type",
|
1110 |
+
# style="loss_type",
|
1111 |
+
# palette=size_colors,
|
1112 |
+
# markers=loss_markers,
|
1113 |
+
# height=6,
|
1114 |
+
# aspect=1.5
|
1115 |
+
# )
|
1116 |
|
1117 |
+
# # Customize the plot
|
1118 |
+
# g.set_xlabels("Epoch")
|
1119 |
+
# g.set_ylabels("Loss")
|
1120 |
+
# g.fig.suptitle("Training Loss by Size and Loss Type", fontsize=16)
|
1121 |
+
# g.add_legend(title="Size")
|
1122 |
|
1123 |
+
# # Create a separate legend for loss types
|
1124 |
+
# loss_legend = plt.legend(title="Loss Type", loc="upper right", labels=["Compliment", "Cross Entropy", "Headless"])
|
1125 |
+
# plt.gca().add_artist(loss_legend)
|
1126 |
|
1127 |
+
# plt.tight_layout()
|
1128 |
+
# return g.fig
|
1129 |
|
1130 |
|
1131 |
# @render.image
|