# ML Solution
[pypi](https://pypi.org/project/ml-solution/) [github](https://github.com/JiahongZhang/ml_solution) [modelscope](https://modelscope.cn/models/hugo42/ml_solution/summary)
This package is used to quickly build a pipline for mechine learning.
## Quick Start
### Installation
Easy installation with pip:
```bash
pip install ml_solution
```
### Code Sample
The code below shows how to use ml_solution to build flexible deep learning model frame quickly:
```python
import torch
from torch import optim
import torch.nn as nn
from dataset import creat_loader
import modeling
from ml_solution.dl_tools import engine, engine_utils, train_utils
from ml_solution import data_utils
from transformers import XLMRobertaTokenizer
train_config = data_utils.json_load('./train_config.json')
dataset_config = data_utils.json_load('./dataset_config.json')
train_loader = creat_loader(dataset_config['train_json_path'],)
valid_loader = creat_loader(dataset_config['valid_json_path'])
dataloaders = {
'train':train_loader,
'valid':valid_loader
}
model = modeling.get_model()
optimizer = optim.Adam(model.parameters(), lr=train_config['lr'])
criterion = train_utils.DictInputWarpper(nn.CrossEntropyLoss(), 'logit', 'label')
metric_grader = engine_utils.ConfusionMetrics(
num_classes=4,
metrics_list=train_config['metrics_list']
)
loss_grader = engine_utils.LossRecorder()
computers = {
'conf_metrics': metric_grader,
'loss': loss_grader
}
grader = engine_utils.Grader(computers)
wandb_init_config = data_utils.json_manipulate_keys(
train_config,
['lr', 'batch_size', "architecture"],
keep=True
)
wandb_init_config['criterion'] = criterion.module.__class__.__name__
wandb_init_config['optimizer'] = optimizer.__class__.__name__
logger = engine_utils.WandbLogger(
config=wandb_init_config, project=train_config['project'])
handler = engine.HandlerSaveModel(
metric_name="ACC",
log_root=train_config['log_root'],
version=logger.version,
ideal_th=5
)
trainer = engine.TorchTrainer(
model, dataloaders, criterion,
optimizer, device=device, mix_pre=train_config['mix_pre']
)
train_pipeline = engine.TrainPipeline(
trainer, grader, logger,
handler=handler
)
train_pipeline.train_epoches(train_config['epoches'])
```
Raw data
{
"_id": null,
"home_page": "https://github.com/JiahongZhang/ml_solution",
"name": "ml-solution",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "",
"keywords": "",
"author": "hugo",
"author_email": "hugo279@foxmail.com",
"download_url": "",
"platform": null,
"description": "# ML Solution\n\n[pypi](https://pypi.org/project/ml-solution/) [github](https://github.com/JiahongZhang/ml_solution) [modelscope](https://modelscope.cn/models/hugo42/ml_solution/summary)\n\nThis package is used to quickly build a pipline for mechine learning.\n\n## Quick Start\n\n### Installation\n\nEasy installation with pip:\n\n```bash\npip install ml_solution\n```\n\n### Code Sample\n\nThe code below shows how to use ml_solution to build flexible deep learning model frame quickly:\n\n```python\nimport torch\nfrom torch import optim\nimport torch.nn as nn\nfrom dataset import creat_loader\nimport modeling\nfrom ml_solution.dl_tools import engine, engine_utils, train_utils\nfrom ml_solution import data_utils\nfrom transformers import XLMRobertaTokenizer\n\ntrain_config = data_utils.json_load('./train_config.json')\ndataset_config = data_utils.json_load('./dataset_config.json')\n\ntrain_loader = creat_loader(dataset_config['train_json_path'],)\nvalid_loader = creat_loader(dataset_config['valid_json_path'])\ndataloaders = {\n 'train':train_loader,\n 'valid':valid_loader\n}\n\nmodel = modeling.get_model()\noptimizer = optim.Adam(model.parameters(), lr=train_config['lr'])\ncriterion = train_utils.DictInputWarpper(nn.CrossEntropyLoss(), 'logit', 'label')\n\nmetric_grader = engine_utils.ConfusionMetrics(\n num_classes=4, \n metrics_list=train_config['metrics_list']\n )\nloss_grader = engine_utils.LossRecorder()\ncomputers = {\n 'conf_metrics': metric_grader, \n 'loss': loss_grader\n}\ngrader = engine_utils.Grader(computers)\n\n\nwandb_init_config = data_utils.json_manipulate_keys(\n train_config, \n ['lr', 'batch_size', \"architecture\"], \n keep=True\n )\nwandb_init_config['criterion'] = criterion.module.__class__.__name__\nwandb_init_config['optimizer'] = optimizer.__class__.__name__\nlogger = engine_utils.WandbLogger(\n config=wandb_init_config, project=train_config['project'])\n\nhandler = engine.HandlerSaveModel(\n metric_name=\"ACC\", \n log_root=train_config['log_root'], \n version=logger.version,\n ideal_th=5\n )\n\ntrainer = engine.TorchTrainer(\n model, dataloaders, criterion, \n optimizer, device=device, mix_pre=train_config['mix_pre']\n )\n\ntrain_pipeline = engine.TrainPipeline(\n trainer, grader, logger, \n handler=handler\n )\n\ntrain_pipeline.train_epoches(train_config['epoches'])\n\n\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "A mechine learning pipeline lib.",
"version": "0.0.3",
"project_urls": {
"Homepage": "https://github.com/JiahongZhang/ml_solution"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "baacccfed3b56c77e2b4ed9ff83cdd4ed17d6a9f4a2fbe251af1c602c7ecdb59",
"md5": "06012932224a50aa78d20fc10e8319fb",
"sha256": "6d79a6a728a67e827a416df8bce1c63a87f104a6e5aeea3dc2edd830f6371f39"
},
"downloads": -1,
"filename": "ml_solution-0.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "06012932224a50aa78d20fc10e8319fb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 19970,
"upload_time": "2024-01-08T11:13:10",
"upload_time_iso_8601": "2024-01-08T11:13:10.668656Z",
"url": "https://files.pythonhosted.org/packages/ba/ac/ccfed3b56c77e2b4ed9ff83cdd4ed17d6a9f4a2fbe251af1c602c7ecdb59/ml_solution-0.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-08 11:13:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "JiahongZhang",
"github_project": "ml_solution",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "ml-solution"
}