Skip to content

Instantly share code, notes, and snippets.

View iamaziz's full-sized avatar
🎲

Aziz Alto iamaziz

🎲
View GitHub Profile
@iamaziz
iamaziz / word2vec-accuracy.py
Last active January 29, 2021 21:21
Computing the accuracy of a word2vec model (used GoogleNews-vectors-negative300.bin as an example).
from gensim.models import Word2Vec
# read the evaluation file, get it at:
# https://word2vec.googlecode.com/svn/trunk/questions-words.txt
>>> questions = 'questions-words.txt'
>>> evals = open(questions, 'r').readlines()
>>> num_sections = len([l for l in evals if l.startswith(':')])
>>> print('total evaluation sentences: {} '.format(len(evals) - num_sections))
total evaluation sentences: 19544
@iamaziz
iamaziz / mlp-mini.py
Last active November 8, 2017 17:09
Multi-Layer Perceptron in Theano (minimal example)
>>> # Multi-layer perceptron in Theano see: http://ir.hit.edu.cn/~jguo/docs/notes/a_simple_tutorial_on_theano.pdf
>>> import numpy
>>> import theano
>>> import theano.tensor as T
>>> rng = numpy.random
>>> N = 400
>>> feats = 784
>>> D = (rng.randn(N, feats), rng.randint(size=N, low=0,high=2) )
>>> training_steps = 10000
>>> x = T.matrix('x')
@iamaziz
iamaziz / gensim-to-docset.py
Created July 17, 2016 03:21
generate gensim docset
# generate gensim docset
# http://radimrehurek.com/gensim/
#----------------------------------
# built-in packages
import sqlite3
import os
import urllib
import plistlib
@iamaziz
iamaziz / linear-regerssion-gradient-descent.ipynb
Created September 16, 2016 09:05
Simple Linear Regression using Gradient Descent algorithm (plain Python no lib required)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@iamaziz
iamaziz / create-notebooks-app.sh
Last active March 21, 2019 16:13
CREATING NOTEBOOKS App (for IPYTHON/JUPYTER/JUPYTERLAB) USING NATIVEFIER
# CREATING A DEDICATED NOTEBOOKS App (for IPYTHON/JUPYTER/JUPYTERLAB) INSTEAD OF THE BROWSER
# Fri Sep 30 02:56:42 EDT 2016
# Oftentimes I get lost when I open Python notebooks in the same browser I use to surf the web.
# Specially when the tabs start cluttering and growing exponentially with every wild click on every tempting link.
# So I wanted to find a way where I can open my notebooks away from the browser's mess.
# I tried Pineapple.app (https://nwhitehead.github.io/pineapple/), it's cool. Specially when it comes to opening a notebook instantly just by clicking on its .ipynb file just like any other file. The problem is that Pineapple is not maintained and lack some features.
@iamaziz
iamaziz / github-repo-stars.py
Last active December 29, 2020 20:09
Scrape the stars count of a GitHub repo (beautifulSoup)
from bs4 import BeautifulSoup as bs
import requests
def stars_count(url):
html = requests.get(url).text
soup = bs(html, 'lxml')
stars_class = "social-count js-social-count"
stars = soup.find('a', class_=stars_class).text.strip()
return stars
@iamaziz
iamaziz / weather.html
Last active December 3, 2022 12:11
Open Weather Map API.
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<title>Weather API</title>
<!-- to be in a script.js -->
<script type="text/javascript">
@iamaziz
iamaziz / list.py
Last active July 16, 2017 02:48
naive implementation for list data structure (int type)
"""
Create a data structure that mimics Python's list.
IDEA: convert each element to a base representation with a fixed size (byte / binary / octal / hexadecimal ... etc)
then, concat elements as a string.
Based on meetup: https://www.meetup.com/Deep-Dive-into-Python-Know-Thy-Interpreter/events/238587475/
"""
class List(object):
@iamaziz
iamaziz / xor.ipynb
Created June 2, 2017 18:46
learning XOR
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.