Skip to content

Instantly share code, notes, and snippets.

View Garfounkel's full-sized avatar

Garfounkel Garfounkel

View GitHub Profile
@Garfounkel
Garfounkel / parsing.sh
Last active April 25, 2024 17:01
Helper bash function to parse arguments.
#!/bin/bash
#================================================================================
# MIT License
#
# Copyright (c) 2024 Simon Andersen
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@Garfounkel
Garfounkel / -UNITY_UTILITIES.md
Last active December 13, 2020 12:28
Collection of utilities solving specific problems for Unity

Utilities for Unity

Files in this gist are things that do not exactly fit in a general utility repository because I don't use them in every single project, but they are generic enough that someone else might also want to use them in their own project.

License

You are free to use and/or sell copies of this software according to the following MIT License. Credits are not required, but greately appreciated.

MIT License

Copyright (c) 2020 Simon Andersen
@Garfounkel
Garfounkel / gpu_tfidf_demo.ipynb
Last active April 24, 2021 21:59
notebooks/gpu_tfidf_demo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Garfounkel
Garfounkel / cluster_topics.py
Last active July 8, 2020 23:50
Nvidia NLP blog clustering
import numpy as np
sorted_centroids = kmeans.cluster_centers_.argsort()[:, ::-1]
terms = cv.get_feature_names()
clusters_terms = sorted_centroids[:, :100].get()
for i, c1 in enumerate(clusters_terms):
cluster = set(c1)
@Garfounkel
Garfounkel / document_search.py
Last active July 8, 2020 23:50
Nvidia NLP blog sparsity
def document_search(text_df, query, vectorizer, tfidf_matrix, top_n=3):
query_vec = vectorizer.transform(Series([query]))
similarities = efficient_csr_cosine_similarity(query_vec, tfidf_matrix, matrix_normalized=True)
similarities = similarities.todense().reshape(-1)
best_idx = similarities.argsort()[-top_n:][::-1]
pp = cudf.DataFrame({
'text': text_df['text'].iloc[best_idx],
'similarity': similarities[best_idx]
})
@Garfounkel
Garfounkel / ProgressBarDecorator.py
Last active March 15, 2024 16:31
A python decorator that prints a progress bar when a decored function yields it's current progress.
import time
import sys
class ProgressBarPrinter:
def __init__(self, width, step, stream, fname):
self.width = width
self.block_progress = 0
self.current_progress = 0
self.start_time = time.time()