Downloads · 30 days
0
ranshofen/transformers
transformers is a machine learning model from ranshofen. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments from datasets import loaddataset
Downloads · 30 days
0
Access
Public
Updated Aug 10, 2024
Repo size
—
Likes
0
Public
Click a slice to open those files.
Other1.5 KB · 53%
From the Hugging Face model README
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments from datasets import load_dataset
model_name = "distilbert-base-uncased" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=2)
dataset = load_dataset("imdb") # Вы можете использовать свой набор данных encoded_dataset = dataset.map(lambda examples: tokenizer(examples['text'], padding="max_length", truncation=True), batched=True)
training_args = TrainingArguments( output_dir="./results", evaluation_strategy="epoch", learning_rate=2e-5, per_device_train_batch_size=16, per_device_eval_batch_size=16, num_train_epochs=3, weight_decay=0.01, )
trainer = Trainer( model=model, args=training_args, train_dataset=encoded_dataset['train'], eval_dataset=encoded_dataset['test'], )
trainer.train()
model.save_pretrained("./my_custom_model") tokenizer.save_pretrained("./my_custom_model")