Text Generation
Transformers
Safetensors
Turkish
gpt2
mathematics
gsm8k
turkish
sft
dpo
text-generation-inference
Instructions to use OnurAkyar/Cosmos-Math-Gpt2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OnurAkyar/Cosmos-Math-Gpt2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="OnurAkyar/Cosmos-Math-Gpt2")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("OnurAkyar/Cosmos-Math-Gpt2") model = AutoModelForCausalLM.from_pretrained("OnurAkyar/Cosmos-Math-Gpt2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use OnurAkyar/Cosmos-Math-Gpt2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OnurAkyar/Cosmos-Math-Gpt2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OnurAkyar/Cosmos-Math-Gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/OnurAkyar/Cosmos-Math-Gpt2
- SGLang
How to use OnurAkyar/Cosmos-Math-Gpt2 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 "OnurAkyar/Cosmos-Math-Gpt2" \ --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": "OnurAkyar/Cosmos-Math-Gpt2", "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 "OnurAkyar/Cosmos-Math-Gpt2" \ --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": "OnurAkyar/Cosmos-Math-Gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use OnurAkyar/Cosmos-Math-Gpt2 with Docker Model Runner:
docker model run hf.co/OnurAkyar/Cosmos-Math-Gpt2
|
Download README.md from OnurAkyar/Cosmos-Math-Gpt2: direct link, hf CLI and curl.
- Browser
- Download file 2.52 kB
-
https://huggingface.co/OnurAkyar/Cosmos-Math-Gpt2/resolve/main/README.md
- Command line
-
hf download hf://OnurAkyar/Cosmos-Math-Gpt2/README.md
-
curl -L -o README.md https://huggingface.co/OnurAkyar/Cosmos-Math-Gpt2/resolve/main/README.md
2.52 kB
| language: | |
| - tr | |
| license: mit | |
| library_name: transformers | |
| tags: | |
| - mathematics | |
| - gsm8k | |
| - turkish | |
| - text-generation | |
| - sft | |
| - dpo | |
| base_model: ytu-ce-cosmos/turkish-gpt2-medium | |
| datasets: | |
| - malhajar/gsm8k-tr | |
| # Cosmos-Math-Gpt2 (Türkçe Matematik Modeli) | |
| Bu model, Türkçe matematik problemlerini adım adım mantık yürüterek (Chain of Thought) çözmek için geliştirilmiştir. Model ilk olarak next token prediction ile pre-training yapılmıştır. | |
| 2.adım olarak Sft uygulanmış ve son olarak Dpo algoritması uygulanarak fine-tuning işlemleri yapılmıştır. | |
| **ytu-ce-cosmos/turkish-gpt2-medium** taban modeli üzerine inşa edilmiş olup, önce **SFT (Supervised Fine-Tuning)** ardından **DPO (Direct Preference Optimization)** yöntemleri ile **GSM8K-TR** veri seti üzerinde eğitilmiştir. | |
| ## Model Yetenekleri | |
| - İlkokul ve ortaokul seviyesindeki matematik problemlerini çözer. | |
| - Problemi parçalara ayırır ve adım adım anlatır. | |
| - Sonucu `#### [Cevap]` formatında verir. | |
| ## Nasıl Kullanılır? | |
| Modeli kullanmak için aşağıdaki Python kodunu çalıştırabilirsiniz. Model **"### Soru:"** ve **"### Cevap:"** formatına duyarlıdır. | |
| ```python | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| import torch | |
| # 1. Modeli Yükle | |
| model_name = "KullaniciAdin/Cosmos-TR-Math-v1" # Burayı kendi kullanıcı adınla değiştir | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_name, | |
| torch_dtype=torch.float16, | |
| device_map="auto" | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| # 2. Tahmin Fonksiyonu | |
| def solve_math_problem(question): | |
| # Prompt formatı eğitimdeki gibi olmalı | |
| prompt = f"### Soru: {question}\n### Cevap:" | |
| inputs = tokenizer(prompt, return_tensors="pt").to(device) | |
| with torch.no_grad(): | |
| outputs = model.generate( | |
| **inputs, | |
| max_new_tokens=256, # Cevap uzunluğu | |
| do_sample=False, # Deterministik (Daha tutarlı cevaplar için) | |
| temperature=0.0, | |
| pad_token_id=tokenizer.eos_token_id | |
| ) | |
| # Sadece cevabı al | |
| full_text = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| return full_text.split("### Cevap:")[-1].strip() | |
| # 3. Örnek Kullanım | |
| soru = "Ali'nin 50 lirası var. Tanesi 5 lira olan kalemlerden 3 tane alırsa geriye kaç lirası kalır?" | |
| cevap = solve_math_problem(soru) | |
| print(f"SORU: {soru}") | |
| print("-" * 30) | |
| print(f"CEVAP:\n{cevap}") |