Skip to content

Commit da3d1a4

Browse files
Add PyTorch snippets
1 parent 2597b76 commit da3d1a4

File tree

6 files changed

+68
-10
lines changed

6 files changed

+68
-10
lines changed

README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,24 @@ The easiest way to install Python Data Science Snippets is through [Package Cont
1414
* [Matplotlib](#matplotlib)
1515
* [Scikit-learn](#scikit-learn)
1616
* [Keras](#keras)
17+
* [PyTorch](#pytorch)
1718

1819
### Imports
1920

2021
Import snippets start with `i` followed by the package's import alias.
2122

22-
| Trigger | Description |
23-
|------------|-----------------------------------|
24-
| `ikeras` | `from tensorflow import keras` |
25-
| `inp` | `import numpy as np` |
26-
| `ipd` | `import pandas as pd` |
27-
| `iplt` | `import matplotlib.pyplot as plt` |
28-
| `isklearn` | `from sklearn.$1 import $2` |
29-
| `isns` | `import seaborn as sns` |
30-
| `itf` | `import tensorflow as tf` |
31-
| `itorch` | `import torch` |
23+
| Trigger | Description |
24+
|------------|-------------------------------------------|
25+
| `ikeras` | `from tensorflow import keras` |
26+
| `inp` | `import numpy as np` |
27+
| `ipd` | `import pandas as pd` |
28+
| `iplt` | `import matplotlib.pyplot as plt` |
29+
| `isklearn` | `from sklearn.$1 import $2` |
30+
| `isns` | `import seaborn as sns` |
31+
| `itf` | `import tensorflow as tf` |
32+
| `itorch` | `import torch` |
33+
| `inn` | `from torch import nn` |
34+
| `idl` | `from torch.utils.data import DataLoader` |
3235

3336
### NumPy
3437

@@ -89,4 +92,12 @@ Import snippets start with `i` followed by the package's import alias.
8992
| `save` | `model.save` |
9093
| `sequential` | `keras.Sequential` |
9194

95+
### PyTorch
96+
97+
| Trigger | Description |
98+
|--------------|-------------------------------|
99+
| `dataloader` | `torch.utils.data.DataLoader` |
100+
| `device` | `torch.device (cuda/cpu)` |
101+
| `module` | `torch.nn.Module` |
102+
92103
The snippet files are in the `snippets` folder of [this GitHub repository](https://github.com/futureprogrammer360/Python-Data-Science-Snippets).

snippets/imports/dl.sublime-snippet

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<snippet>
2+
<content><![CDATA[
3+
from torch.utils.data import DataLoader
4+
]]></content>
5+
<tabTrigger>idl</tabTrigger>
6+
<scope>source.python</scope>
7+
<description>from torch.utils.data import DataLoader</description>
8+
</snippet>

snippets/imports/nn.sublime-snippet

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<snippet>
2+
<content><![CDATA[
3+
from torch import nn
4+
]]></content>
5+
<tabTrigger>inn</tabTrigger>
6+
<scope>source.python</scope>
7+
<description>from torch import nn</description>
8+
</snippet>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<snippet>
2+
<content><![CDATA[
3+
${1:dataloader} = ${2:torch.utils.data.}DataLoader(${3:dataset}, batch_size=${4:1})
4+
]]></content>
5+
<tabTrigger>dataloader</tabTrigger>
6+
<scope>source.python</scope>
7+
<description>torch.utils.data.DataLoader</description>
8+
</snippet>

snippets/torch/device.sublime-snippet

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<snippet>
2+
<content><![CDATA[
3+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
4+
]]></content>
5+
<tabTrigger>device</tabTrigger>
6+
<scope>source.python</scope>
7+
<description>torch device (cuda/cpu)</description>
8+
</snippet>

snippets/torch/module.sublime-snippet

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<snippet>
2+
<content><![CDATA[
3+
class ${1:Model}(${2:nn.}Module):
4+
def __init__(self$3):
5+
super(${1:Model}, self).__init__()
6+
self.${4:layer} = ${5:${2:nn.}Linear}($0)
7+
8+
def forward(self, x):
9+
x = self.${4:layer}(x)
10+
return x
11+
]]></content>
12+
<tabTrigger>module</tabTrigger>
13+
<scope>source.python</scope>
14+
<description>torch.nn.Module</description>
15+
</snippet>

0 commit comments

Comments
 (0)