Views
No views yet
do_sample=False to maximise factual accuracy1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
4
5BASE_MODEL = "HuggingFaceTB/SmolLM2-1.7B"
6PEFT_MODEL = "ZygAI/ZygAI-OSS-2B-Encyclopedia"
7
8tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
9model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, torch_dtype=torch.float16)
10model = PeftModel.from_pretrained(model, PEFT_MODEL)
11model.eval()
12
13prompt = "Vilnius is the capital of Lithuania, which"
14
15inputs = tokenizer(prompt, return_tensors="pt")
16with torch.no_grad():
17 outputs = model.generate(
18 **inputs,
19 max_new_tokens=150,
20 do_sample=False,
21 repetition_penalty=1.3,
22 no_repeat_ngram_size=3,
23 pad_token_id=tokenizer.eos_token_id,
24 )
25
26print(tokenizer.decode(outputs[0], skip_special_tokens=True))1# Clone the Space repository
2git clone https://huggingface.co/spaces/ZygAI/ZygAI-Encyclopedia-2B-DEMO
3cd ZygAI-Encyclopedia-2B-DEMO
4
5# Create and activate a Python virtual environment
6python -m venv env
7source env/bin/activate # Windows: env\Scripts\activate
8
9# Install dependencies and launch
10pip install -r requirements.txt
11python app.py1docker run -it -p 7860:7860 --platform=linux/amd64 --gpus all \
2 registry.hf.space/zygai-zygai-encyclopedia-2b-demo:latest python app.pyNote: Review the Space code before running locally. GPU (--gpus all) is optional — the app falls back to CPU automatically.
Albert Einstein was a physicist whoVilnius yra Lietuvos sostinė, kuriThe Battle of Grunwald took place inKauno pilis yra vienas seniausių| Property | Value |
|---|---|
| Base model | HuggingFaceTB/SmolLM2-1.7B |
| Fine-tuning method | LoRA (PEFT) via TRL SFT |
| Training data | 200,000+ Wikipedia paragraphs (LT + EN) |
| Hardware | NVIDIA A100 SXM (RunPod) |
| Precision | float16 |
do_sample=False (greedy); sampling may produce incoherent output1@software{vonwerra2020trl,
2 title = {{TRL: Transformers Reinforcement Learning}},
3 author = {von Werra, Leandro and Belkada, Younes and Tunstall, Lewis and Beeching, Edward
4 and Thrush, Tristan and Lambert, Nathan and Huang, Shengyi and Rasul, Kashif
5 and Gallouédec, Quentin},
6 license = {Apache-2.0},
7 url = {https://github.com/huggingface/trl},
8 year = {2020}
9}