Instructions to use vipisdeath/HGRXv1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Flair
How to use vipisdeath/HGRXv1 with Flair:
from flair.models import SequenceTagger tagger = SequenceTagger.load("vipisdeath/HGRXv1") - Notebooks
- Google Colab
- Kaggle
Create train.py
Browse files
train.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# train.py
|
| 2 |
+
from datasets import load_dataset
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
|
| 4 |
+
|
| 5 |
+
# 1. Get the data
|
| 6 |
+
dataset = load_dataset("imdb") # Or "csv", data_files="my_data.csv"
|
| 7 |
+
|
| 8 |
+
# 2. Get the tools
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
| 10 |
+
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased", num_labels=2)
|
| 11 |
+
|
| 12 |
+
# 3. Process the data
|
| 13 |
+
def tokenize_func(examples):
|
| 14 |
+
return tokenizer(examples["text"], truncation=True, padding="max_length")
|
| 15 |
+
|
| 16 |
+
tokenized_datasets = dataset.map(tokenize_func, batched=True)
|
| 17 |
+
|
| 18 |
+
# 4. Set the rules
|
| 19 |
+
training_args = TrainingArguments(output_dir="my_model_folder", num_train_epochs=1)
|
| 20 |
+
|
| 21 |
+
# 5. Do the training
|
| 22 |
+
trainer = Trainer(
|
| 23 |
+
model=model,
|
| 24 |
+
args=training_args,
|
| 25 |
+
train_dataset=tokenized_datasets["train"],
|
| 26 |
+
eval_dataset=tokenized_datasets["test"],
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
trainer.train()
|