This file contains 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
# pip install openai retry | |
import openai | |
from retry import retry | |
model="curie:ft-xxx-2021-01-09-19-21-20 | |
@retry(Exception, tries=3, delay=10) | |
def get_gpt_reason(prompt, model, prob=False, max_tokens=10): | |
This file contains 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
on: | |
pull_request: | |
types: [opened] | |
jobs: | |
comment: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/github-script@v5 | |
with: |
This file contains 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 time | |
from functools import wraps | |
def timing(f): | |
"""Decorator for timing functions | |
Usage: | |
@timing | |
def function(a): | |
pass |
This file contains 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
def fbeta_harmonic_mean(metric1: float, metric2: float, beta: float): | |
""" Return harmonic mean giving more importance to one metric | |
metric1: metric1 value | |
metric2: metric2 value | |
beta : The strength of metric2 versus metric1 in the F-score. | |
""" | |
beta2 = beta ** 2 | |
denom = beta2 * metric1 + metric2 | |
f_score = (1 + beta2) * metric1 * metric2 / denom | |
return f_score |
This file contains 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 numpy as np | |
import pandas as pd | |
from imblearn.over_sampling import RandomOverSampler | |
from imblearn.under_sampling import RandomUnderSampler | |
from sklearn.utils import class_weight | |
def get_class_weights(y, one_hot=False): | |
"""Returns a dict of class weights for label encoded as well as one-hot encoded y.""" | |
if one_hot: |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
from googletrans import Translator | |
from google.cloud import translate_v2 as translate | |
from textblob import TextBlob | |
class CustomTranslator: | |
def __init__(self, target='en'): | |
self.target = target | |
self.set_free_client() | |
self.set_google_client() |
This file contains 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 re, inspect | |
# Taken and modified from https://github.com/fastai/fastcore | |
class Base: | |
def _store_attr(self, **attrs): | |
for n,v in attrs.items(): | |
setattr(self, n, v) | |
self.__stored_args__[n] = v |
This file contains 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 os | |
def run_command(cmd): | |
return os.system(cmd) | |
def shutdown(seconds=0, os='linux'): | |
"""Shutdown system after seconds given. Useful for shutting EC2 to save costs.""" | |
if os == 'linux': | |
run_command('sudo shutdown -h -t sec %s' % seconds) | |
elif os == 'windows': |
This file contains 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
# Remove old version | |
brew uninstall elasticsearch-full | |
rm -rf /usr/local/var/lib/elasticsearch/ | |
rm -rf /usr/local/var/log/elasticsearch/elasticsearch_account.log | |
rm -rf /usr/local/var/elasticsearch/plugins/ | |
rm -rf /usr/local/etc/elasticsearch/ | |
brew uninstall kibana-full | |
rm -rf /usr/local/var/lib/kibana/ | |
rm -rf /usr/local/var/kibana/plugins/ |
NewerOlder