--- language: fa license: apache-2.0 tags: - farsi - persian --- # GPT2-Persian Bolbol-zaban/gpt2-persian is gpt2 language model that is trained with hyper parameters similar to standard gpt2-medium with two differences: 1. The context size is reduced from 1024 to 256 sub words in order to make the training affordable 2. Instead of BPE, google sentence piece tokenizor is used for tokenization. 3. The training dataset only include Persian text. All non-persian characters are replaced with especial tokens (e.g [LAT], [URL], [NUM]) Please refer to this [blog post](https://medium.com/@khashei/a-not-so-dangerous-ai-in-the-persian-language-39172a641c84) for further detail. Also try the model [here](https://huggingface.co/bolbolzaban/gpt2-persian?text=%D8%AF%D8%B1+%DB%8C%DA%A9+%D8%A7%D8%AA%D9%81%D8%A7%D9%82+%D8%B4%DA%AF%D9%81%D8%AA+%D8%A7%D9%86%DA%AF%DB%8C%D8%B2%D8%8C+%D9%BE%DA%98%D9%88%D9%87%D8%B4%DA%AF%D8%B1%D8%A7%D9%86) or on [Bolbolzaban.com](http://www.bolbolzaban.com/text). ## How to use You can use this model directly with a pipeline for text generation: ```python from transformers import pipeline, AutoTokenizer, GPT2LMHeadModel tokenizer = AutoTokenizer.from_pretrained('bolbolzaban/gpt2-persian') model = GPT2LMHeadModel.from_pretrained('bolbolzaban/gpt2-persian') generator = pipeline('text-generation', model, tokenizer=tokenizer, config={'max_length':256}) sample = generator('در یک اتفاق شگفت انگیز، پژوهشگران') ``` If you are using Tensorflow import TFGPT2LMHeadModel instead of GPT2LMHeadModel. ## Acknowledgment This project is supported by Cloud TPUs from Google’s TensorFlow Research Cloud (TFRC). ## Citation and Reference Please reference "bolbolzaban.com" website if you are using gpt2-persian in your research or commertial application. ## Contacts [Bolbolzaban.com](http://bolbolzaban.com/about), [Twitter](https://twitter.com/bolbol_zaban), [Telegram](https://t.me/bolbol_zaban), [Instagram](https://www.instagram.com/bolbolzaban/), [Linkedin](https://www.linkedin.com/in/khashei/)