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

Colab tutorial #134

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# aitextgen

[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://github.com/MohamedAliRashad/aitextgen/blob/colab-tutorial/train_aitextgen.ipynb)

A robust Python tool for text-based AI training and generation using [OpenAI's](https://openai.com) [GPT-2](https://openai.com/blog/better-language-models/) and [EleutherAI's](https://www.eleuther.ai) [GPT Neo/GPT-3](https://github.com/EleutherAI/gpt-neo) architecture.

aitextgen is a Python package that leverages [PyTorch](https://pytorch.org), [Hugging Face Transformers](https://github.com/huggingface/transformers) and [pytorch-lightning](https://github.com/PyTorchLightning/pytorch-lightning) with specific optimizations for text generation using GPT-2, plus _many_ added features. It is the successor to [textgenrnn](https://github.com/minimaxir/textgenrnn) and [gpt-2-simple](https://github.com/minimaxir/gpt-2-simple), taking the best of both packages:
Expand Down
11 changes: 5 additions & 6 deletions aitextgen/aitextgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class aitextgen:
tokenizer = None
vocab_file = os.path.join(STATIC_PATH, "gpt2_vocab.json")
merges_file = os.path.join(STATIC_PATH, "gpt2_merges.txt")
models = ["124M", "355M", "774M", "1558M"]
bos_token = "<|endoftext|>"
eos_token = "<|endoftext|>"
unk_token = "<|endoftext|>"
Expand Down Expand Up @@ -123,12 +124,7 @@ def __init__(
if not os.path.isfile(
os.path.join(cache_dir, f"pytorch_model_{tf_gpt2}.bin")
):
assert tf_gpt2 in [
"124M",
"355M",
"774M",
"1558M",
], "Invalid TensorFlow GPT-2 model size."
assert tf_gpt2 in self.models, "Invalid TensorFlow GPT-2 model size."

logger.info(
f"Downloading the {tf_gpt2} GPT-2 TensorFlow weights/config "
Expand Down Expand Up @@ -863,3 +859,6 @@ def __repr__(self) -> str:
num_params_m = int(sum(p.numel() for p in self.model.parameters()) / 10 ** 6)
model_name = type(self.model.config).__name__.replace("Config", "")
return f"{model_name} loaded with {num_params_m}M parameters."

def list_models(self) -> None:
print("\n".join(self.models))
Loading