Skip to content

Instantly share code, notes, and snippets.

View jbencina's full-sized avatar
👋

John Bencina jbencina

👋
View GitHub Profile
@jbencina
jbencina / CSPAN-transcript-parser.py
Last active January 7, 2021 20:09
Quick (and dirty) Python script that takes the transcript information from CSPAN video pages and parses it into a JSON file with the time stamp, speaker name, and speech text. There are probably 100 more elegant ways to write this, but it works for what I needed.
from html.parser import HTMLParser
import re
import json
import datetime as dt
class Entry():
def __init__(self, time):
self.time = ''
self.time_base = time
self.speaker = ''
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jbencina
jbencina / scikit_topic_cohesion.py
Last active April 24, 2017 17:30
Scikit Topic Cohesion
def topic_coherence(lda_model, corpus, num_words, sort_topics=True, avg_per_word=False):
topics = {}
# Get the top num_words within each model in topic
for idx, topic in enumerate(lda_model.components_):
topics[idx] = [i for i in topic.argsort()[:-num_words -1: -1]]
# Convert to csc for efficient column slicing
D = corpus.tocsc()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jbencina
jbencina / backprop_tutorial.ipynb
Last active February 19, 2019 09:45
Example for running backprop in numpy
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jbencina
jbencina / plot.py
Created April 6, 2023 02:55
Interactive plot for Segment Anything Model example
%matplotlib widget # Install ipympl https://github.com/matplotlib/ipympl
import matplotlib.pyplot as plt
# Previous steps followed from example notebook at
# https://github.com/facebookresearch/segment-anything/blob/main/notebooks/onnx_model_example.ipynb
def show_mask(mask, ax):
# From SAM notebook
color = np.array([30/255, 144/255, 255/255, 0.6])
h, w = mask.shape[-2:]