-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added detokenisation to llama2 experiments * Removed redundant parent * Switched endianness to little * Fixed transformers loading
- Loading branch information
1 parent
d94e5f7
commit 2445b09
Showing
2 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
import json | ||
|
||
from transformers import AutoTokenizer | ||
|
||
|
||
def get_accuracy_dict(accuracy_dict_full): | ||
accuracy_dict = {} | ||
for k in accuracy_dict_full.keys(): | ||
if k in [ "rouge1", "rouge2", "rougeL", "tokens_per_sample" ]: | ||
if k in ["rouge1", "rouge2", "rougeL", "tokens_per_sample"]: | ||
accuracy_dict[k] = accuracy_dict_full[k] | ||
return accuracy_dict | ||
|
||
def detokenise( | ||
checkpoint_path: str, tokenised_accuracy_log_path: str, output_log_path: str | ||
): | ||
tokeniser = AutoTokenizer.from_pretrained(checkpoint_path) | ||
|
||
with open(tokenised_accuracy_log_path) as f: | ||
log = json.load(f) | ||
|
||
output_log = [] | ||
for item in log: | ||
hex_str = item["data"] | ||
hex_tokens = [hex_str[i : i + 8] for i in range(0, len(hex_str), 8)] | ||
tokens = [ | ||
int.from_bytes(bytes.fromhex(tok), byteorder="little") for tok in hex_tokens | ||
] | ||
output_log.append(tokeniser.decode(tokens)) | ||
|
||
with open(output_log_path, "w") as f: | ||
json.dump(output_log, f, indent=2) | ||
return output_log_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters