Text Generation
Transformers
PyTorch
JAX
Arabic
gpt2
poetry
Eval Results (legacy)
text-generation-inference
Instructions to use elgeish/gpt2-medium-arabic-poetry with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use elgeish/gpt2-medium-arabic-poetry with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="elgeish/gpt2-medium-arabic-poetry")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("elgeish/gpt2-medium-arabic-poetry") model = AutoModelForCausalLM.from_pretrained("elgeish/gpt2-medium-arabic-poetry") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use elgeish/gpt2-medium-arabic-poetry with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "elgeish/gpt2-medium-arabic-poetry" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "elgeish/gpt2-medium-arabic-poetry", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/elgeish/gpt2-medium-arabic-poetry
- SGLang
How to use elgeish/gpt2-medium-arabic-poetry with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "elgeish/gpt2-medium-arabic-poetry" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "elgeish/gpt2-medium-arabic-poetry", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "elgeish/gpt2-medium-arabic-poetry" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "elgeish/gpt2-medium-arabic-poetry", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use elgeish/gpt2-medium-arabic-poetry with Docker Model Runner:
docker model run hf.co/elgeish/gpt2-medium-arabic-poetry
YAML Metadata Error:"datasets[0]" with value "Arabic Poetry Dataset (6th - 21st century)" is not valid. If possible, use a dataset id from https://hf.co/datasets.
GPT2-Medium-Arabic-Poetry
Fine-tuned aubmindlab/aragpt2-medium on the Arabic Poetry Dataset (6th - 21st century) using 41,922 lines of poetry as the train split and 9,007 (by poets not in the train split) for validation.
Usage
from transformers import AutoModelForCausalLM, AutoTokenizer, set_seed
set_seed(42)
model_name = "elgeish/gpt2-medium-arabic-poetry"
model = AutoModelForCausalLM.from_pretrained(model_name).to("cuda")
tokenizer = AutoTokenizer.from_pretrained(model_name)
prompt = "للوهلة الأولى قرأت في عينيه"
input_ids = tokenizer.encode(prompt, return_tensors="pt")
samples = model.generate(
input_ids.to("cuda"),
do_sample=True,
early_stopping=True,
max_length=32,
min_length=16,
num_return_sequences=3,
pad_token_id=50256,
repetition_penalty=1.5,
top_k=32,
top_p=0.95,
)
for sample in samples:
print(tokenizer.decode(sample.tolist()))
print("--")
Here's the output:
للوهلة الأولى قرأت في عينيه عن تلك النسم لم تذكر شيءا فلربما نامت علي كتفيها العصافير وتناثرت اوراق التوت عليها وغابت الوردة من
--
للوهلة الأولى قرأت في عينيه اية نشوة من ناره وهي تنظر الي المستقبل بعيون خلاقة ورسمت خطوطه العريضة علي جبينك العاري رسمت الخطوط الحمر فوق شعرك
--
للوهلة الأولى قرأت في عينيه كل ما كان وما سيكون غدا اذا لم تكن امراة ستكبر كثيرا علي الورق الابيض او لا تري مثلا خطوطا رفيعة فوق صفحة الماء
--
- Downloads last month
- 26
Model tree for elgeish/gpt2-medium-arabic-poetry
Evaluation results
- Validation Perplexity on Arabic Poetry Dataset (6th - 21st century)self-reported282.090