YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Bard β trained from scratch, pushed to Hugging Face
A complete, minimal project: a custom tokenizer, a small Transformer built by hand, a training loop, and a script to publish the result to the Hugging Face Hub.
Files
| File | What it does |
|---|---|
tokenizer.py |
A word-level tokenizer that learns its own vocabulary from your text β no external files. |
model.py |
A small Transformer encoder classifier, wrapped as a proper Hugging Face PreTrainedModel. |
sample_data.csv |
50 labeled example sentences (positive/negative) to get you started. |
train.py |
Trains the model from scratch on sample_data.csv. |
push_to_hub.py |
Uploads your trained model to huggingface.co. |
MODEL_CARD.md |
Becomes the model's README on the Hub. |
Steps
Install dependencies (locally, or in a free Colab notebook β training is small and fast even on CPU):
pip install -r requirements.txt(Optional) Replace
sample_data.csvwith your own data. Keep the same two columns:text,label(label is0or1). More rows = a better model β even a few hundred makes a real difference.Train:
python train.pyThis prints loss/accuracy per epoch and saves the trained model to
tiny-sentiment-model/.Create a Hugging Face account and access token, if you don't have one: https://huggingface.co/join, then https://huggingface.co/settings/tokens (create a token with "write" access).
Log in from the terminal:
huggingface-cli loginEdit
REPO_IDinpush_to_hub.pyto"your-username/tiny-sentiment-model".Push it:
python push_to_hub.pyYour model will be live at
https://huggingface.co/your-username/tiny-sentiment-model.
Notes
- This model is trained fully from scratch (random weight initialization) β it does not fine-tune any existing pretrained model. That keeps it small and fast to train, but it will need more data than the 50-row sample to get genuinely good at sentiment analysis.
- Because the model is a custom architecture, anyone loading it later
needs
model.pyalongside the checkpoint (or you can addtrust_remote_codesupport β ask if you'd like help setting that up soAutoModel.from_pretrained(...)works without the file). - Want to go bigger later? The same pattern (config + PreTrainedModel)
scales up β just increase
hidden_size,num_layers, and dataset size.