Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added HashedDocDotFeatures in modular interfaces
- Loading branch information
Showing
6 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
examples/undocumented/python_modular/features_hasheddocdot_modular.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
strings=['hey','guys','i','am','a','string'] | ||
|
||
parameter_list=[[strings]] | ||
|
||
def features_hasheddocdot_modular(strings): | ||
from shogun.Features import StringCharFeatures, RAWBYTE | ||
from shogun.Features import HashedDocDotFeatures | ||
from shogun.Library import NGramTokenizer | ||
from numpy import array | ||
|
||
#create string features | ||
f=StringCharFeatures(strings, RAWBYTE) | ||
|
||
#set the number of bits of the target dimension | ||
#means a dim of size 2^5=32 | ||
num_bits=5 | ||
|
||
#create the ngram tokenizer of size 8 to parse the strings | ||
tokenizer=NGramTokenizer(8) | ||
|
||
#normalize results | ||
normalize=True | ||
|
||
#create HashedDocDot features | ||
hddf=HashedDocDotFeatures(num_bits, f, tokenizer, normalize) | ||
|
||
#should expect 32 | ||
#print('Feature space dimensionality is', hddf.get_dim_feature_space()) | ||
|
||
#print('Self dot product of string 0', hddf.dot(0, hddf, 0)) | ||
|
||
return hddf | ||
|
||
if __name__=='__main__': | ||
print('HashedDocDotFeatures') | ||
features_hasheddocdot_modular(*parameter_list[0]) |
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
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
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
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
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