Skip to content

Instantly share code, notes, and snippets.

View bhavsarpratik's full-sized avatar

Pratik Bhavsar bhavsarpratik

View GitHub Profile
@bhavsarpratik
bhavsarpratik / pr-checklist.yml
Created January 9, 2022 16:14
PR checklist github action
on:
pull_request:
types: [opened]
jobs:
comment:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v5
with:
@bhavsarpratik
bhavsarpratik / gpt3_inference.py
Last active February 16, 2024 13:12
OpenaAI GPT3 inference
# 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):
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
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()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
# 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/
PUT /test_index
{
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "synonym_analyzer",
"search_analyzer": "synonym_analyzer"
},
# https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html
# Explicit mappings match any token sequence on the LHS of "=>"
# and replace with all alternatives on the RHS. These types of mappings
# ignore the expand parameter in the schema.
# Examples:
i-pod, i pod => ipod,
sea biscuit, sea biscit => seabiscuit
# Equivalent synonyms may be separated with commas and give
# no explicit mapping. In this case the mapping behavior will
PUT /test_index
{
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "synonym_analyzer",
"search_analyzer": "synonym_analyzer"
}