Text Generation
Transformers
Safetensors
English
gpt2
rlhf
sentiment-analysis
sft
text-generation-inference
Instructions to use Saif10/sft-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Saif10/sft-model with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Saif10/sft-model")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Saif10/sft-model") model = AutoModelForCausalLM.from_pretrained("Saif10/sft-model") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use Saif10/sft-model with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Saif10/sft-model" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Saif10/sft-model", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Saif10/sft-model
- SGLang
How to use Saif10/sft-model 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 "Saif10/sft-model" \ --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": "Saif10/sft-model", "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 "Saif10/sft-model" \ --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": "Saif10/sft-model", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Saif10/sft-model with Docker Model Runner:
docker model run hf.co/Saif10/sft-model
cool
Browse files
README.md
CHANGED
|
@@ -13,15 +13,16 @@ datasets:
|
|
| 13 |
- stanfordnlp/sst2
|
| 14 |
base_model:
|
| 15 |
- openai-community/gpt2
|
|
|
|
| 16 |
---
|
| 17 |
|
| 18 |
-
#
|
| 19 |
|
| 20 |
This model is the **first stage** in a 3-step RLHF (Reinforcement Learning from Human Feedback) pipeline using **GPT-2**. It has been fine-tuned on the **Stanford Sentiment Treebank v2 (SST2)** dataset, focusing on generating sentences with a positive sentiment tone.
|
| 21 |
|
| 22 |
---
|
| 23 |
|
| 24 |
-
##
|
| 25 |
|
| 26 |
This model is part of the following RLHF project structure:
|
| 27 |
|
|
@@ -33,7 +34,7 @@ You are currently viewing the **SFT model**.
|
|
| 33 |
|
| 34 |
---
|
| 35 |
|
| 36 |
-
##
|
| 37 |
|
| 38 |
Train GPT-2 on sentiment-labeled sentences to mimic human-like, sentiment-aware generation.
|
| 39 |
|
|
@@ -41,37 +42,28 @@ Train GPT-2 on sentiment-labeled sentences to mimic human-like, sentiment-aware
|
|
| 41 |
- **Output:** GPT-2 completes it with a positively-toned sentence.
|
| 42 |
|
| 43 |
---
|
| 44 |
-
|
| 45 |
-
## ๐ Training Details
|
| 46 |
-
|
| 47 |
-
### ๐ง Dataset
|
| 48 |
|
| 49 |
- **Source:** `stanfordnlp/sst2`
|
| 50 |
- **Type:** Movie review sentences
|
| 51 |
- **Labels:** Positive and Negative
|
| 52 |
- **Preprocessing:** Only positive samples retained for SFT
|
| 53 |
|
| 54 |
-
### โ๏ธ Configuration
|
| 55 |
-
|
| 56 |
-
- **Model Base:** `gpt2`
|
| 57 |
-
- **Max Sequence Length:** 128
|
| 58 |
-
- **Batch Size:** 8
|
| 59 |
-
- **Epochs:** 3
|
| 60 |
-
- **Optimizer:** AdamW
|
| 61 |
-
- **Learning Rate:** 5e-5
|
| 62 |
-
- **Precision:** FP16
|
| 63 |
-
|
| 64 |
-
---
|
| 65 |
-
|
| 66 |
-
## ๐ Usage
|
| 67 |
|
| 68 |
```python
|
| 69 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 70 |
|
| 71 |
-
model = AutoModelForCausalLM.from_pretrained("
|
| 72 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
| 73 |
|
| 74 |
prompt = "The movie was"
|
| 75 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 76 |
outputs = model.generate(**inputs, max_new_tokens=30)
|
| 77 |
-
print(tokenizer.decode(outputs[0]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
- stanfordnlp/sst2
|
| 14 |
base_model:
|
| 15 |
- openai-community/gpt2
|
| 16 |
+
pipeline_tag: text-generation
|
| 17 |
---
|
| 18 |
|
| 19 |
+
# GPT-2 SFT Model โ Supervised Fine-Tuning for Positive Sentiment
|
| 20 |
|
| 21 |
This model is the **first stage** in a 3-step RLHF (Reinforcement Learning from Human Feedback) pipeline using **GPT-2**. It has been fine-tuned on the **Stanford Sentiment Treebank v2 (SST2)** dataset, focusing on generating sentences with a positive sentiment tone.
|
| 22 |
|
| 23 |
---
|
| 24 |
|
| 25 |
+
## Context
|
| 26 |
|
| 27 |
This model is part of the following RLHF project structure:
|
| 28 |
|
|
|
|
| 34 |
|
| 35 |
---
|
| 36 |
|
| 37 |
+
## Model Objective
|
| 38 |
|
| 39 |
Train GPT-2 on sentiment-labeled sentences to mimic human-like, sentiment-aware generation.
|
| 40 |
|
|
|
|
| 42 |
- **Output:** GPT-2 completes it with a positively-toned sentence.
|
| 43 |
|
| 44 |
---
|
| 45 |
+
### Dataset
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
- **Source:** `stanfordnlp/sst2`
|
| 48 |
- **Type:** Movie review sentences
|
| 49 |
- **Labels:** Positive and Negative
|
| 50 |
- **Preprocessing:** Only positive samples retained for SFT
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
```python
|
| 54 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 55 |
|
| 56 |
+
model = AutoModelForCausalLM.from_pretrained("Saif10/sft-model")
|
| 57 |
+
tokenizer = AutoTokenizer.from_pretrained("Saif10/sft-model")
|
| 58 |
|
| 59 |
prompt = "The movie was"
|
| 60 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 61 |
outputs = model.generate(**inputs, max_new_tokens=30)
|
| 62 |
+
print(tokenizer.decode(outputs[0]))
|
| 63 |
+
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
## Author
|
| 67 |
+
Saif Rathod
|
| 68 |
+
- Hugging Face: Saif10
|
| 69 |
+
- GitHub: Saif-rathod
|