Skip to content

Instantly share code, notes, and snippets.

View shahbazsyed's full-sized avatar

Shahbaz Syed shahbazsyed

View GitHub Profile
@shahbazsyed
shahbazsyed / seq2seq_attention_model.py
Created March 9, 2017 11:03
An overview of sequence2sequence model with attention
## Parameters
batch_sze = 4
enc_layers = 4
enc_timesteps = 120
dec_timesteps = 30
min_lr=0.01, # min learning rate.
lr=0.15, # learning rate
min_input_len = 2
num_hidden = 256
@shahbazsyed
shahbazsyed / callApplyBind.js
Created April 25, 2017 08:16
JS call, apply ,bind
// Consider an object having a num property
var obj = {num:2};
// Note the use of this in the function
var addToThis = function(a,b,c){
return this.num + a+b+c;
};
// call is used to call a function on an object with the arguments passed along
var result = addToThis.call(obj,4,3,4); // functioname.call(object_to_be_called, arguments_to_function)
@shahbazsyed
shahbazsyed / closure.js
Last active April 25, 2017 08:50
Closure
var addTo = function(passed){
var inner=2;
return passed+inner;
};
console.log(addTo(3)); // 5
@shahbazsyed
shahbazsyed / oop.js
Created April 25, 2017 08:28
Basic OOP in Js
var x = new Object(); // empty object in js
var y= {} ; // another way of creating empty object
// Adding properties to our empty object
y.name="Tim";
y.age=20;
y.getName= function(){
return this.name;
};
@shahbazsyed
shahbazsyed / prototypeInheritance.js
Created April 25, 2017 08:36
Inherting from Prototype in Js
/*
This gist covers creating a subclass from a baseclas, overriding in the prototype chain, and adding properties
to the master Object prototype
*/
// baseclass
var Job = function() {
this.pays = true;
};
@shahbazsyed
shahbazsyed / reduce.js
Created April 25, 2017 08:55
Functional programming in Js - Reduce
Array.prototype.reduce = function(combiner, initialValue) {
var counter, accumulatedValue;
// If the array to be reduced is empty, then do nothing
if (this.length === 0) {
return this; //this refers to the Array being reduced
} else {
/*
If the user did not pass an initialValue, that is if the number of arguments passed to the reduce function is just 1,
then use the first item from the array as the accumulatedValue to begin with
@shahbazsyed
shahbazsyed / map.js
Created April 25, 2017 08:57
Functional programming in Js - Map
Array.prototype.map = function(projectionFunction) {
var results = [];
this.forEach(function(itemInArray) {
/*
projectionFunction is applied to each element of the array, which returns the modified value of that element
*/
results.push(projectionFunction(itemInArray));
});
POS tag list:
CC coordinating conjunction
CD cardinal digit
DT determiner
EX existential there (like: "there is" ... think of it like "there exists")
FW foreign word
IN preposition/subordinating conjunction
JJ adjective 'big'
JJR adjective, comparative 'bigger'
@shahbazsyed
shahbazsyed / word2vec_tf_idf_from_wikipeida.py
Created October 30, 2017 14:20 — forked from maxbellec/word2vec_tf_idf_from_wikipeida.py
Create Word2Vec from wikipedia with gensim
import multiprocessing
from gensim.corpora.wikicorpus import WikiCorpus
from gensim.models.word2vec import Word2Vec
from gensim.models import TfidfModel
# logging is important to get the state of the functions
import logging
logging.basicConfig(format='%(asctime)s: %(levelname)s: %(message)s')
logging.root.setLevel(level=logging.INFO)
@shahbazsyed
shahbazsyed / parallel.py
Created June 3, 2019 13:18 — forked from thomwolf/parallel.py
Data Parallelism in PyTorch for modules and losses
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
## Created by: Hang Zhang, Rutgers University, Email: zhang.hang@rutgers.edu
## Modified by Thomas Wolf, HuggingFace Inc., Email: thomas@huggingface.co
## Copyright (c) 2017-2018
##
## This source code is licensed under the MIT-style license found in the
## LICENSE file in the root directory of this source tree
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"""Encoding Data Parallel"""