Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binarized meta-templates; some extraction refactoring #218

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bbee489
Initial support for FEVER
norabelrose Apr 22, 2023
5ba1ddd
Start saving and fitting a reporter to the input embeddings
norabelrose Apr 22, 2023
3b1f74d
Merge branch 'input-embeddings' into template-filtering
norabelrose Apr 22, 2023
51ba54f
Rename layer 0 to 'input' to make it more clear
norabelrose Apr 22, 2023
544b485
Actually rename layer 0 correctly
norabelrose Apr 22, 2023
43da44e
Handle layer_stride correctly
norabelrose Apr 22, 2023
9056e00
Merge branch 'input-embeddings' into template-filtering
norabelrose Apr 22, 2023
756fa53
label_choices
norabelrose Apr 22, 2023
93b7ae0
Clean up train and eval commands; do transfer in sweep
norabelrose Apr 22, 2023
57d0b8b
Support INLP and split eval output into multiple CSVs
norabelrose Apr 22, 2023
228a6a0
Merge branch 'inlp' into template-filtering
norabelrose Apr 22, 2023
b086f0b
Merge branch 'inlp' into template-filtering
norabelrose Apr 25, 2023
934cd54
Log ensembled metrics
norabelrose Apr 26, 2023
dff69bf
Fixing pyright version
norabelrose Apr 26, 2023
b181d3e
Merge remote-tracking branch 'origin/main' into ensembling
norabelrose Apr 26, 2023
15254bf
Merge main
norabelrose Apr 26, 2023
69c2d55
Tons of stuff, preparing for sciq_binary experiment
norabelrose Apr 27, 2023
960ff01
Support --binarize again
norabelrose Apr 27, 2023
c9e62ea
Partial support for truthful_qa
norabelrose Apr 27, 2023
eb71a6c
Merge branch 'main' into template-filtering
norabelrose Apr 29, 2023
88bb15e
Merge remote-tracking branch 'origin/main' into template-filtering
norabelrose Apr 29, 2023
c648ff0
Remove crap
norabelrose Apr 29, 2023
ef12130
EleutherAI/truthful_qa_mc
norabelrose Apr 29, 2023
5d60ebd
Update templates
norabelrose Apr 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
label_choices
  • Loading branch information
norabelrose committed Apr 22, 2023
commit 756fa532c48731d951e9791d8eba761f564043b2
13 changes: 8 additions & 5 deletions elk/extraction/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
assert_type,
float32_to_int16,
infer_label_column,
infer_num_classes,
instantiate_model,
instantiate_tokenizer,
is_autoregressive,
Expand Down Expand Up @@ -216,13 +217,13 @@ def extract_hiddens(

log_p = outputs.logits[..., -answer_len:, :].log_softmax(dim=-1)
tokens = answer[..., None]
lm_logits[i, j] = log_p.gather(-1, tokens).sum()
lm_logits[i, j] = log_p.gather(-1, tokens).mean()

elif isinstance(outputs, Seq2SeqLMOutput):
# The cross entropy loss is averaged over tokens, so we need to
# multiply by the length to get the total log probability.
length = encoding.labels.shape[-1]
lm_logits[i, j] = -assert_type(Tensor, outputs.loss) * length
# length = encoding.labels.shape[-1]
lm_logits[i, j] = -assert_type(Tensor, outputs.loss) # * length

hiddens = (
outputs.get("decoder_hidden_states") or outputs["hidden_states"]
Expand Down Expand Up @@ -300,8 +301,10 @@ def get_splits() -> SplitDict:

prompter = DatasetTemplates(ds_name, config_name)
ds_features = assert_type(Features, info.features)
prompter.label_column or infer_label_column(ds_features)
num_classes = 2 # prompter.num_classes or infer_num_classes(ds_features[label_col])
label_col = prompter.label_column or infer_label_column(ds_features)
num_classes = len(prompter.label_choices) or infer_num_classes(
ds_features[label_col]
)

num_variants = cfg.prompts.num_variants
if num_variants < 0:
Expand Down
4 changes: 2 additions & 2 deletions elk/promptsource/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class DatasetTemplates:
TEMPLATE_FILENAME = "templates.yaml"

label_column: str | None
label_choices: list[str] | None
label_choices: list[str]

def __init__(self, dataset_name: str, subset_name: str | None = None):
self.dataset_name = dataset_name
Expand All @@ -400,7 +400,7 @@ def __init__(self, dataset_name: str, subset_name: str | None = None):

# Optional fields; may be None
self.label_column = yaml_dict.get(self.LABEL_COLUMN_KEY)
self.label_choices = yaml_dict.get(self.LABEL_CHOICES_KEY)
self.label_choices = yaml_dict.get(self.LABEL_CHOICES_KEY, [])

# Mapping from template name to template id
self.name_to_id_mapping = {}
Expand Down
1 change: 1 addition & 0 deletions elk/promptsource/templates/glue/mnli/templates.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dataset: glue
subset: mnli
label_choices: [0, 2]
templates:
02b4c44e-52cb-417b-b069-5d334b1f1a91: !Template
answer_choices: Always ||| Sometimes ||| Never
Expand Down
Loading