No project description provided
Project description
ai-utils
Installation
pip install cyvidia-ai-utils
Cross validation
Huggingface Trainer API
from cyvidia_ai_utils import TransformerCrossValidationModel, cross_validate, EvaluationResult
from transformers import AutoTokenizer, AutoModelForSequenceClassification,TrainingArguments
from datasets import load_dataset, Dataset
from transformers import DataCollatorWithPadding,Trainer
folds = load_dataset("dipesh/Intent-Classification-small",split=[f"train[{k}%:{k+10}%]" for k in range(0, 100, 10)])
assert(isinstance(folds, list))
def create_model():
model = AutoModelForSequenceClassification.from_pretrained("prajjwal1/bert-tiny", num_labels=21)
tokenizer= AutoTokenizer.from_pretrained("prajjwal1/bert-tiny")
return TransformerCrossValidationModel(
model= model,
tokenizer= tokenizer,
training_args= TrainingArguments(
output_dir=f'tests/test_models/{uuid.uuid4()}',
learning_rate=2e-5,
per_device_train_batch_size=16,
per_device_eval_batch_size=16,
num_train_epochs=0.001,
weight_decay=0.01,
evaluation_strategy="epoch",
save_strategy="epoch",
load_best_model_at_end=True,
)
)
# folds can either be a list of Dataset's or a dictionary of label to Dataset
folds_dict= {f"train[{k}%:{k+10}%]": fold for k, fold in enumerate(folds)}
results=cross_validate(create_model, folds_dict, target_id_column="label", input_text_column="text")
aggragated_result= EvaluationResult.aggregate(list(results.values()))
Custom Trainer
from cyvidia_ai_utils import CrossValidationModel
class MyCustomCrossValidationModel(CrossValidationModel):
def get_label_for_id(self, id: int)-> str:
# Implement
def train(self, train_ds, val_ds)-> CrossValidationModel:
# Implement
def predict_values(self, values)-> Dict[str,Any]:
# Implement
def create_model():
return MyCustomCrossValidationModel()
results= cross_validate(create_model, folds, target_id_column="label", input_text_column="text")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cyvidia_ai_utils-1.0.4.tar.gz
.
File metadata
- Download URL: cyvidia_ai_utils-1.0.4.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22bcee1bcd0f9289da56aaaa3a3ff305201ce6213ced8e0d616af2bd1ba3397b |
|
MD5 | 5fef4fa180929eb2eed34fd5e62d8b05 |
|
BLAKE2b-256 | dcfb33063cd12b3f4bb81bd061c54c2a2af34a67833c80ceaef070c00fc6f2d2 |
File details
Details for the file cyvidia_ai_utils-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: cyvidia_ai_utils-1.0.4-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3122ceb232079c5e8919bd06019e9b4c3799315d23cf602e51295cc046ab433d |
|
MD5 | 7ff5a925ae83b5d1715ec154e0836456 |
|
BLAKE2b-256 | 09b82dec24bae5371118e20394ac26bbe768186d05707bd7d018bc722caaca03 |