Spaces:
Runtime error
Runtime error
Download model_utils/tokenizer.py from FarhanAK128/LipNet-Pytorch: direct link, hf CLI and curl.
- Browser
- Download file 505 Bytes
-
https://huggingface.co/spaces/FarhanAK128/LipNet-Pytorch/resolve/main/model_utils/tokenizer.py
- Command line
-
hf download hf://spaces/FarhanAK128/LipNet-Pytorch/model_utils/tokenizer.py
-
curl -L -o tokenizer.py https://huggingface.co/spaces/FarhanAK128/LipNet-Pytorch/resolve/main/model_utils/tokenizer.py
505 Bytes
| from .vocabulary import vocabulary | |
| class Tokenizer: | |
| def __init__(self, vocab=vocabulary): | |
| self.str_to_int = vocab | |
| self.int_to_str = {id:token for token, id in vocab.items()} | |
| def encode(self, text): | |
| text_tokens = [token if token in self.str_to_int else "<|unk|>" for token in text] | |
| ids = [self.str_to_int[token] for token in text_tokens] | |
| return ids | |
| def decode(self, ids): | |
| text = "".join([self.int_to_str[id] for id in ids]) | |
| return text |