Notebooks
F
FastAI
Lesson4 Collab

Lesson4 Collab

colabdev_nbsmachine-learninggpudeep-learningnotebooksPythonfastaipytorchcourse
[ ]

Collaborative filtering example

collab models use data in a DataFrame of user, items, and ratings.

[ ]
[ ]
PosixPath('/home/sgugger/.fastai/data/movie_lens_sample')
[ ]

That's all we need to create and train a model:

[ ]
[ ]
[ ]
[ ]

Movielens 100k

Let's try with the full Movielens 100k data dataset, available from http://files.grouplens.org/datasets/movielens/ml-100k.zip

[ ]
[ ]
[ ]
[ ]
100000
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
Output
[ ]
[ ]

Here's some benchmarks on the same dataset for the popular Librec system for collaborative filtering. They show best results based on RMSE of 0.91, which corresponds to an MSE of 0.91**2 = 0.83.

Interpretation

Setup

[ ]
[ ]
EmbeddingDotBias(
,  (u_weight): Embedding(944, 40)
,  (i_weight): Embedding(1650, 40)
,  (u_bias): Embedding(944, 1)
,  (i_bias): Embedding(1650, 1)
,)
[ ]
array(['Star Wars (1977)', 'Contact (1997)', 'Fargo (1996)',
,       'Return of the Jedi (1983)', 'Liar Liar (1997)',
,       'English Patient, The (1996)', 'Scream (1996)', 'Toy Story (1995)',
,       'Air Force One (1997)', 'Independence Day (ID4) (1996)'],
,      dtype=object)

Movie bias

[ ]
torch.Size([1000])
[ ]
[ ]
[ ]
[(tensor(-0.3480),
,  'Children of the Corn: The Gathering (1996)',
,  1.3157894736842106),
, (tensor(-0.3199),
,  'Lawnmower Man 2: Beyond Cyberspace (1996)',
,  1.7142857142857142),
, (tensor(-0.2892), 'Crow: City of Angels, The (1996)', 1.9487179487179487),
, (tensor(-0.2810), "Joe's Apartment (1996)", 2.2444444444444445),
, (tensor(-0.2784), 'Mortal Kombat: Annihilation (1997)', 1.9534883720930232),
, (tensor(-0.2743), 'Cable Guy, The (1996)', 2.339622641509434),
, (tensor(-0.2514), 'Home Alone 3 (1997)', 1.894736842105263),
, (tensor(-0.2509), 'Beautician and the Beast, The (1997)', 2.313953488372093),
, (tensor(-0.2329), 'Grease 2 (1982)', 2.0),
, (tensor(-0.2298), 'Bio-Dome (1996)', 1.903225806451613),
, (tensor(-0.2295), 'Kansas City (1996)', 2.260869565217391),
, (tensor(-0.2254), 'Island of Dr. Moreau, The (1996)', 2.1578947368421053),
, (tensor(-0.2178), 'Striptease (1996)', 2.2388059701492535),
, (tensor(-0.2178), 'Thinner (1996)', 2.4489795918367347),
, (tensor(-0.2099), 'Flintstones, The (1994)', 2.064516129032258)]
[ ]
[(tensor(0.5769), 'Titanic (1997)', 4.2457142857142856),
, (tensor(0.5740), 'Shawshank Redemption, The (1994)', 4.445229681978798),
, (tensor(0.5597), "Schindler's List (1993)", 4.466442953020135),
, (tensor(0.5412), 'L.A. Confidential (1997)', 4.161616161616162),
, (tensor(0.5299), 'Silence of the Lambs, The (1991)', 4.28974358974359),
, (tensor(0.5277), 'Star Wars (1977)', 4.3584905660377355),
, (tensor(0.5270), 'Rear Window (1954)', 4.3875598086124405),
, (tensor(0.5267), 'Apt Pupil (1998)', 4.1),
, (tensor(0.5005), 'As Good As It Gets (1997)', 4.196428571428571),
, (tensor(0.4942), 'Casablanca (1942)', 4.45679012345679),
, (tensor(0.4938), 'Close Shave, A (1995)', 4.491071428571429),
, (tensor(0.4844), 'Good Will Hunting (1997)', 4.262626262626263),
, (tensor(0.4650), 'Usual Suspects, The (1995)', 4.385767790262173),
, (tensor(0.4602), 'Godfather, The (1972)', 4.283292978208232),
, (tensor(0.4561), 'Vertigo (1958)', 4.251396648044692)]

Movie weights

[ ]
torch.Size([1000, 40])
[ ]
torch.Size([1000, 3])
[ ]
[ ]
[(tensor(1.1449), 'Chinatown (1974)'),
, (tensor(1.0863), 'Close Shave, A (1995)'),
, (tensor(1.0594),
,  'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb (1963)'),
, (tensor(1.0126), 'Casablanca (1942)'),
, (tensor(0.9971), 'When We Were Kings (1996)'),
, (tensor(0.9898), 'Some Folks Call It a Sling Blade (1993)'),
, (tensor(0.9893), '12 Angry Men (1957)'),
, (tensor(0.9696), 'North by Northwest (1959)'),
, (tensor(0.9677), 'Lawrence of Arabia (1962)'),
, (tensor(0.9567), 'Ran (1985)')]
[ ]
[(tensor(-1.2181), 'Home Alone 3 (1997)'),
, (tensor(-1.1975), 'Jungle2Jungle (1997)'),
, (tensor(-1.1753), 'Congo (1995)'),
, (tensor(-1.1661), 'Bio-Dome (1996)'),
, (tensor(-1.1285), 'Children of the Corn: The Gathering (1996)'),
, (tensor(-1.1258), "McHale's Navy (1997)"),
, (tensor(-1.0802), 'Free Willy 3: The Rescue (1997)'),
, (tensor(-1.0568), 'Batman & Robin (1997)'),
, (tensor(-1.0467), 'Leave It to Beaver (1997)'),
, (tensor(-1.0363), 'Mortal Kombat: Annihilation (1997)')]
[ ]
[ ]
[(tensor(0.8935), 'Trainspotting (1996)'),
, (tensor(0.8681), 'Beavis and Butt-head Do America (1996)'),
, (tensor(0.8247), 'Exotica (1994)'),
, (tensor(0.8018), 'Brazil (1985)'),
, (tensor(0.7887), 'Clockwork Orange, A (1971)'),
, (tensor(0.7714), 'Jude (1996)'),
, (tensor(0.7573), 'Lost Highway (1997)'),
, (tensor(0.7393), 'Keys to Tulsa (1997)'),
, (tensor(0.7232), 'Cable Guy, The (1996)'),
, (tensor(0.7216), 'Pallbearer, The (1996)')]
[ ]
[(tensor(-1.1362), 'Braveheart (1995)'),
, (tensor(-1.1113), 'Raiders of the Lost Ark (1981)'),
, (tensor(-1.0690), 'Titanic (1997)'),
, (tensor(-0.9674), 'American President, The (1995)'),
, (tensor(-0.8977), "It's a Wonderful Life (1946)"),
, (tensor(-0.8572), 'Sleepless in Seattle (1993)'),
, (tensor(-0.8516), 'Pretty Woman (1990)'),
, (tensor(-0.8425), 'Field of Dreams (1989)'),
, (tensor(-0.8065), 'Independence Day (ID4) (1996)'),
, (tensor(-0.7923), 'Back to the Future (1985)')]
[ ]
Output
[ ]