Home / Expert Answers / Computer Science / def-hashfeatures-baby-d-fix-debug-false-34-34-34-input-baby-a-string-representing-pa777

(Solved): def hashfeatures(baby, d, FIX, debug=False): """ Input: baby : a string representing ...



def hashfeatures(baby, d, FIX, debug=False): """ Input: baby : a string representing the baby's name to be hashed d: the number of dimensions to be in the feature vector FIX: the number of chunks to extract and hash from each string debug: a bool for printing debug values (default False) Output: v: a feature vector representing the input string """ v = np.zeros(d) for m in range(1, FIX+1): prefix = baby[:m] + ">" P = hash(prefix) % d v[P] = 1 suffix = "<" + baby[-m:] S = hash(suffix) % d v[S] = 1 if debug: print(f"Split {m}/{FIX}:\t({prefix}, {suffix}),\t1s at indices [{P}, {S}]") if debug: print(f"Feature vector for {baby}: {v.astype(int)} ") return v



We have an Answer from Expert

View Expert Answer

Expert Answer


We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe