Skip to content

Instantly share code, notes, and snippets.

View datasciencemonkey's full-sized avatar
👉
Working from home

Sathish Gangichetty datasciencemonkey

👉
Working from home
View GitHub Profile
@datasciencemonkey
datasciencemonkey / dspy-happiness.py
Last active July 12, 2024 13:47
dspy module for an LLM Pipeline
import random
from utils import get_country_data_and_corr
class WriteEssayAfterParsingUserQuery(dspy.Module):
def __init__(self):
super().__init__()
self.country = dspy.Predict(ExtractCountry)
self.essay_writer = dspy.ChainOfThought(EssayOnePass)
def forward(self, question, constraint, persona):
with dspy.settings.context(lm=qwen2): # Call QWEN2 for extracting country name
@datasciencemonkey
datasciencemonkey / qlora_gptq.py
Created October 22, 2023 23:45
Start with qlora training and then quantize to disk with gptq
# %%
from huggingface_hub import login
from dotenv import load_dotenv
load_dotenv("/notebooks/.env")
import os
os.environ["TOKENIZERS_PARALLELISM"] = "false"
login(token=os.getenv("HUGGINGFACE_TOKEN"))
@datasciencemonkey
datasciencemonkey / gptq_lora.py
Created September 13, 2023 21:57
train a gptq model using peft/lora
# %%
# this is run from /notebooks on paperspace
from huggingface_hub import login
from dotenv import load_dotenv
load_dotenv("/notebooks/.env")
import os
os.environ["TOKENIZERS_PARALLELISM"]="false"
login(token=os.getenv("HUGGINGFACE_TOKEN"))
@datasciencemonkey
datasciencemonkey / text_similarity.py
Created January 17, 2022 22:09
compute document similarity
from flair.embeddings import (
FlairEmbeddings,
TransformerWordEmbeddings,
StackedEmbeddings,
)
from flair.data import Sentence
from flair.embeddings import DocumentPoolEmbeddings
from sklearn.metrics.pairwise import cosine_similarity
# init Flair embeddings
@datasciencemonkey
datasciencemonkey / src.py
Last active March 18, 2021 15:51
open src node run py scripts and make results globally available - CAS/Viya/Model Studio
# import libraries
import os
import swat
import pandas as pd
import toml
with open('/tmp/config.toml','r') as f:
server_config = toml.load(f)
cas_settings = server_config.get('cas35')
@datasciencemonkey
datasciencemonkey / network_helper.dart
Created September 30, 2020 03:14
networkHelper to fire requests off to ESP
class NetworkHelper {
NetworkHelper(this.url);
final String url;
final Xml2Json xml2json = new Xml2Json();
Future getData() async {
print(url);
http.Response response =
await http.get(url, headers: {'Accept': 'application/json'});
@datasciencemonkey
datasciencemonkey / update_results.dart
Created September 30, 2020 03:12
update app state for the TV app
void updateUI(dynamic recommendationJSON) {
setState(() {
if (recommendationJSON == null) {
recommendationText = '';
return;
}
recommendationText =
recommendationJSON['events'][1]['event']['Recommendation'];
print(recommendationText);
});
@datasciencemonkey
datasciencemonkey / recommendation_model.dart
Created September 30, 2020 03:08
Calling ESP from TV companion app
import 'networking.dart';
import '../constants/esp_settings.dart';
const esp_rec_model_url =
'$hostname:$http_port/SASESP/events/Recommendation_Engine/cq1/Final_Recommendation';
class RecommendationModel {
Future<dynamic> getRecommendation(String id) async {
NetworkHelper networkHelper =
NetworkHelper('$esp_rec_model_url?filter=in(cust_id,$id)');