This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # (C) Mathieu Blondel, November 2013 | |
| # License: BSD 3 clause | |
| import numpy as np | |
| def ranking_precision_score(y_true, y_score, k=10): | |
| """Precision at rank k | |
| Parameters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Information Retrieval metrics | |
| Useful Resources: | |
| http://www.cs.utexas.edu/~mooney/ir-course/slides/Evaluation.ppt | |
| http://www.nii.ac.jp/TechReports/05-014E.pdf | |
| http://www.stanford.edu/class/cs276/handouts/EvaluationNew-handout-6-per.pdf | |
| http://hal.archives-ouvertes.fr/docs/00/72/67/60/PDF/07-busa-fekete.pdf | |
| Learning to Rank for Information Retrieval (Tie-Yan Liu) | |
| """ | |
| import numpy as np |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| import json | |
| import math | |
| import random | |
| import fileinput | |
| import collections | |
| class LDASampler(object): | |
| def __init__(self, docs=None, num_topics=None, alpha=0.1, beta=0.1, state=None): | |
| if state: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import sys | |
| #from numpy import array, diag, zeros, ones_like, identity, amax, maximum, amin, minimum, loadtxt, kron, ones, reshape | |
| import numpy as np | |
| from numpy.random import rand | |
| #from matplotlib.pyplot import * | |
| from optparse import OptionParser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 利用python的正则去解决 | |
| import re | |
| def remove_url(txt): | |
| regex =re.compile(r'https://[a-zA-Z0-9.?/&=:]*',re.S) | |
| return regex.sub("",txt) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import string | |
| import re | |
| from nltk.corpus import stopwords | |
| from nltk.tokenize import TweetTokenizer | |
| cache_english_stopwords=stopwords.words('english') | |
| def tweet_clean(tweet): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import nltk | |
| text = """The Buddha, the Godhead, resides quite as comfortably in the circuits of a digital | |
| computer or the gears of a cycle transmission as he does at the top of a mountain | |
| or in the petals of a flower. To think otherwise is to demean the Buddha...which is | |
| to demean oneself.""" | |
| # Used when tokenizing words | |
| sentence_re = r'''(?x) # set flag to allow verbose regexps | |
| ([A-Z])(\.[A-Z])+\.? # abbreviations, e.g. U.S.A. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def convex_hull_graham(points): | |
| ''' | |
| Returns points on convex hull in CCW order according to Graham's scan algorithm. | |
| By Tom Switzer <thomas.switzer@gmail.com>. | |
| ''' | |
| TURN_LEFT, TURN_RIGHT, TURN_NONE = (1, -1, 0) | |
| def cmp(a, b): | |
| return (a > b) - (a < b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import threading | |
| # folk from https://gist.github.com/werediver/4396488 | |
| # Based on tornado.ioloop.IOLoop.instance() approach. | |
| # See https://github.com/facebook/tornado | |
| class SingletonMixin(object): | |
| __singleton_lock = threading.Lock() | |
| __singleton_instance = None | |
| @classmethod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| class ImportGraph(): | |
| """ Importing and running isolated TF graph """ | |
| def __init__(self, loc): | |
| # Create local graph and use it in the session | |
| self.graph = tf.Graph() | |
| self.sess = tf.Session(graph=self.graph) | |
| with self.graph.as_default(): | |
| # Import saved model from location 'loc' into local graph |
OlderNewer