Skip to content

Instantly share code, notes, and snippets.

View maulberto3's full-sized avatar

Mauricio maulberto3

View GitHub Profile
import optuna
import xgboost as xgb
from sklearn.metrics import mean_squared_error # or any other metric
from sklearn.model_selection import train_test_split
# Load the dataset
X, y = ... # load your own
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Define the objective function for Optuna
@finiteautomata
finiteautomata / run_mlm_big_text_files.py
Created August 3, 2021 12:54
Train MLM with big text files (Workaround)
"""
This is a workaround for `examples/run_mlm.py` for pretraining models
with big text files line-by-line.
For the time being, `datasets` is facing some issues dealing with really
big text files, so we use a custom dataset until this is fixed.
August 3th 2021
Author: Juan Manuel Pérez
@kumaraditya303
kumaraditya303 / main.py
Last active March 14, 2024 12:06
MultiThreaded Playwright with ThreadPoolExecutor
import threading
from playwright.sync_api import sync_playwright
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
class Tls(threading.local):
def __init__(self) -> None:
self.playwright = sync_playwright().start()
print("Create playwright instance in Thread", threading.current_thread().name)
@dims
dims / README.md
Last active May 22, 2024 09:02
Kubernetes Resources
@MineRobber9000
MineRobber9000 / donotuse3.py
Last active February 8, 2024 12:48
How to NEVER use lambdas - Python 3 edition
###########################################################
# How to NEVER use lambdas. An inneficient and yet educa- #
# tonal [sic] guide to the proper misuse of the lambda #
# construct in Python 3.x. [DO NOT USE ANY OF THIS EVER] #
# original by (and apologies to): e000 (13/6/11) #
# now in Python 3 courtesy of: khuxkm (17/9/20) #
###########################################################
## Part 1. Basic LAMBDA Introduction ##
# If you're reading this, you've probably already read e000's
@vadimkantorov
vadimkantorov / perlin.py
Last active February 15, 2024 10:36
Perlin noise in PyTorch
# ported from https://github.com/pvigier/perlin-numpy/blob/master/perlin2d.py
import torch
import math
def rand_perlin_2d(shape, res, fade = lambda t: 6*t**5 - 15*t**4 + 10*t**3):
delta = (res[0] / shape[0], res[1] / shape[1])
d = (shape[0] // res[0], shape[1] // res[1])
grid = torch.stack(torch.meshgrid(torch.arange(0, res[0], delta[0]), torch.arange(0, res[1], delta[1])), dim = -1) % 1
@johnmeade
johnmeade / pool_data_loader.py
Created July 13, 2019 19:50
A Python multiprocessing pool drop-in replacement for the PyTorch DataLoader class
'''
A multiprocessing Pool drop-in replacement for the pytorch
DataLoader class. Built to work around an apparent bug in
the default pytorch DataLoader, in which it hangs indefinitely.
It is possible to reach a sustained 95-100% GPU usage (as
reported by `nvidia-smi`) using this implementation.
Requirements:
pip install filelock
@ibuildthecloud
ibuildthecloud / README.md
Last active May 14, 2024 21:29
k3s on WSL2

Instructions to hack up WSL2 on Windows 10 Build 18917 to run k3s (Kubernetes) and rio

Install WSL2

https://docs.microsoft.com/en-us/windows/wsl/wsl2-install

I already had Ubuntu-18.04 installed in wsl 1. So I just did wsl --set-version Ubuntu-18.04 2

Compile Kernel

Using Ubuntu 18.04 (I'm sure any distro will work), inside WSL2 download https://thirdpartysource.microsoft.com/download/Windows%20Subsystem%20for%20Linux%20v2/May%202019/WSLv2-Linux-Kernel-master.zip and extract to a folder. The latest version of the kernel source is available at (https://github.com/microsoft/WSL2-Linux-Kernel)

@eshirazi
eshirazi / sqlalchemy_azure_mssql_pyodbc.py
Created April 25, 2019 09:49
SQLAlchemy connect to Azure SQL, using PyODBC
# On mac, run these first:
# - brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
# - brew update
# - brew install msodbcsql17 mssql-tools
#
# Install requirements:
# - pip install pyodbc sqlalchemny
import urllib
from sqlalchemy import create_engine
@gkhayes
gkhayes / Mountain_Car.py
Created February 22, 2019 08:09
Use Q-learning to solve the OpenAI Gym Mountain Car problem
import numpy as np
import gym
import matplotlib.pyplot as plt
# Import and initialize Mountain Car Environment
env = gym.make('MountainCar-v0')
env.reset()
# Define Q-learning function
def QLearning(env, learning, discount, epsilon, min_eps, episodes):