-
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.
fix(): correct training and inference code to use gpt4 tokenizer
- Loading branch information
Showing
11 changed files
with
125 additions
and
45 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
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
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
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
Empty file.
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
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from signwriting_translation.bin import load_sockeye_translator, translate | ||
from signwriting_translation.tokenizer import tokenize_spoken_text | ||
|
||
spoken_language = "en" | ||
signed_language = "ase" | ||
texts = [ | ||
"Hello world", | ||
"World", | ||
"Hello", | ||
"How are you?" | ||
"Hello, how are you?", | ||
"Hi", | ||
"goodbye world", | ||
"My name is Amit.", | ||
"test", | ||
"Test", | ||
"testing", | ||
"Testing", | ||
"Washington D.C.", | ||
"Washington, D.C.", | ||
"Washington DC", | ||
] | ||
translator, spoken_tokenizer = load_sockeye_translator( | ||
"/shares/iict-sp2.ebling.cl.uzh/amoryo/checkpoints/signwriting-translation/spoken-to-signed/target-factors-gpt-tuned/model", | ||
log_timing=True) | ||
tokenized_texts = [tokenize_spoken_text(text) for text in texts] | ||
model_inputs = [f"${spoken_language} ${signed_language} {tokenized_text}" for tokenized_text in tokenized_texts] | ||
|
||
for translation in translate(translator, model_inputs, log_timing=True): | ||
print(translation) | ||
print("M500x500S38800464x496") |
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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from functools import lru_cache | ||
|
||
import tiktoken | ||
|
||
|
||
@lru_cache() | ||
def load_tokenizer(): | ||
return tiktoken.get_encoding("cl100k_base") | ||
|
||
|
||
def tokenize_spoken_text(text: str): | ||
tokenizer = load_tokenizer() | ||
encoding = tokenizer.encode(text) | ||
|
||
tokens_text = [tokenizer.decode([t]) for t in encoding] | ||
# replace space with special token: | ||
tokens_text = [t.replace(" ", "Ġ") for t in tokens_text] | ||
|
||
return " ".join(tokens_text) | ||
|
||
|
||
if __name__ == "__main__": | ||
print(tokenize_spoken_text("Hello world, my name is amit.")) |
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