Download pptx - Recommendation Techn

Transcript
Page 1: Recommendation Techn

© 2014 MapR Technologies 1© 2014 MapR Technologies

Practical Machine Learning:

Innovations in Recommendation

Ted Dunning

22 June 2014 Big Data Everywhere Conference Tel Aviv

Page 2: Recommendation Techn

© 2014 MapR Technologies 2

Who I am

Ted Dunning, Chief Applications Architect, MapR Technologies

Email [email protected] [email protected]

Twitter @Ted_Dunning

Apache Mahout https://mahout.apache.org/

Twitter @ApacheMahout

22 June 2014 Big Data Everywhere Conference #DataIsrael

Page 3: Recommendation Techn

© 2014 MapR Technologies 3

http://www.wired.com/wiredenterprise/2012/12/mahout/

Recommendation: Widely Used Machine Learning

Example: Open source Apache Mahout used in production

Page 4: Recommendation Techn

© 2014 MapR Technologies 4

Recommendations

– Data: interactions between people taking action (users) and items • Data used to train recommendation model

– Goal is to suggest additional interactions– Example applications: movie, music or map-based restaurant choices;

suggesting sale items for e-stores or via cash-register receipts

Page 5: Recommendation Techn

© 2014 MapR Technologies 5

Google maps: restaurant recommendations

Page 6: Recommendation Techn

© 2014 MapR Technologies 6

Google maps: tech recommendations

Page 7: Recommendation Techn

© 2014 MapR Technologies 7

Tutorial Part 1:How recommendation works,or “I want a pony”…

Page 8: Recommendation Techn

© 2014 MapR Technologies 9

First question:Are you using the right data?

Page 9: Recommendation Techn

© 2014 MapR Technologies 10

Recommendation

Behavior of a crowd helps us understand what individuals will do

Page 10: Recommendation Techn

© 2014 MapR Technologies 11

Recommendations

Alice got an apple and a puppyAlice

Page 11: Recommendation Techn

© 2014 MapR Technologies 12

Recommendations

Alice got an apple and a puppyAlice

Charles got a bicycleCharles

Page 12: Recommendation Techn

© 2014 MapR Technologies 13

Recommendations

Alice got an apple and a puppyAlice

Charles got a bicycleCharles

Bob Bob got an apple

Page 13: Recommendation Techn

© 2014 MapR Technologies 14

Recommendations

Alice got an apple and a puppyAlice

Charles got a bicycleCharles

Bob What else would Bob like?

Page 14: Recommendation Techn

© 2014 MapR Technologies 15

Recommendations

Alice got an apple and a puppyAlice

Charles got a bicycleCharles

Bob A puppy!

Page 15: Recommendation Techn

© 2014 MapR Technologies 16

You get the idea of how recommenders can work…

Page 16: Recommendation Techn

© 2014 MapR Technologies 17

By the way, like me, Bob also wants a pony…

Page 17: Recommendation Techn

© 2014 MapR Technologies 18

Recommendations

?

Alice

Bob

Charles

Amelia

What if everybody gets a pony?

What else would you recommend for new user Amelia?

Page 18: Recommendation Techn

© 2014 MapR Technologies 19

Recommendations

?

Alice

Bob

Charles

Amelia

If everybody gets a pony, it’s not a very good indicator of what to else predict...

Page 19: Recommendation Techn

© 2014 MapR Technologies 20

Problems with Raw Co-occurrence

• Very popular items co-occur with everything or why it’s not very helpful to know that everybody wants a pony… – Examples: Welcome document; Elevator music

• Very widespread occurrence is not interesting to generate indicators for recommendation– Unless you want to offer an item that is constantly desired, such as

razor blades (or ponies)• What we want is anomalous co-occurrence

– This is the source of interesting indicators of preference on which to base recommendation

Page 20: Recommendation Techn

© 2014 MapR Technologies 21

Overview: Get Useful Indicators from Behaviors

1. Use log files to build history matrix of users x items– Remember: this history of interactions will be sparse compared to all

potential combinations

2. Transform to a co-occurrence matrix of items x items

3. Look for useful indicators by identifying anomalous co-occurrences to make an indicator matrix– Log Likelihood Ratio (LLR) can be helpful to judge which co-

occurrences can with confidence be used as indicators of preference– ItemSimilarityJob in Apache Mahout uses LLR

Page 21: Recommendation Techn

© 2014 MapR Technologies 22

Apache Mahout: Overview• Open source Apache project http://mahout.apache.org/• Mahout version is 0.9 released Feb 2014; inc Scala

– Summary 0.9 blog at http://bit.ly/1rirUUL

• Library of scalable algorithms for machine learning– Some run on Apache Hadoop distributions; others do not require Hadoop– Some can be run at small scale– Some are run in parallel; others are sequential

• Includes the following main areas:– Clustering & related techniques– Classification– Recommendation– Mahout Math Library

Page 22: Recommendation Techn

© 2014 MapR Technologies 24

Log Files

Alice

Bob

Charles

Alice

Bob

Charles

Alice

Page 23: Recommendation Techn

© 2014 MapR Technologies 25

Log Files

u1

u3

u2

u1

u3

u2

u1

t1

t4

t3

t2

t3

t3

t1

Page 24: Recommendation Techn

© 2014 MapR Technologies 26

History Matrix: Users x Items

Alice

Bob

Charles

✔ ✔ ✔

✔ ✔

✔ ✔

Page 25: Recommendation Techn

© 2014 MapR Technologies 27

Co-Occurrence Matrix: Items x Items

1 2 0

1

1 1

1

1

0

00

2How do you tell which co-occurrences are useful?

Page 26: Recommendation Techn

© 2014 MapR Technologies 28

Co-Occurrence Matrix: Items x Items

1 2 0

1

1 1

1

1

0

00

2Use LLR test to turn co-occurrence into indicators…

Page 27: Recommendation Techn

© 2014 MapR Technologies 29

Co-occurrence Binary Matrix

1

1not

not

1

Page 28: Recommendation Techn

© 2014 MapR Technologies 30

Which one is the anomalous co-occurrence?

A not A

B 13 1000

not B 1000 100,000

A not A

B 1 0

not B 0 10,000

A not A

B 10 0

not B 0 100,000

A not A

B 1 0

not B 0 2

Page 29: Recommendation Techn

© 2014 MapR Technologies 31

Which one is the anomalous co-occurrence?

A not A

B 13 1000

not B 1000 100,000

A not A

B 1 0

not B 0 10,000

A not A

B 10 0

not B 0 100,000

A not A

B 1 0

not B 0 20.90 1.95

4.52 14.3

Page 30: Recommendation Techn

© 2014 MapR Technologies 32

Co-Occurrence Matrix: Items x Items

1 2 0

1

1 1

1

1

0

00

2Recap:Use LLR test to turn co-occurrence into indicators

Page 31: Recommendation Techn

© 2014 MapR Technologies 33

Indicator Matrix: Anomalous Co-Occurrence

Result:Each marked row shows the indicators of what to recommend…

✔✔

Page 32: Recommendation Techn

© 2014 MapR Technologies 34

Indicator Matrix: Anomalous Co-Occurrence

✔✔

Why not pony + other item?

Page 33: Recommendation Techn

© 2014 MapR Technologies 36

How will you deliver recommendations to users?

Page 34: Recommendation Techn

© 2014 MapR Technologies 37

Seeking Simplicity

Innovation: Exploit search technology to deploy your recommendation system

Page 35: Recommendation Techn

© 2014 MapR Technologies 38

But first, a look at how search works…

Page 36: Recommendation Techn

© 2014 MapR Technologies 39

Apache Solr/Apache Lucene

• Apache Solr/Lucene is an open-source powerful search engine used for flexible, heavily indexed queries including data such as– Full text, geographical data, statistically weighted data

• Lucene – Provides core retrieval– Is a low-level library

• Solr – Is a web-based wrapper around Lucene – Is easy to integrate because you talk to it via a web-interface

• URL http://host machine:8888

Page 37: Recommendation Techn

© 2014 MapR Technologies 40

LucidWorks

• Enterprise platform and collection of applications based on Apache Solr/Lucene– Wrapper around Solr– A free version ships with MapR

• LucidWorks leaves Solr exposed but makes Solr administration much easier, which in turn makes it easier to use Lucene

• URL http://host machine:8989

Page 38: Recommendation Techn

© 2014 MapR Technologies 41

Solr

LucidWorks

Query Response

Index

Lucene

Query Response

Data Source

Relationship of Solr /Lucene/LucidWorks

Page 39: Recommendation Techn

© 2014 MapR Technologies 42

Other Options: Elastic Search

• Apache Lucene library at the heart of several approaches– It can also be used on its own

• Elastic Search is a different web interface for Lucene– Real time search and analytics– Open source (not Apache)– Big advantage is less accumulated cruft

http://www.elasticsearch.com/

Page 40: Recommendation Techn

© 2014 MapR Technologies 44

What is a Document?

• Data is stored in collections made up of documents• Documents contain fields that can be

– Indexed • makes field searchable; don’t have to index all

– Stored• If you want Solr to return content, have Solr store content• Not all data of interest must be stored: can access via stored URL (good for very

large data set)

– Multi-value • Body field can contain more than one type of data

– Facetted• A way to refine a search or use for statistics• Example: data for country: Could return facetted as “37 from US, 23 UK, 7 Japan”

Page 41: Recommendation Techn

© 2014 MapR Technologies 45

Fields and How to Set Them Up

• Lucene is mostly used for text– Text has to be tokenized

• Also supports other types– Long, string, keywords, comma separated

• Fields properties such as stored, indexed, faceted can also be defined

• Defaults aren’t usually so great

Page 42: Recommendation Techn

© 2014 MapR Technologies 46

Example of Facetted Search

The indexed fields “Area” and “Gender” have been facetted to provide counts for the results

Page 43: Recommendation Techn

© 2014 MapR Technologies 48

Field-specific Searches Using Lucene Syntax

• Documents often have title, author, keywords and body text• General syntax is

field:(term1 term2)

• Alternativesfield:(term1 OR term2) field:(“term1 term2” ~ 5) field:(term1 AND term2)

• Default field, default interpretations work very well for text

Page 44: Recommendation Techn

© 2014 MapR Technologies 49

Send Data to Solr (not LucidWorks)

• LucidWorks has lots of spiders that can use file extension or mime type to trigger certain file parsers– Works best with web-ish sources and mime types– Also includes MapR and MapR high volume indexers

• More common at modest volumes or for updates to use JSON format

{"id":"book_314", "title":{"set":"The Call of the Wild"}}

• Use REST interface to send update filescurl http://localhost:8983/solr/update \

-H 'Content-type:application/json' --data-binary @file.json

Page 45: Recommendation Techn

© 2014 MapR Technologies 51

Back to recommendation: How do you abuse search to make recommendation easy?

Page 46: Recommendation Techn

© 2014 MapR Technologies 52

Collection of Documents: Insert Meta-Data

Search Technology

Item meta-data

Document for “puppy” id: t4

title: puppydesc: The sweetest little puppy ever.keywords: puppy, dog, pet

Ingest easily via NFS

Page 47: Recommendation Techn

© 2014 MapR Technologies 53

From Indicator Matrix to New Indicator Field

id: t4title: puppydesc: The sweetest little puppy ever.keywords: puppy, dog, pet

indicators: (t1)

Solr document for “puppy”

Note: data for the indicator field is added directly to meta-data for a document in Apache Solr or Elastic Search index. You don’t need to create a separate index for the indicators.

Page 48: Recommendation Techn

© 2014 MapR Technologies 54

Let’s look at a real example: we built a music recommender

Page 49: Recommendation Techn

© 2014 MapR Technologies 56

Page 50: Recommendation Techn

© 2014 MapR Technologies 57

User activity: Listens to classic jazz hit “Take the A Train”

Page 51: Recommendation Techn

© 2014 MapR Technologies 58

System delivers recommendations based on activity

Page 52: Recommendation Techn

© 2014 MapR Technologies 59

Let’s look inside the music recommender…

Page 53: Recommendation Techn

© 2014 MapR Technologies 60

Music Meta Data for Search Document Collections

• MusicBrainz data

• Data includes Artist ID, MusicBrainz ID, Name, Group/Person, From (geo locations) and Gender as seen in this sample

Page 54: Recommendation Techn

© 2014 MapR Technologies 62

Sample User Behavior Histories: Music Log Files

13 START 10113 2182654281

23 BEACON 10113 218265 428124 START 10113 796006

1193502834 BEACON 10113 7960061193502844 BEACON 10113 7960061193502854 BEACON 10113 7960061193502864 BEACON 10113 7960061193502874 BEACON 10113 7960061193502884 BEACON 10113 7960061193502894 BEACON 10113 79600611935028104 BEACON 10113 79600611935028109 FINISH 10113 79600611935028111 START 10113 589999

12011972121 BEACON 10113 58999912011972

Time

Event type

User ID

Artist ID

Track ID

Page 55: Recommendation Techn

© 2014 MapR Technologies 63

Sample Music Log Files

Artist ID for jazz musician Duke Ellington

What has user 119 done here in the highlighted lines?

Page 56: Recommendation Techn

© 2014 MapR Technologies 64

Internals of a Recommendation Engine

Page 57: Recommendation Techn

© 2014 MapR Technologies 65

Internals of a Recommendation Engine

Page 58: Recommendation Techn

© 2014 MapR Technologies 66

id 1710mbid 592a3b6d-c42b-4567-99c9-ecf63bd66499name Chuck Berryarea United Statesgender Maleindicator_artists 386685,875994,637954,3418,1344,789739,1460, …

id 541902mbid 983d4f8f-473e-4091-8394-415c105c4656name Charlie Winstonarea United Kingdomgender Noneindicator_artists 997727,815,830794,59588,900,2591,1344,696268, …

Lucene Documents for Music RecommendationNotice that data from indicator matrix of trained Mahout recommender model has been added to indicator field in documents of the artists collection

Page 59: Recommendation Techn

© 2014 MapR Technologies 68

Offline Analysis

Analysis Using Mahout

Users History Log Files Indicators

Search Technology

Item Meta-Data

Page 60: Recommendation Techn

© 2014 MapR Technologies 69

Log FilesMahout Analysis

Search Technology

Item Meta-Data

Ingest easily via NFS

MapR Cluster

via NFS Python

Use Python directly via NFS

Pig

Web TierRecommendations

New User History

Real-time recommendations using MapR data platform

Page 61: Recommendation Techn

© 2014 MapR Technologies 70

A Quick Simplification• Users who do h

• Also do

User-centric recommendations

Item-centric recommendations

Page 62: Recommendation Techn

© 2014 MapR Technologies 71

Architectural Advantage

User-centric recommendations

Item-centric recommendations

Page 63: Recommendation Techn

© 2014 MapR Technologies 72

Architectural Advantage

User-centric recommendations

With the first design, you have to do the real-time computation first (in parenthesis). No way to pre-compute. Less efficient, less fast.

With the second design, you can pre-compute offline (overnight) things that change slowly. Only the smaller computation for new user vector (h) is done in real-time, so response is very fast.

Item-centric recommendations

Page 64: Recommendation Techn

© 2014 MapR Technologies 74

Tutorial Part 2:How to make recommendation better

Page 65: Recommendation Techn

© 2014 MapR Technologies 75

Going Further: Multi-Modal Recommendation

Page 66: Recommendation Techn

© 2014 MapR Technologies 76

Going Further: Multi-Modal Recommendation

Page 67: Recommendation Techn

© 2014 MapR Technologies 77

For example

• Users enter queries (A)– (actor = user, item=query)

• Users view videos (B)– (actor = user, item=video)

• ATA gives query recommendation– “did you mean to ask for”

• BTB gives video recommendation– “you might like these videos”

Page 68: Recommendation Techn

© 2014 MapR Technologies 78

The punch-line

• BTA recommends videos in response to a query– (isn’t that a search engine?)– (not quite, it doesn’t look at content or meta-data)

Page 69: Recommendation Techn

© 2014 MapR Technologies 79

Real-life example

• Query: “Paco de Lucia”• Conventional meta-data search results:

– “hombres de paco” times 400– not much else

• Recommendation based search:– Flamenco guitar and dancers– Spanish and classical guitar– Van Halen doing a classical/flamenco riff

Page 70: Recommendation Techn

© 2014 MapR Technologies 80

Real-life example

Page 71: Recommendation Techn

© 2014 MapR Technologies 81

Hypothetical Example

• Want a navigational ontology?• Just put labels on a web page with traffic

– This gives A = users x label clicks

• Remember viewing history– This gives B = users x items

• Cross recommend– B’A = label to item mapping

• After several users click, results are whatever users think they should be

Page 72: Recommendation Techn

© 2014 MapR Technologies 82

Nice. But we can do better?

Page 73: Recommendation Techn

© 2014 MapR Technologies 84

Symmetry Gives Cross Recommentations

Conventional recommendations with off-line learning

Cross recommendations

Page 74: Recommendation Techn

© 2014 MapR Technologies 85

users

things

Page 75: Recommendation Techn

© 2014 MapR Technologies 86

users

thingtype 1

thingtype 2

Page 76: Recommendation Techn

© 2014 MapR Technologies 87

Page 77: Recommendation Techn

© 2014 MapR Technologies 88

Bonus Round:

When worse is better

Page 78: Recommendation Techn

© 2014 MapR Technologies 89

The Real Issues After First Production

• Exploration• Diversity• Speed

• Not the last fraction of a percent

Page 79: Recommendation Techn

© 2014 MapR Technologies 90

Result Dithering

• Dithering is used to re-order recommendation results – Re-ordering is done randomly

• Dithering is guaranteed to make off-line performance worse

• Dithering also has a near perfect record of making actual performance much better

Page 80: Recommendation Techn

© 2014 MapR Technologies 91

Result Dithering

• Dithering is used to re-order recommendation results – Re-ordering is done randomly

• Dithering is guaranteed to make off-line performance worse

• Dithering also has a near perfect record of making actual performance much better

“Made more difference than any other change”

Page 81: Recommendation Techn

© 2014 MapR Technologies 92

Why Dithering Works

Real-time recommender

Overnight training

Log Files

Page 82: Recommendation Techn

© 2014 MapR Technologies 93

Why Use Dithering?

Page 83: Recommendation Techn

© 2014 MapR Technologies 94

Simple Dithering Algorithm

• Synthetic score from log rank plus Gaussian

• Pick noise scale to provide desired level of mixing

• Typically

• Also… use floor(t/T) as seed

Page 84: Recommendation Techn

© 2014 MapR Technologies 95

Example … ε = 2

Page 85: Recommendation Techn

© 2014 MapR Technologies 96

Lesson:Exploration is good

Page 86: Recommendation Techn

© 2014 MapR Technologies 97

Thank you

Ted Dunning, Chief Applications Architect, MapR Technologies

Email [email protected] [email protected]

Twitter @Ted_Dunning

Apache Mahout https://mahout.apache.org/

Twitter @ApacheMahout

22 June 2014 Big Data Everywhere Conference #DataIsrael