Run this model with HF Jobs

Run ModerRAS/AniFileBERT on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/ModerRAS/AniFileBERT. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/ModerRAS/AniFileBERT on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
AniFileBERT / model.py
ModerRAS's picture
Add AniFileBERT model and training project
be5f706
Raw History Blame
2.04 kB
"""
Tiny BERT model for anime filename token classification.
Uses HuggingFace BertForTokenClassification from scratch (no pretrained weights).
"""
from transformers import BertConfig, BertForTokenClassification
from config import Config
def create_model(config: Config) -> BertForTokenClassification:
"""
Create a Tiny BERT model for token classification.
Args:
config: Config object with model hyperparameters.
Returns:
A BertForTokenClassification model initialized from scratch.
"""
bert_config = BertConfig(
vocab_size=config.vocab_size,
hidden_size=config.hidden_size,
num_hidden_layers=config.num_hidden_layers,
num_attention_heads=config.num_attention_heads,
intermediate_size=config.intermediate_size,
max_position_embeddings=config.max_position_embeddings,
num_labels=config.num_labels,
hidden_dropout_prob=config.hidden_dropout_prob,
attention_probs_dropout_prob=config.attention_probs_dropout_prob,
)
model = BertForTokenClassification(bert_config)
return model
def count_parameters(model) -> int:
"""Count total trainable parameters in a model."""
return sum(p.numel() for p in model.parameters())
def print_model_summary(model):
"""Print model architecture summary with parameter count."""
total_params = count_parameters(model)
trainable_params = sum(p.numel() for p in model.parameters() if p.requires_grad)
print(f"Total parameters: {total_params:,}")
print(f"Trainable parameters: {trainable_params:,}")
print(f"Parameter limit: 5,000,000")
if total_params < 5_000_000:
print(f"[OK] Within 5M limit ({(5_000_000 - total_params):,} remaining)")
else:
print(f"[FAIL] Exceeds 5M limit by {total_params - 5_000_000:,}")
return total_params
if __name__ == "__main__":
cfg = Config()
# Set a placeholder vocab_size for standalone testing
cfg.vocab_size = 3000
model = create_model(cfg)
print_model_summary(model)