Instructions to use JTSJohnny/pipi0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use JTSJohnny/pipi0 with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://JTSJohnny/pipi0") - Notebooks
- Google Colab
- Kaggle
Download utils/preprocess_corpus.py from JTSJohnny/pipi0: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/JTSJohnny/pipi0/resolve/main/utils/preprocess_corpus.py
- Command line
-
hf download hf://JTSJohnny/pipi0/utils/preprocess_corpus.py
-
curl -L -o preprocess_corpus.py https://huggingface.co/JTSJohnny/pipi0/resolve/main/utils/preprocess_corpus.py
1.47 kB
| from tokenizer import load_tokenizer | |
| from os import listdir | |
| from tqdm import tqdm | |
| import subprocess | |
| if __name__ == "__main__": | |
| print("Preparing corpus for training...") | |
| tokenizer = load_tokenizer("trained/tokenizer_saved.json") | |
| print("Save path: data/pretraining/corpus_tokenized.txt") | |
| with open( | |
| "data/pretraining/corpus_tokenized.txt", | |
| "w", | |
| encoding="utf-8", | |
| ) as corpus_f: | |
| for filename in listdir("data/rawtexts/"): | |
| with open( | |
| "data/rawtexts/" + filename, | |
| "r", | |
| encoding="utf-8", | |
| ) as f: | |
| line = f.readline() | |
| with tqdm( | |
| desc=f"Preprocessing corpus file: {filename}", | |
| unit="lines", | |
| total=int( | |
| subprocess.run( | |
| ["wc", "-l", "data/rawtexts/" + str(filename)], | |
| capture_output=True, | |
| text=True, | |
| ).stdout.split()[0] | |
| ), | |
| ) as prog: | |
| while line != "": | |
| encoding = tokenizer.encode(line) | |
| for token_id in encoding.ids: | |
| corpus_f.write(str(token_id)) | |
| corpus_f.write(" ") | |
| line = f.readline() | |
| prog.update(1) | |
| print("Done!") | |