Skip to content

Instantly share code, notes, and snippets.

View centroid_initialization.py
from math import sqrt, floor
import numpy as np
def random(ds, k, random_state=42):
"""
Create random cluster centroids.
Parameters
----------
View better_text_summarization.py
from collections import Counter
from string import punctuation
from sklearn.feature_extraction.stop_words import ENGLISH_STOP_WORDS as stop_words
import spacy
def count_words(tokens):
word_counts = {}
for token in tokens:
if token not in stop_words and token not in punctuation and token is not '\n':
if token not in word_counts.keys():
View vocabulary.py
class Vocabulary:
PAD_token = 0 # Used for padding short sentences
SOS_token = 1 # Start-of-sentence token
EOS_token = 2 # End-of-sentence token
def __init__(self, name):
self.name = name
self.word2index = {}
self.word2count = {}
self.index2word = {PAD_token: "PAD", SOS_token: "SOS", EOS_token: "EOS"}
View toy-speech-recognition.py
import os
import speech_recognition as sr
from pydub import AudioSegment
from pydub.playback import play
from gtts import gTTS as tts
def speak(text):
View ahmed-gad-ga.py
import numpy
import GA
"""
The y=target is to maximize this equation ASAP:
View keras-template.py
from keras import models
from keras.layers import Dense, Dropout
from keras.utils import to_categorical
from keras.datasets import mnist
from keras.utils.vis_utils import model_to_dot
from IPython.display import SVG
import livelossplot
plot_losses = livelossplot.PlotLossesKeras()
View time-series-garch.r
#Install the Ecdat package
install.packages("Ecdat")
#Loading the library and the Garch dataset
library(Ecdat)
mydata=Garch
#Look at the dataset
str(mydata)
#Correct the data types of date and day
#Correcting date fixes it to some arbitrary date such that the trend is same but the mapping is different
View text_data_preprocessing_6.py
def stem_and_lemmatize(words):
stems = stem_words(words)
lemmas = lemmatize_verbs(words)
return stems, lemmas
stems, lemmas = stem_and_lemmatize(words)
print('Stemmed:\n', stems)
print('\nLemmatized:\n', lemmas)
View sample_text_2.py
sample = """Title Goes Here
Bolded Text
Italicized Text
But this will still be here!
I run. He ran. She is running. Will they stop running?
I talked. She was talking. They talked to them about running. Who ran to the talking runner?
View sample_text.py
sample = """<h1>Title Goes Here</h1>
<b>Bolded Text</b>
<i>Italicized Text</i>
<img src="this should all be gone"/>
<a href="this will be gone, too">But this will still be here!</a>
I run. He ran. She is running. Will they stop running?