Lab 5: Information Retrieval and Vector Semantics
In 1998, a tiny startup called Google launched a search engine and changed the world. But I mean...come on, how hard can it be to make a search engine, right? Is Larry and Sergey's fame and fortune deserved? Could you do better? Let's find out!
In this lab, you'll try your hand at building a (very basic) search engine. To keep things manageable, we won't be having you search the entirety of the Internet. Instead, your search engine will simply search Wikipedia articles; specifically, it will search a corpus of over 120,000 Wikipedia articles, which we have provided for you in the directory /courses/cs159/data/wikipedia/enwiki_sampled.
As you might imagine, even though this is the largest corpus we've had you work with on a lab, it's still only a tiny fraction of Wikipedia!
Along the way, you will also investigate how vector semantics can (or can't) help you with this information retrieval task.
One other thing to know about this lab: believe it or not, this is the last lab of the semester! From here on out, we'll start to transition to thinking about the final project. Therefore, in addition to having you practice information retrieval and vector semantics, another learning goal of this lab is to give you some experience with what it "feels like" to work on a final project. Specifically, this lab has the following properties that make it different from previous labs (but which make it more closely resemble a final project):
- The data you will be working with has no labels of any kind, which means that you cannot do any sort of empirical evaluation. Instead, you will need to interpret your results qualitatively, based on your own human intuitions and knowledge of NLP. This is a common situation faced by many final project teams, since teams often want to work with real world data which likewise typically isn't labeled.
- Likewise, there are no provided tests. You will need to use your intuition to judge whether the results you are seeing look reasonable. Again, this is something you will encounter in the final project; NLP algorithms don't always behave the way we expect and "correct" results can sometimes still look strange, so making this judgment can be harder than it sounds! When in doubt, try running multiple different searches/inputs. If they all look weird, then something is probably wrong, but if at least some look clearly reasonable you are probably ok.
- There will be a "choose your own adventure" aspect at the end of this lab where you're given full freedom to explore Python libraries of your own choosing with no guidance. Once again, this is meant to simulate the final project experience, where teams typically need to do their own research to find resources that will help them achieve their goal.
Hint (useful for the entire lab): at several points in this lab, you may find yourself wanting to do matrix multiplication. There are two things to be careful about regarding matrix multiplication in numpy:
- You might think that
*does matrix multiplication, but you'd be wrong! The exact behavior of*varies depending on the shape of the matrices, and it can be hard to predict since numpy will always try to interpret it in some way that "works" regardless of the shapes. To do actual matrix multiplication, of the kind that you learned about in Linear Algebra, such that the code will throw an error if the shapes don't work, you shoud instead use the@operator (so,M @ Ninstead ofM * N). - A vector is not a matrix, even though both are considered "arrays" in numpy! A vector with
Nelements has shape(N), whereas a matrix with one row andNelements (which sounds like it should be the same thing) has shape(1,N). You can't multiply a vector with a matrix, you can only multiply two matrices! To turn a vector into a 1xNmatrix, you can callreshape(1,-1). Another nice trick: if you want the vector to become "vertical" (i.e., a matrix with one column, with one element per row) you can instead callreshape(-1,1). Finally, if you ever want to take such a "flat" matrix (1xN or Nx1) and turn it back into a vector, you can do that by callingflatten().
In order to proceed, please fill out the following confirmation:
What is this, a terms of service agreement?
Sorry if it felt annoying—it's just that, since this lab is so different from the others, we wanted to make absolutely sure everyone understands the instructions before they click to the next page.
Meh. Nobody reads those terms of service agreements anyway, they just click "Yes".
Sure, but if we can at least get some folks to stop and double check, that's a win in our book!
(When logged in, completion status appears here.)