Skip to content

Instantly share code, notes, and snippets.

View omarsar's full-sized avatar
🐙

Elvis Saravia omarsar

🐙
View GitHub Profile
@omarsar
omarsar / bool_query_with_or.md
Created September 16, 2019 14:52
Bool Query with OR and AND
GET blogs_fixed/_search
{
    "query": {
        "query_string" : {
            "query" : "(content:elasticsearch AND content:engineering) OR (title:elasticsearch AND title:engineering)"
        }
    }
}
@omarsar
omarsar / eng1-milan.md
Created September 30, 2019 09:41
milan-eng1-module1.md
GET _search
{
  "query": {
    "match_all": {}
  }
}


GET /
!pip3 install torch torchvision
## 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)
## Neural network with 1 hidden layer
layer1 = nn.Linear(1,1, bias=False)
model = nn.Sequential(layer1)
## loss function
criterion = nn.MSELoss()
## optimizer algorithm
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
@omarsar
omarsar / train.py
Last active December 25, 2019 14:36
## training
for i in range(150):
model = model.train()
## forward
output = model(x)
loss = criterion(output, y)
optimizer.zero_grad()
## backward + update model params
## test the model
sample = torch.tensor([10.0], dtype=torch.float)
predicted = model(sample)
print(predicted.detach().item())
@omarsar
omarsar / libs.py
Last active December 29, 2019 15:56
## 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
## configuration to detect cuda or cpu
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print (device)