Created
February 6, 2018 12:06
-
-
Save lievcin/c3e7986e04bdb589f8799c8446d5c489 to your computer and use it in GitHub Desktop.
This file contains 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
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