GET blogs_fixed/_search
{
"query": {
"query_string" : {
"query" : "(content:elasticsearch AND content:engineering) OR (title:elasticsearch AND title:engineering)"
}
}
}
GET _search
{
"query": {
"match_all": {}
}
}
GET /
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!pip3 install torch torchvision |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## our data in tensor form | |
x = torch.tensor([[-1.0], [0.0], [1.0], [2.0], [3.0], [4.0]], dtype=torch.float) | |
y = torch.tensor([[-3.0], [-1.0], [1.0], [3.0], [5.0], [7.0]], dtype=torch.float) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Neural network with 1 hidden layer | |
layer1 = nn.Linear(1,1, bias=False) | |
model = nn.Sequential(layer1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## loss function | |
criterion = nn.MSELoss() | |
## optimizer algorithm | |
optimizer = torch.optim.SGD(model.parameters(), lr=0.01) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## training | |
for i in range(150): | |
model = model.train() | |
## forward | |
output = model(x) | |
loss = criterion(output, y) | |
optimizer.zero_grad() | |
## backward + update model params |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## test the model | |
sample = torch.tensor([10.0], dtype=torch.float) | |
predicted = model(sample) | |
print(predicted.detach().item()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Import the usual libraries | |
import torch | |
import torchvision | |
import torch.nn as nn | |
from torchvision import datasets, models, transforms | |
import os | |
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## configuration to detect cuda or cpu | |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") | |
print (device) |