Skip to content

Instantly share code, notes, and snippets.

@lievcin
Created February 6, 2018 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lievcin/c3e7986e04bdb589f8799c8446d5c489 to your computer and use it in GitHub Desktop.
Save lievcin/c3e7986e04bdb589f8799c8446d5c489 to your computer and use it in GitHub Desktop.
featureDict = {} # A global dictionary of features
def toFeatureVector(tokens):
# Should return a dictionary containing features as keys, and weights as values
v = {}
for t in tokens:
try:
featureDict[t] += 1
except KeyError:
featureDict[t] = 1
try:
v[t] += (1.0/len(tokens))
except KeyError:
v[t] = (1.0/len(tokens))
return v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment