How does Feature Hashing work? (For ANN Input)

  • 3 Replies
  • 2034 Views
*

JohnnyWaffles

  • Roomba
  • *
  • 14
How does Feature Hashing work? (For ANN Input)
« on: January 09, 2019, 06:48:23 pm »
I've built a feed forward neural network in Excel using VBA specifically for classification. I'm using this neural network at my place of work. It's the only programming language I have access too there. I'm trying to prep my data for NN input. I've tried using One Hot Encoding and Binary Encoding to encode my data, but I have over 100 categories and I usually end up with a memory error. Does anybody know how to do Feature Hashing? Apparently its the next best way to prep categorical data for NN input.

Online examples that I have seen don't explain it well. Can anyone here explain how it works?

*

Korrelan

  • Trusty Member
  • ***********
  • Eve
  • *
  • 1454
  • Look into my eyes! WOAH!
    • YouTube
Re: How does Feature Hashing work? (For ANN Input)
« Reply #1 on: January 10, 2019, 11:17:36 am »
Not really my area but…

A binary representation of a sentence is created using a ‘bag of words’ BOW, the location/ index of the words within the BOW dictionary is used to create a long binary feature matrix.  Depending on the size of your dictionary this can obviously lead to very long matrixes, so a small 10k word BOW gives a 10k string of 1’s & 0’s… ouch lol.

A method of data compression is to first pre-process you sentences extracting features, or regular combinations of words to create a ‘bag of features’ and then encode the binary feature matrix from this. 

Both these methods have the disadvantage that as new words are encountered the dictionary length changes, and the whole NN needs re-training on the new feature set.

To avoid this problem…another method that does not require a dictionary is feature hashing.

A hashing algorithm converts data of arbitrary length/ type into a unique (ish) numerical representation within a know range. (MURMURHASH3)

So in chatbots for example… long complex input sentences don’t have to be stored in their entirety… they can be hashed and just the unique result/ number stored.  The hash algorithm will always convert the same sentence to the same hash output for searching/ matching etc.

Using the inbuilt windows shlwapi.dll hashing routines gives…

Hash(“this whole sentence will be converted into a single unique number”) = 166579926

So the idea is to transform/ compress any given sentence/ data into a unique/ repeatable binary sequence/ vector of a fixed known length, because hashing algorithm always returns a number within a set range, the length of the resulting binary vector is always fixed.

To do this each word is passed through a hash algorithm, and a 1 is placed within the binary array element/ index derived from the hash output NOT the words location within the BOW.  This gives a unique sparse binary vector ready to send to the NN, but again depending on the hashing algorithm used can result in some long vectors/ binaries.

A variation on this is the hashing trick, to use the MOD function on the hash output and place a 1 at the array index of the MOD’s remainder result.

https://docs.microsoft.com/en-us/azure/machine-learning/studio-module-reference/feature-hashing

https://medium.com/value-stream-design/introducing-one-of-the-best-hacks-in-machine-learning-the-hashing-trick-bf6a9c8af18f

https://en.wikipedia.org/wiki/Vowpal_Wabbit

 :)
« Last Edit: January 10, 2019, 01:42:19 pm by Korrelan »
It thunk... therefore it is!...    /    Project Page    /    KorrTecx Website

*

JohnnyWaffles

  • Roomba
  • *
  • 14
Re: How does Feature Hashing work? (For ANN Input)
« Reply #2 on: March 28, 2019, 03:27:41 pm »
Hey, sorry it’s been a while since I have a had a chance to come back to this. Thank you however for the informative post.

I do not understand how to do the hashing trick though. If I can provide some examples of the data I’m working with, do you think you could help me understand how to apply the hashing trick?

I’m using data from an engineering system. In this case, I have attributes of piping components.

For example, the material of a component is one attribute I’d consider using. I’m using the following VBA code to produce a hash sequence:
https://stackoverflow.com/questions/7358955/generate-short-hash-string-based-using-vba/7359753#7359753

CATEGORY:    HASH SEQUENCE:
Steel                                        37152
Plastic                                31081
Aluminum                        2310
Bronze                                9364

So with this small dataset, how would I proceed to use the hashing trick?

*

goaty

  • Trusty Member
  • ********
  • Replicant
  • *
  • 552
Re: How does Feature Hashing work? (For ANN Input)
« Reply #3 on: March 29, 2019, 07:06:49 am »
not really answering your question but...
hashing isn't that good, because they cant be near matched,   you need descriptive factors you can near match between is better.
« Last Edit: March 29, 2019, 07:40:53 am by goaty »

 


Requirements for functional equivalence to conscious processing?
by DaltonG (General AI Discussion)
November 19, 2024, 11:56:05 am
Will LLMs ever learn what is ... is?
by HS (Future of AI)
November 10, 2024, 06:28:10 pm
Who's the AI?
by frankinstien (Future of AI)
November 04, 2024, 05:45:05 am
Project Acuitas
by WriterOfMinds (General Project Discussion)
October 27, 2024, 09:17:10 pm
Ai improving AI
by infurl (AI Programming)
October 19, 2024, 03:43:29 am
Atronach's Eye
by WriterOfMinds (Home Made Robots)
October 13, 2024, 09:52:42 pm
Running local AI models
by spydaz (AI Programming)
October 07, 2024, 09:00:53 am
Hi IM BAA---AAACK!!
by MagnusWootton (Home Made Robots)
September 16, 2024, 09:49:10 pm
LLaMA2 Meta's chatbot released
by spydaz (AI News )
August 24, 2024, 02:58:36 pm
ollama and llama3
by spydaz (AI News )
August 24, 2024, 02:55:13 pm
AI controlled F-16, for real!
by frankinstien (AI News )
June 15, 2024, 05:40:28 am
Open AI GPT-4o - audio, vision, text combined reasoning
by MikeB (AI News )
May 14, 2024, 05:46:48 am
OpenAI Speech-to-Speech Reasoning Demo
by MikeB (AI News )
March 31, 2024, 01:00:53 pm
Say good-bye to GPUs...
by MikeB (AI News )
March 23, 2024, 09:23:52 am
Google Bard report
by ivan.moony (AI News )
February 14, 2024, 04:42:23 pm
Elon Musk's xAI Grok Chatbot
by MikeB (AI News )
December 11, 2023, 06:26:33 am

Users Online

284 Guests, 0 Users

Most Online Today: 532. Most Online Ever: 2369 (November 21, 2020, 04:08:13 pm)

Articles