https://github.com/havakv/torchtuples

Training neural networks in PyTorch

https://github.com/havakv/torchtuples

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    7 of 11 committers (63.6%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.5%) to scientific vocabulary

Keywords

deep-learning machine-learning neural-network python pytorch

Keywords from Contributors

survival-analysis
Last synced: 5 months ago · JSON representation

Repository

Training neural networks in PyTorch

Basic Info
  • Host: GitHub
  • Owner: havakv
  • License: bsd-2-clause
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 369 KB
Statistics
  • Stars: 27
  • Watchers: 1
  • Forks: 12
  • Open Issues: 6
  • Releases: 5
Topics
deep-learning machine-learning neural-network python pytorch
Created over 7 years ago · Last pushed almost 2 years ago
Metadata Files
Readme License

README.md

torchtuples

Python package PyPI PyPI PyPI - Python Version License

torchtuples is a small python package for training PyTorch models. It works equally well for numpy arrays and torch tensors. One of the main benefits of torchtuples is that it handles data in the form of nested tuples (see example below).

Installation

torchtuples depends on PyTorch which should be installed from HERE.

Next, torchtuples can be installed with pip: bash pip install torchtuples Or, via conda: bash conda install -c conda-forge torchtuples For the bleeding edge version, install directly from github (consider adding --force-reinstall): bash pip install git+git://github.com/havakv/torchtuples.git or by cloning the repo: bash git clone https://github.com/havakv/torchtuples.git cd torchtuples python setup.py install

Example

python import torch from torch import nn from torchtuples import Model, optim Make a data set with three sets of covariates x0, x1 and x2, and a target y. The covariates are structured in a nested tuple x. python n = 500 x0, x1, x2 = [torch.randn(n, 3) for _ in range(3)] y = torch.randn(n, 1) x = (x0, (x0, x1, x2)) Create a simple ReLU net that takes as input the tensor x_tensor and the tuple x_tuple. Note that x_tuple can be of arbitrary length. The tensors in x_tuple are passed through a layer lin_tuple, averaged, and concatenated with x_tensor. We then pass our new tensor through the layer lin_cat. ```python class Net(nn.Module): def init(self): super().init() self.lintuple = nn.Linear(3, 2) self.lincat = nn.Linear(5, 1) self.relu = nn.ReLU()

def forward(self, x_tensor, x_tuple):
    x = [self.relu(self.lin_tuple(xi)) for xi in x_tuple]
    x = torch.stack(x).mean(0)
    x = torch.cat([x, x_tensor], dim=1)
    return self.lin_cat(x)

def predict(self, x_tensor, x_tuple):
    x = self.forward(x_tensor, x_tuple)
    return torch.sigmoid(x)

```

We can now fit the model with python model = Model(Net(), nn.MSELoss(), optim.SGD(0.01)) log = model.fit(x, y, batch_size=64, epochs=5) and make predictions with either the Net.predict method python preds = model.predict(x) or with the Net.forward method python preds = model.predict_net(x)

For more examples, see the examples folder.

Owner

  • Name: Haavard Kvamme
  • Login: havakv
  • Kind: user
  • Company: University of Oslo

GitHub Events

Total
  • Watch event: 1
  • Pull request event: 1
Last Year
  • Watch event: 1
  • Pull request event: 1

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 148
  • Total Committers: 11
  • Avg Commits per committer: 13.455
  • Development Distribution Score (DDS): 0.291
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
havakv h****e@g****m 105
Haavard Kvamme h****e@g****m 18
Haavard Kvamme h****e@a****m 9
Havard h****d@1****o 3
Havard h****d@1****o 3
Havard h****d@1****o 2
Havard h****d@1****o 2
Havard h****d@1****o 2
Håvard Kvamme k****e@s****o 2
Havard h****d@1****o 1
Sarthak Pati s****i@p****u 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 10
  • Total pull requests: 16
  • Average time to close issues: 2 days
  • Average time to close pull requests: about 1 month
  • Total issue authors: 4
  • Total pull request authors: 3
  • Average comments per issue: 0.6
  • Average comments per pull request: 0.31
  • Merged pull requests: 14
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • havakv (7)
  • kyuchoi (1)
  • sarthakpati (1)
  • hgjlee (1)
Pull Request Authors
  • havakv (13)
  • YonghaoZhao722 (1)
  • sarthakpati (1)
  • zyh040521 (1)
Top Labels
Issue Labels
enhancement (3) bug (3)
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 11,392 last-month
  • Total dependent packages: 2
    (may contain duplicates)
  • Total dependent repositories: 15
    (may contain duplicates)
  • Total versions: 8
  • Total maintainers: 1
pypi.org: torchtuples

Training neural networks in PyTorch

  • Versions: 5
  • Dependent Packages: 1
  • Dependent Repositories: 15
  • Downloads: 11,392 Last month
Rankings
Dependent repos count: 3.7%
Downloads: 4.2%
Dependent packages count: 4.8%
Average: 7.3%
Forks count: 10.5%
Stargazers count: 13.2%
Maintainers (1)
Last synced: 5 months ago
conda-forge.org: torchtuples
  • Versions: 3
  • Dependent Packages: 1
  • Dependent Repositories: 0
Rankings
Dependent packages count: 28.8%
Dependent repos count: 34.0%
Average: 38.0%
Forks count: 42.2%
Stargazers count: 46.8%
Last synced: 5 months ago

Dependencies

requirements-dev.txt pypi
  • pytest >=4.0.2 development
.github/workflows/publish_pypi.yml actions
  • actions/checkout v1 composite
  • actions/setup-python v1 composite
  • pypa/gh-action-pypi-publish master composite
.github/workflows/pythonpackage.yml actions
  • actions/checkout v1 composite
  • actions/setup-python v1 composite
setup.py pypi