Downloads · 30 days
21
40% of all-time downloads
mreeza/simple-transformer-model
simple-transformer-model is a text generation model from mreeza. Use it when you need the model to write or continue text. It is set up for pytorch. The card lists the license as apache-2.0.
This is a simple Transformer Decoder-based autoregressive language model developed as part of a deep learning project. It was trained on the WikiText-2 dataset using PyTorch, with a focus on learning to generate Engli…
Downloads · 30 days
21
40% of all-time downloads
All-time downloads
53
Public
Parameters
109M
495 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors438 MB · 88%
From the Hugging Face model README
This is a simple Transformer Decoder-based autoregressive language model developed as part of a deep learning project.
It was trained on the WikiText-2 dataset using PyTorch, with a focus on learning to generate English text in an autoregressive manner (predicting the next token given previous tokens).
The model follows a decoder-only architecture similar to models like GPT, using causal masking to prevent attention to future tokens.
Dataset Link: WikiText-2 on Hugging Face Datasets
✅ Loss decreased successfully during training, indicating the model learned the structure of English text.
Note: Since this is a custom PyTorch model (not a Hugging Face PreTrainedModel), you must manually define and load it.
import torch
from transformers import AutoTokenizer
from your_custom_model_code import SimpleTransformerDecoderModel # import your model class
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("mreeza/simple-transformer-model")
# Initialize the model
model = SimpleTransformerDecoderModel(
vocab_size=len(tokenizer),
d_model=128,
nhead=4,
num_layers=2,
max_seq_len=256
)
# Load trained weights
model.load_state_dict(torch.load("pytorch_model.bin", map_location="cpu"))
model.eval()
# Generate text
def generate_text(model, tokenizer, prompt="Once upon a time", max_length=50):
model.eval()
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
with torch.no_grad():
for _ in range(max_length):
outputs = model(input_ids)
next_token_logits = outputs[:, -1, :]
next_token_id = torch.argmax(next_token_logits, dim=-1).unsqueeze(0)
input_ids = torch.cat([input_ids, next_token_id], dim=-1)
return tokenizer.decode(input_ids[0], skip_special_tokens=True)
prompt = "Once upon a time"
generated = generate_text(model, tokenizer, prompt)
print(generated)