Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View lppier's full-sized avatar

Pier lppier

View GitHub Profile
@lppier
lppier / gist:3a11c5c54b18d2b33126da7eb3ee5b66
Created December 30, 2023 08:08
AI Voice Cloning for MacOS
RVC-Mangio
https://github.com/Mangio621/Mangio-RVC-Fork/releases
Google Doc for MacOS Install Instructions
https://docs.google.com/document/d/1KKKE7hoyGXMw-Lg0JWx16R8xz3OfxADjwEYJTqzDO1k/edit#heading=h.8vqd8m4fh76q
Voice Models
https://voice-models.com/
def nextpow2(N):
""" Function for finding the next power of 2 """
n = 1
while n < N: n *= 2
return n
@lppier
lppier / Using PCA to represent word vectors in 2D.py
Created January 3, 2023 10:56
Using PCA to represent word vectors in 2D
from sentence_transformers import SentenceTransformer
from sklearn.cluster import KMeans
embedder = SentenceTransformer('paraphrase-multilingual-mpnet-base-v2')
#embedder = SentenceTransformer('all-MiniLM-L6-v2')
corpus = tfidf_sum.index.to_list()
corpus_embeddings = embedder.encode(corpus)
# Perform kmean clustering
num_clusters = 8
clustering_model = KMeans(n_clusters=num_clusters, random_state=42, init='k-means++')
@lppier
lppier / redis_python_dict.py
Created January 2, 2019 01:27
Redis Retrieving and Putting a Python Dictionary in Redis
import redis
import json
# Retrieve Redis Stored Values, if any for faster processing
anc_dict_320 = {}
r = redis.Redis(host='localhost', port=6379, db=0)
json_str_320 = r.get("anc_dict_320")
if json_str_320 is not None:
anc_dict_320 = json.loads(json_str_320)
print(anc_dict_320)
@lppier
lppier / add_sagemaker_kernel.sh
Created March 21, 2022 02:35
Add custom python kernel to sagemaker
conda create -n my_custom_python_39 python=3.9 -y
cd ~/SageMaker
source activate my_custom_python_39
pip install virtualenv
virtualenv my_custom_python_39_venv
conda deactivate
source my_custom_python_39_venv/bin/activate
pip install -r <your_project_folder>/requirements.txt
pip install ipykernel
python -m ipykernel install --user --name=my_custom_python_39
@lppier
lppier / gist:1548d7b93cc8d32955ea4db078af91b6
Created March 17, 2022 06:39
Use Custom Python Version in Sagemaker
conda create -n my_custom_python_39 python=3.9 -y
cd ~/SageMaker
source activate my_custom_python_39
pip install virtualenv
virtualenv my_custom_python_39_venv
conda deactivate
source my_custom_python_39_venv/bin/activate
pip install ipykernel -y
python -m ipykernel install --user --name=my_custom_python_39
@lppier
lppier / regex_cheatsheet.py
Last active December 28, 2020 10:29
regex python cheatsheet
# Remove URLs
text_clean = [re.sub(r'http\S+', '', t) for t in text]
# Remove new lines \n
text_clean= [t.strip().replace('\n', ' ') for t in text_clean]
# Remove emails
text_clean = [re.sub(r'[\w\.-]+@[\w\.-]+', '', t) for t in text_clean]
# Remove single quotes
from pathlib import Path
from sklearn.model_selection import train_test_split
# IMDB Dataset can be found here
# wget http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz
# tar -xf aclImdb_v1.tar.gz
def read_imdb_split(split_dir):
split_dir = Path(split_dir)
from pathlib import Path
from sklearn.model_selection import train_test_split
from transformers import DistilBertTokenizerFast
import torch
from transformers import DistilBertForSequenceClassification, Trainer, TrainingArguments
import torch.nn.functional as F
from sklearn.metrics import accuracy_score, precision_recall_fscore_support
# IMDB Dataset can be found here
# wget http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz
@lppier
lppier / gist:a117e2f1702b36c65350987ccf73659b
Created September 18, 2020 07:54
.vimrc file for Python highlighting (put in ~/Users/<yourname>/.vimrc
" enable syntax highlighting
syntax enable
" show line numbers
set number
" set tabs to have 4 spaces
set ts=4
" indent when moving to the next line while writing code