<s>
In	O
machine	O
learning	O
,	O
feature	B-Algorithm
hashing	I-Algorithm
,	O
also	O
known	O
as	O
the	O
hashing	B-Algorithm
trick	I-Algorithm
(	O
by	O
analogy	O
to	O
the	O
kernel	B-Algorithm
trick	O
)	O
,	O
is	O
a	O
fast	O
and	O
space-efficient	O
way	O
of	O
vectorizing	O
features	B-Algorithm
,	O
i.e.	O
</s>
<s>
turning	O
arbitrary	O
features	B-Algorithm
into	O
indices	O
in	O
a	O
vector	O
or	O
matrix	O
.	O
</s>
<s>
It	O
works	O
by	O
applying	O
a	O
hash	B-Error_Name
function	I-Error_Name
to	O
the	O
features	B-Algorithm
and	O
using	O
their	O
hash	B-Error_Name
values	I-Error_Name
as	O
indices	O
directly	O
,	O
rather	O
than	O
looking	O
the	O
indices	O
up	O
in	O
an	O
associative	B-Application
array	I-Application
.	O
</s>
<s>
In	O
a	O
typical	O
document	B-Algorithm
classification	I-Algorithm
task	O
,	O
the	O
input	O
to	O
the	O
machine	O
learning	O
algorithm	O
(	O
both	O
during	O
learning	O
and	O
classification	O
)	O
is	O
free	O
text	O
.	O
</s>
<s>
From	O
this	O
,	O
a	O
bag	B-General_Concept
of	I-General_Concept
words	I-General_Concept
(	O
BOW	O
)	O
representation	O
is	O
constructed	O
:	O
the	O
individual	O
tokens	O
are	O
extracted	O
and	O
counted	O
,	O
and	O
each	O
distinct	O
token	O
in	O
the	O
training	O
set	O
defines	O
a	O
feature	B-Algorithm
(	O
independent	O
variable	O
)	O
of	O
each	O
of	O
the	O
documents	O
in	O
both	O
the	O
training	O
and	O
test	O
sets	O
.	O
</s>
<s>
Therefore	O
,	O
the	O
bags	B-General_Concept
of	I-General_Concept
words	I-General_Concept
for	O
a	O
set	O
of	O
documents	O
is	O
regarded	O
as	O
a	O
term-document	B-General_Concept
matrix	I-General_Concept
where	O
each	O
row	O
is	O
a	O
single	O
document	O
,	O
and	O
each	O
column	O
is	O
a	O
single	O
feature/word	O
;	O
the	O
entry	O
in	O
such	O
a	O
matrix	O
captures	O
the	O
frequency	O
(	O
or	O
weight	O
)	O
of	O
the	O
'	O
th	O
term	O
of	O
the	O
vocabulary	O
in	O
document	O
.	O
</s>
<s>
Typically	O
,	O
these	O
vectors	O
are	O
extremely	O
sparse	B-Algorithm
—	O
according	O
to	O
Zipf	O
's	O
law	O
.	O
</s>
<s>
The	O
common	O
approach	O
is	O
to	O
construct	O
,	O
at	O
learning	O
time	O
or	O
prior	O
to	O
that	O
,	O
a	O
dictionary	B-Application
representation	O
of	O
the	O
vocabulary	O
of	O
the	O
training	O
set	O
,	O
and	O
use	O
that	O
to	O
map	O
words	O
to	O
indices	O
.	O
</s>
<s>
Hash	B-Algorithm
tables	I-Algorithm
and	O
tries	B-General_Concept
are	O
common	O
candidates	O
for	O
dictionary	B-Application
implementation	O
.	O
</s>
<s>
(	O
Punctuation	O
was	O
removed	O
,	O
as	O
is	O
usual	O
in	O
document	B-Algorithm
classification	I-Algorithm
and	O
clustering	O
.	O
)	O
</s>
<s>
The	O
problem	O
with	O
this	O
process	O
is	O
that	O
such	O
dictionaries	B-Application
take	O
up	O
a	O
large	O
amount	O
of	O
storage	O
space	O
and	O
grow	O
in	O
size	O
as	O
the	O
training	O
set	O
grows	O
.	O
</s>
<s>
Research	O
attempted	O
to	O
use	O
feature	B-Algorithm
hashing	I-Algorithm
for	O
their	O
spam	O
filters	O
.	O
</s>
<s>
Note	O
that	O
the	O
hashing	B-Algorithm
trick	I-Algorithm
is	O
n't	O
limited	O
to	O
text	B-Algorithm
classification	I-Algorithm
and	O
similar	O
tasks	O
at	O
the	O
document	O
level	O
,	O
but	O
can	O
be	O
applied	O
to	O
any	O
problem	O
that	O
involves	O
large	O
(	O
perhaps	O
unbounded	O
)	O
numbers	O
of	O
features	B-Algorithm
.	O
</s>
<s>
Most	O
neural	O
networks	O
can	O
only	O
operate	O
on	O
real	O
vector	O
inputs	O
,	O
so	O
we	O
must	O
construct	O
a	O
"	O
dictionary	B-Application
"	O
function	O
.	O
</s>
<s>
At	O
this	O
point	O
,	O
we	O
have	O
just	O
specified	O
that	O
should	O
be	O
a	O
hashing	B-Error_Name
function	I-Error_Name
.	O
</s>
<s>
Thus	O
,	O
ineluctably	O
,	O
we	O
reach	O
the	O
idea	O
of	O
feature	B-Algorithm
hashing	I-Algorithm
.	O
</s>
<s>
The	O
basic	O
feature	B-Algorithm
hashing	I-Algorithm
algorithm	O
presented	O
in	O
(	O
Weinberger	O
et	O
al	O
.	O
</s>
<s>
First	O
,	O
one	O
specifies	O
two	O
hash	B-Error_Name
functions	I-Error_Name
:	O
the	O
kernel	B-Algorithm
hash	B-Error_Name
,	O
and	O
the	O
sign	O
hash	B-Error_Name
.	O
</s>
<s>
Next	O
,	O
one	O
defines	O
the	O
feature	B-Algorithm
hashing	I-Algorithm
function:Finally	O
,	O
extend	O
this	O
feature	B-Algorithm
hashing	I-Algorithm
function	O
to	O
strings	O
of	O
tokens	O
bywhere	O
is	O
the	O
set	O
of	O
all	O
finite	O
strings	O
consisting	O
of	O
tokens	O
in	O
.	O
</s>
<s>
Now	O
we	O
have	O
an	O
inner	O
product	O
space	O
,	O
with	O
enough	O
structure	O
to	O
describe	O
the	O
geometry	O
of	O
the	O
feature	B-Algorithm
hashing	I-Algorithm
function	O
.	O
</s>
<s>
First	O
,	O
we	O
can	O
see	O
why	O
is	O
called	O
a	O
"	O
kernel	B-Algorithm
hash	B-Error_Name
"	O
:	O
it	O
allows	O
us	O
to	O
define	O
a	O
kernel	B-Algorithm
byIn	O
the	O
language	O
of	O
the	O
"	O
kernel	B-Algorithm
trick	O
"	O
,	O
is	O
the	O
kernel	B-Algorithm
generated	O
by	O
the	O
"	O
feature	B-Algorithm
map	O
"	O
Note	O
that	O
this	O
is	O
not	O
the	O
feature	B-Algorithm
map	O
we	O
were	O
using	O
,	O
which	O
is	O
.	O
</s>
<s>
In	O
fact	O
,	O
we	O
have	O
been	O
using	O
another	O
kernel	B-Algorithm
,	O
defined	O
by	O
The	O
benefit	O
of	O
augmenting	O
the	O
kernel	B-Algorithm
hash	B-Error_Name
with	O
the	O
binary	O
hash	B-Error_Name
is	O
the	O
following	O
theorem	O
,	O
which	O
states	O
that	O
is	O
an	O
isometry	O
"	O
on	O
average	O
"	O
.	O
</s>
<s>
The	O
above	O
statement	O
and	O
proof	O
interprets	O
the	O
binary	O
hash	B-Error_Name
function	I-Error_Name
not	O
as	O
a	O
deterministic	O
function	O
of	O
type	O
,	O
but	O
as	O
a	O
random	O
binary	O
vector	O
with	O
unbiased	O
entries	O
,	O
meaning	O
that	O
for	O
any	O
.	O
</s>
<s>
Instead	O
of	O
maintaining	O
a	O
dictionary	B-Application
,	O
a	O
feature	B-Algorithm
vectorizer	O
that	O
uses	O
the	O
hashing	B-Algorithm
trick	I-Algorithm
can	O
build	O
a	O
vector	O
of	O
a	O
pre-defined	O
length	O
by	O
applying	O
a	O
hash	B-Error_Name
function	I-Error_Name
to	O
the	O
features	B-Algorithm
(	O
e.g.	O
,	O
words	O
)	O
,	O
then	O
using	O
the	O
hash	B-Error_Name
values	I-Error_Name
directly	O
as	O
feature	B-Algorithm
indices	O
and	O
updating	O
the	O
resulting	O
vector	O
at	O
those	O
indices	O
.	O
</s>
<s>
Here	O
,	O
we	O
assume	O
that	O
feature	B-Algorithm
actually	O
means	O
feature	B-Algorithm
vector	I-Algorithm
.	O
</s>
<s>
Thus	O
,	O
if	O
our	O
feature	B-Algorithm
vector	I-Algorithm
is	O
 [ "cat" , "dog" , "cat" ] 	O
and	O
hash	B-Error_Name
function	I-Error_Name
is	O
if	O
is	O
"	O
cat	O
"	O
and	O
if	O
is	O
"	O
dog	O
"	O
.	O
</s>
<s>
Let	O
us	O
take	O
the	O
output	O
feature	B-Algorithm
vector	I-Algorithm
dimension	O
(	O
)	O
to	O
be	O
4	O
.	O
</s>
<s>
It	O
has	O
been	O
suggested	O
that	O
a	O
second	O
,	O
single-bit	O
output	O
hash	B-Error_Name
function	I-Error_Name
be	O
used	O
to	O
determine	O
the	O
sign	O
of	O
the	O
update	O
value	O
,	O
to	O
counter	O
the	O
effect	O
of	O
hash	B-Error_Name
collisions	O
.	O
</s>
<s>
An	O
optimized	O
version	O
would	O
instead	O
only	O
generate	O
a	O
stream	O
of	O
pairs	O
and	O
let	O
the	O
learning	O
and	O
prediction	O
algorithms	O
consume	O
such	O
streams	O
;	O
a	O
linear	B-Algorithm
model	I-Algorithm
can	O
then	O
be	O
implemented	O
as	O
a	O
single	O
hash	B-Algorithm
table	I-Algorithm
representing	O
the	O
coefficient	O
vector	O
.	O
</s>
<s>
Feature	B-Algorithm
hashing	I-Algorithm
generally	O
suffers	O
from	O
hash	B-Error_Name
collision	O
,	O
which	O
means	O
that	O
there	O
exist	O
pairs	O
of	O
different	O
tokens	O
with	O
the	O
same	O
hash	B-Error_Name
:	O
.	O
</s>
<s>
A	O
machine	O
learning	O
model	O
trained	O
on	O
feature-hashed	O
words	O
would	O
then	O
have	O
difficulty	O
distinguishing	O
and	O
,	O
essentially	O
because	O
is	O
polysemic	O
.	O
</s>
<s>
To	O
handle	O
this	O
,	O
one	O
can	O
train	O
supervised	O
hashing	B-Error_Name
functions	I-Error_Name
that	O
avoids	O
mapping	O
common	O
tokens	O
to	O
the	O
same	O
feature	B-Algorithm
vectors	I-Algorithm
.	O
</s>
<s>
Ganchev	O
and	O
Dredze	O
showed	O
that	O
in	O
text	B-Algorithm
classification	I-Algorithm
applications	O
with	O
random	O
hash	B-Error_Name
functions	I-Error_Name
and	O
several	O
tens	O
of	O
thousands	O
of	O
columns	O
in	O
the	O
output	O
vectors	O
,	O
feature	B-Algorithm
hashing	I-Algorithm
need	O
not	O
have	O
an	O
adverse	O
effect	O
on	O
classification	O
performance	O
,	O
even	O
without	O
the	O
signed	O
hash	B-Error_Name
function	I-Error_Name
.	O
</s>
<s>
(	O
2009	O
)	O
applied	O
their	O
version	O
of	O
feature	B-Algorithm
hashing	I-Algorithm
to	O
multi-task	B-General_Concept
learning	I-General_Concept
,	O
and	O
in	O
particular	O
,	O
spam	O
filtering	O
,	O
where	O
the	O
input	O
features	B-Algorithm
are	O
pairs	O
(	O
user	O
,	O
feature	B-Algorithm
)	O
so	O
that	O
a	O
single	O
parameter	O
vector	O
captured	O
per-user	O
spam	O
filters	O
as	O
well	O
as	O
a	O
global	O
filter	O
for	O
several	O
hundred	O
thousand	O
users	O
,	O
and	O
found	O
that	O
the	O
accuracy	O
of	O
the	O
filter	O
went	O
up	O
.	O
</s>
<s>
(	O
2015	O
)	O
combined	O
the	O
idea	O
of	O
feature	B-Algorithm
hashing	I-Algorithm
and	O
sparse	B-Algorithm
matrix	I-Algorithm
to	O
construct	O
"	O
virtual	O
matrices	O
"	O
:	O
large	O
matrices	O
with	O
small	O
storage	O
requirements	O
.	O
</s>
<s>
The	O
idea	O
is	O
to	O
treat	O
a	O
matrix	O
as	O
a	O
dictionary	B-Application
,	O
with	O
keys	O
in	O
,	O
and	O
values	O
in	O
.	O
</s>
<s>
Then	O
,	O
as	O
usual	O
in	O
hashed	O
dictionaries	B-Application
,	O
one	O
can	O
use	O
a	O
hash	B-Error_Name
function	I-Error_Name
,	O
and	O
thus	O
represent	O
a	O
matrix	O
as	O
a	O
vector	O
in	O
,	O
no	O
matter	O
how	O
big	O
is	O
.	O
</s>
<s>
Implementations	O
of	O
the	O
hashing	B-Algorithm
trick	I-Algorithm
are	O
present	O
in	O
:	O
</s>
