Downloads · 30 days
19
0% of all-time downloads
cwestnedge/gpt2-small-pubmed
gpt2-small-pubmed is a text generation model from cwestnedge. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
This pipeline was used to fine‑tune GPT‑2 small, medium, and large on abstracts from PubMed's baseline data. Models were trained on a single A100 GPU in Google Colab.
Downloads · 30 days
19
0% of all-time downloads
All-time downloads
116K
Public
Parameters
124M
139 GB on disk
Likes
0
Public
Click a slice to open those files.
.pt1.5 GB · 75%
From the Hugging Face model README
This pipeline was used to fine‑tune GPT‑2 small, medium, and large on abstracts from PubMed's baseline data. Models were trained on a single A100 GPU in Google Colab.
Here are the the loss curves for GPT‑2 small, medium, and large fine‑tuned on PubMed abstracts over single epoch.
Hold‑out set of 1000 × 16 × 1024 tokens (≈ 16.4 M tokens) randomly sampled from PubMed abstracts, disjoint from the training split.
Cross‑entropy loss (averaged over all tokens) and derived perplexity (ppl = exp(loss)) on the hold‑out set:
| Model | Parameters | Avg CE Loss ↓ | Perplexity ↓ |
|---|---|---|---|
| gpt2‑small‑pubmed | 124 M | 2.5017 | 12.20 |
| gpt2‑medium‑pubmed | 355 M | 2.2984 | 9.96 |
| gpt2‑large‑pubmed | 774 M | 2.1863 | 8.90 |
from transformers import pipeline
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
generator = pipeline(
"text-generation",
model="cwestnedge/gpt2-small-pubmed",
tokenizer="openai-community/gpt2",
device=device,
)
prompt = (
"Background: The CRISPR–Cas9 system has revolutionized gene editing. "
"In this study, we evaluate its efficacy in"
)
out = generator(
prompt,
max_length=200,
temperature=1e-9,
top_p=1e-9,
num_return_sequences=1,
truncation=True,
)
print(out[0]["generated_text"])
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
device = "cuda" if torch.cuda.is_available() else "cpu"
model_name = "cwestnedge/gpt2-small-pubmed"
tokenizer = AutoTokenizer.from_pretrained("openai-community/gpt2")
model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
inputs = tokenizer(
"Methods: We performed a double‐blind randomized trial to assess",
return_tensors="pt",
).to(device)
gen_ids = model.generate(
**inputs,
max_length=150,
num_beams=5,
no_repeat_ngram_size=2,
early_stopping=True,
)
print(tokenizer.decode(gen_ids[0], skip_special_tokens=True))
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
device = "cuda" if torch.cuda.is_available() else "cpu"
model_name = "cwestnedge/gpt2-small-pubmed"
tokenizer = AutoTokenizer.from_pretrained("openai-community/gpt2")
model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
text = (
"Tetralogy of Fallot is a rare congenital heart condition that is present at birth."
)
enc = tokenizer(text, return_tensors="pt").to(device)
with torch.no_grad():
outputs = model(**enc, labels=enc.input_ids)
loss = outputs.loss
ppl = torch.exp(loss)
print(f"CE loss: {loss:.4f} → Perplexity: {ppl:.2f}")