Spaces:
Build error
Build error
Update cs772_proj/app.py
Browse files- cs772_proj/app.py +10 -10
cs772_proj/app.py
CHANGED
|
@@ -83,9 +83,9 @@ def create_bert(cache_dir=None):
|
|
| 83 |
"""Creates a GPT2 model, config, and tokenizer from the given name and revision"""
|
| 84 |
from transformers import BertConfig
|
| 85 |
|
| 86 |
-
config = BertConfig.from_pretrained("./
|
| 87 |
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
|
| 88 |
-
gpt = AutoModelForSequenceClassification.from_pretrained("./
|
| 89 |
print("loaded model")
|
| 90 |
return config, tokenizer, gpt
|
| 91 |
def interpret(text,label):
|
|
@@ -164,9 +164,9 @@ def interpret(text,label):
|
|
| 164 |
prob_offense = probabilities[0][l].item()
|
| 165 |
data.append({"layer": layer_i, "pos": pos_i, "prob": prob_offense})
|
| 166 |
df = pd.DataFrame(data)
|
| 167 |
-
df.to_csv(f"./
|
| 168 |
for stream in ["block_output", "mlp_activation", "attention_output"]:
|
| 169 |
-
df = pd.read_csv(f"./
|
| 170 |
df["layer"] = df["layer"].astype(int)
|
| 171 |
df["pos"] = df["pos"].astype(int)
|
| 172 |
prob_type = "p"+"("+label+")"
|
|
@@ -189,13 +189,13 @@ def interpret(text,label):
|
|
| 189 |
+ theme(axis_text_y = element_text(angle = 90, hjust = 1))
|
| 190 |
)
|
| 191 |
ggsave(
|
| 192 |
-
plot, filename=f"./
|
| 193 |
)
|
| 194 |
if stream == "mlp_activation":
|
| 195 |
-
mlp_img_path = f"./
|
| 196 |
elif stream=="block_output":
|
| 197 |
-
bo_path = f"./
|
| 198 |
-
else:attention_path = f"./
|
| 199 |
return mlp_img_path,bo_path,attention_path
|
| 200 |
|
| 201 |
def restore_corrupted_with_interval_config(
|
|
@@ -252,9 +252,9 @@ def create_bert(cache_dir=None):
|
|
| 252 |
"""Creates a GPT2 model, config, and tokenizer from the given name and revision"""
|
| 253 |
from transformers import BertConfig
|
| 254 |
|
| 255 |
-
config = BertConfig.from_pretrained("./
|
| 256 |
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
|
| 257 |
-
gpt = AutoModelForSequenceClassification.from_pretrained("./
|
| 258 |
print("loaded model")
|
| 259 |
return config, tokenizer, gpt
|
| 260 |
|
|
|
|
| 83 |
"""Creates a GPT2 model, config, and tokenizer from the given name and revision"""
|
| 84 |
from transformers import BertConfig
|
| 85 |
|
| 86 |
+
config = BertConfig.from_pretrained("./cs772_proj/bert_base/checkpoint-3848/config.json")
|
| 87 |
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
|
| 88 |
+
gpt = AutoModelForSequenceClassification.from_pretrained("./cs772_proj/bert_base/checkpoint-3848", config=config, cache_dir=cache_dir)
|
| 89 |
print("loaded model")
|
| 90 |
return config, tokenizer, gpt
|
| 91 |
def interpret(text,label):
|
|
|
|
| 164 |
prob_offense = probabilities[0][l].item()
|
| 165 |
data.append({"layer": layer_i, "pos": pos_i, "prob": prob_offense})
|
| 166 |
df = pd.DataFrame(data)
|
| 167 |
+
df.to_csv(f"./cs772_proj/tutorial_data/pyvene_rome_{stream}.csv")
|
| 168 |
for stream in ["block_output", "mlp_activation", "attention_output"]:
|
| 169 |
+
df = pd.read_csv(f"./cs772_proj/tutorial_data/pyvene_rome_{stream}.csv")
|
| 170 |
df["layer"] = df["layer"].astype(int)
|
| 171 |
df["pos"] = df["pos"].astype(int)
|
| 172 |
prob_type = "p"+"("+label+")"
|
|
|
|
| 189 |
+ theme(axis_text_y = element_text(angle = 90, hjust = 1))
|
| 190 |
)
|
| 191 |
ggsave(
|
| 192 |
+
plot, filename=f"./cs772_proj/tutorial_data/pyvene_rome_{stream}.png", dpi=200
|
| 193 |
)
|
| 194 |
if stream == "mlp_activation":
|
| 195 |
+
mlp_img_path = f"./cs772_proj/tutorial_data/pyvene_rome_{stream}.png"
|
| 196 |
elif stream=="block_output":
|
| 197 |
+
bo_path = f"./cs772_proj/tutorial_data/pyvene_rome_{stream}.png"
|
| 198 |
+
else:attention_path = f"./cs772_proj/tutorial_data/pyvene_rome_{stream}.png"
|
| 199 |
return mlp_img_path,bo_path,attention_path
|
| 200 |
|
| 201 |
def restore_corrupted_with_interval_config(
|
|
|
|
| 252 |
"""Creates a GPT2 model, config, and tokenizer from the given name and revision"""
|
| 253 |
from transformers import BertConfig
|
| 254 |
|
| 255 |
+
config = BertConfig.from_pretrained("./cs772_proj/bert_base/checkpoint-3848/config.json")
|
| 256 |
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
|
| 257 |
+
gpt = AutoModelForSequenceClassification.from_pretrained("./cs772_proj/bert_base/checkpoint-3848", config=config, cache_dir=cache_dir)
|
| 258 |
print("loaded model")
|
| 259 |
return config, tokenizer, gpt
|
| 260 |
|