# Import loads the model automatically (one-time download from HuggingFace)from gpt2_slm_instruct_inference import ask
# Simple questionprint(ask("What is the capital of France?"))
print()
# With input contextprint(ask(
instruction="Summarize the following text.",
input_text="Machine learning enables systems to learn from data rather than being explicitly programmed."
))
print()
# Control generationprint(ask(
"Write a short poem about the ocean.",
temperature=1.0, # higher = more creative
top_k=100, # wider sampling pool
max_tokens=150# longer output
))
print()
Option 3: Load weights manually
from huggingface_hub import hf_hub_download
import torch
model_path = hf_hub_download(
repo_id="nishantup/gpt2-slm-instruct",
filename="gpt2_slm_instruct.pth"
)
from gpt2_slm_instruct_inference import GPTModel, BASE_CONFIG
model = GPTModel(BASE_CONFIG)
model.load_state_dict(torch.load(model_path, map_location="cpu"))
model.eval()
Prompt Format
Below is an instruction that describes a task.
### Instruction:
{instruction}
### Response:
With optional input:
Below is an instruction that describes a task, paired with further context.
### Instruction:
{instruction}
### Input:
{input}
### Response: