Math, Madison, food, the Orioles, books, my kids.

Category Archives: computers

Awesome SILO seminar this week by Suriya Gunasekar of TTI Chicago. Here’s the idea, as I understand it. In a classical optimization problem, like linear regression, you are trying to solve a problem which typically has no solution (draw a line that passes through every point in this cloud!) and the challenge is to find the best approximate solution. Algebraically speaking: you might be asked to solve

for x; but since x may not be in the image of the linear transformation A, you settle for minimizing

in whatever norm you like (L^2 for standard linear regression.)

In many modern optimization problems, on the other hand, the problem you’re trying to solve may have a lot more degrees of freedom. Maybe you’re setting up an RNN with lots and lots and lots of parameters. Or maybe, to bring this down to earth, you’re trying to pass a curve through lots of points but the curve is allowed to have very high degree. This has the advantage that you can definitely find a curve that passes through all the points. But it also has the disadvantage that you can definitely find a curve that passes through all the points. You are likely to overfit! Your wildly wiggly curve, engineered to exactly fit the data you trained on, is unlikely to generalize well to future data.

Everybody knows about this problem, everybody knows to worry about it. But here’s the thing. A lot of modern problems are of this form, and yet the optima we find on training data often do generalize pretty well to test data! Why?

Make this more formal. Let’s say for the sake of argument you’re trying to learn a real-valued function F, which you hypothesize is drawn from some giant space X. (Not necessarily a vector space, just any old space.) You have N training pairs (x_i, y_i), and a good choice for F might be one such that F(x_i) = y_i. So you might try to find F such that

for all i. But if X is big enough, there will be a whole space of functions F which do the trick! The solution set to

will be some big subspace F_{x,y} of X. How do you know which of these F’s to pick?

One popular way is to regularize; you decide that some elements of X are just better than others, and choose the point of F_{x,y} that optimizes that objective. For instance, if you’re curve-fitting, you might try to find, among those curves passing through your N points, the least wiggly one (e.g. the one with the least total curvature.) Or you might optimize for some combination of hitting the points and non-wiggliness, arriving at a compromise curve that wiggles only mildly and still passes near most of the points. (The ultimate version of this strategy would be to retreat all the way back to linear regression.)

But it’s not obvious what regularization objective to choose, and maybe trying to optimize that objective is yet another hard computational problem, and so on and so on. What’s really surprising is that something much simpler often works pretty well. Namely: how would you find F such that F(x) = y in the first place? You would choose some random F in X, then do some version of gradient descent. Find the direction in the tangent space to X at F that decreases most steeply, perturb F a bit in that direction, lather, rinse, repeat.

If this process converges, it ought to get you somewhere on the solution space F_{x,y}. But where? And this is really what Gunasekar’s work is about. Even if your starting F is distributed broadly, the distribution of the spot where gradient descent “lands” on F_{x,y} can be much more sharply focused. In some cases, it’s concentrated on a single point! The “likely targets of gradient descent” seem to generalize better to test data, and in some cases Gunasekar et al can prove gradient descent likes to find the points on F_{x,y} which optimize some regularizer.

I was really struck by this outlook. I have tended to think of function learning as a problem of optimization; how can you effectively minimize the training loss ||F(x) – y||? But Gunasekar asks us instead to think about the much richer mathematical structure of the dynamical system of gradient descent on X guided by the loss function. (Or I should say dynamical systems; gradient descent comes in many flavors.)

The dynamical system has a lot more stuff in it! Think about iterating a function; knowing the fixed points is one thing, but knowing which fixed points are stable and which aren’t, and knowing which stable points have big basins of attraction, tells you way more.

What’s more, the dynamical system formulation is much more natural for learning problems as they are so often encountered in life, with streaming rather than static training data. If you are constantly observing more pairs (x_i,y_i), you don’t want to have to start over every second and optimize a new loss function! But if you take the primary object of study to be, not the loss function, but the dynamical system on the hypothesis space X, new data is no problem; your gradient is just a longer and longer sum with each timestep (or you exponentially deweight the older data, whatever you want my friend, the world is yours.)

Anyway. Loved this talk. Maybe this dynamical framework is the way other people are already accustomed to think of it but it was news to me.

I saw Peter Norvig give a great general-audience talk on AI at Berkeley when I was there last month. A few notes from his talk.

“We have always prioritized fast and cheap over safety and privacy — maybe this time we can make better choices.”

He briefly showed a demo where, given values of a polynomial, a machine can put together a few lines of code that successfully computes the polynomial. But the code looks weird to a human eye. To compute some quadratic, it nests for-loops and adds things up in a funny way that ends up giving the right output. So has it really ”learned” the polynomial? I think in computer science, you typically feel you’ve learned a function if you can accurately predict its value on a given input. For an algebraist like me, a function determines but isn’t determined by the values it takes; to me, there’s something about that quadratic polynomial the machine has failed to grasp. I don’t think there’s a right or wrong answer here, just a cultural difference to be aware of. Relevant: Norvig’s description of “the two cultures” at the end of this long post on natural language processing (which is interesting all the way through!)

Norvig made the point that traditional computer programs are very modular, leading to a highly successful debugging tradition of zeroing in on the precise part of the program that is doing something wrong, then fixing that part. An algorithm or process developed by a machine, by contrast, may not have legible “parts”! If a neural net is screwing up when classifying something, there’s no meaningful way to say “this neuron is the problem, let’s fix it.” We’re dealing with highly non-modular complex systems which have evolved into a suboptimally functioning state, and you have to find a way to improve function which doesn’t involve taking the thing apart and replacing the broken component. Of course, we already have a large professional community that works on exactly this problem. They’re called therapists. And I wonder whether the future of debugging will look a lot more like clinical psychology than it does like contemporary software engineering.

Like this:

I was talking the other day with a former student at UW, Sarah Rich, who’s done degrees in both math and CS and then went off to Twitter. I asked her: so what would you say to a math Ph.D. student who was wondering whether they would like being a data scientist in the tech industry? How would you know whether you might find that kind of work enjoyable? And if you did decide to pursue it, what’s the strategy for making yourself a good job candidate?

Sarah exceeded my expectations by miles and wrote the following extremely informative and thorough tip sheet, which she’s given me permission to share. Take it away, Sarah!

Like this:

When I was a kid we looked up our elliptic curves in Cremona’s tables, on paper. Then William Stein created the Modular Forms Database (you can still go there but it doesn’t really work) and suddenly you could look at the q-expansions of cusp forms in whatever weight and level you wanted, up to the limits of what William had computed.

The LMFDB is a sort of massively souped up version of Cremona and Stein, put together by a team of dozens and dozens of number theorists, including too many friends of mine to name individually. And it’s a lot more than what the title suggests: the incredibly useful Jones-Roberts database of local fields is built in; there’s a database of genus 2 curves over Q with small conductor; it even has Maass forms! I’ve been playing with it all night. It’s like an adventure playground for number theorists.

One of my first trips through Stein’s database came when I was a postdoc and was thinking about Ljunggren’s equation y^2 + 1 = 2x^4. This equation has a large solution, (13,239), which has to do with the classical identity

.

It turns out, as I explain in an old survey paper, that the existence of such a large solution is “explained” by the presence of a certain weight-2 cuspform in level 1024 whose mod-5 Galois representation is reducible.

With the LMFDB, you can easily wander around looking for more such examples! For instance, you can very easily ask the database for non-CM elliptic curves whose mod-7 Galois representation is nonsurjective. Among those, you can find this handsome curve of conductor 1296, which has very large height relative to its conductor. Applying the usual Frey curve trick you can turn this curve into the Diophantine oddity

3*48383^2 – (1915)^3 = 2^13.

Huh — I wonder whether people ever thought about this Diophantine problem, when can the difference between a cube and three times a square be a power of 2? Of course they did! I just Googled

Like this:

When I was a kid people thought it would be a long time before computers could adequately translate natural language text, or play Go against a human being, because you’d need some kind of AI to do those things, and AI seemed really hard.

Now we know that you can get pretty decent translation and Go without anything like AI. But AI still seems really hard.

Share this:

Like this:

By the way, here’s another fun word2vec trick. Following Ben Schmidt, you can try to find “gender-neutralized synonyms” — words which are close to each other except for the fact that they have different gender connotations. A quick and dirty way to “mascify” a word is to find its nearest neighbor which is closer to “he” than “she”:

“femify” is defined similarly. We could put a threshold away from 0 in there, if we wanted to restrict to more strongly gender-coded words.

Anyway, if you start with a word and run mascify and femify alternately, you can ask whether you eventually wind up in a 2-cycle: a pair of words which are each others gender counterparts in this loose sense.

e.g.

gentle -> easygoing -> chatty -> talkative -> chatty -> …..

So “chatty” and “talkative” are a pair, with “chatty” female-coded and “talkative” male-coded.

beautiful -> magnificent -> wonderful -> marvelous -> wonderful -> …

So far, I keep hitting 2-cycles, and pretty quickly, though I don’t see why a longer cycle wouldn’t be possible or likely. Update: Kevin in comments explains very nicely why it has to terminate in a 2-cycle!

Some other pairs, female-coded word first:

overjoyed / elated

strident / vehement

fearful / worried

furious / livid

distraught / despondent

hilarious / funny

exquisite / sumptuous

thought_provoking / insightful

kick_ass / badass

Sometimes it’s basically giving the same word, in two different forms or with one word misspelled:

intuitive / intuitively

buoyant / bouyant

sad / Sad

You can do this for names, too, though you have to make the “topn” a little longer to find matches. I found:

Jamie / Chris

Deborah / Jeffrey

Fran / Pat

Mary / Joseph

Pretty good pairs! Note that you hit a lot of gender-mixed names (Jamie, Chris, Pat), just as you might expect: the male-biased name word2vec-closest to a female name is likely to be a name at least some women have! You can deal with this by putting in a threshold:

Like this:

Word2vec is a way of representing words and phrases as vectors in medium-dimensional space developed by Tomas Mikolov and his team at Google; you can train it on any corpus you like (see Ben Schmidt’s blog for some great examples) but the version of the embedding you can download was trained on about 100 billion words of Google News, and encodes words as unit vectors in 300-dimensional space.

What really got people’s attention, when this came out, was word2vec’s ability to linearize analogies.For example:if x is the vector representing “king,” and y the vector representing “woman,” and z the vector representing “man,” then consider

x + y – z

which you might think of, in semantic space, as being the concept “king” to which “woman” has been added and “man” subtracted — in other words, “king made more female.”What word lies closest in direction to x+y-z?Just as you might hope, the answer is “queen.”

I found this really startling.Does it mean that there’s some hidden linear structure in the space of words?

It turns out it’s not quite that simple.I played around with word2vec a bunch, using Radim Řehůřek’s gensim package that nicely pulls everything into python; here’s what I learned about what the embedding is and isn’t telling you.

Word2Vec distance isn’t semantic distance

The Word2Vec metric tends to place two words close to each other if they occur in similar contexts — that is, w and w’ are close to each other if the words that tend to show up near w also tend to show up near w’(This is probably an oversimplification, but see this paper of Levy and Goldberg for a more precise formulation.)If two words are very close to synonymous, you’d expect them to show up in similar contexts, and indeed synonymous words tend to be close:

>>> model.similarity(‘tremendous’,’enormous’)

0.74432902555062841

The notion of similarity used here is just cosine distance (which is to say, dot product of vectors.)It’s positive when the words are close to each other, negative when the words are far.For two completely random words, the similarity is pretty close to 0.

On the other hand:

>>> model.similarity(‘tremendous’,’negligible’)

0.37869063705009987

Tremendous and negligible are very far apart semantically; but both words are likely to occur in contexts where we’re talking about size, and using long, Latinate words.‘Negligible’ is actually one of the 500 words closest to ’tremendous’ in the whole 3m-word database.

You might ask:well, what words in Word2Vec are farthest from “tremendous?”You just get trash:

If 3 million words were distributed randomly in the unit ball in R^300, you’d expect the farthest one from “tremendous” to have dot product about -0.3 from it.So when you see a list whose largest score is around that size, you should think “there’s no structure there, this is just noise.”

Antonyms

Challenge problem:Is there a way to accurately generate antonyms using the word2vec embedding?That seems to me the sort of thing the embedding is not capturing.Kyle McDonald had a nice go at this, but I think the lesson of his experiment is that asking word2vec to find analogies of the form “word is to antonym as happy is to?” is just going to generate a list of neighbors of “happy.”McDonald’s results also cast some light on the structure of word2vec analogies:for instance, he finds that

waste is to economise as happy is to chuffed

First of all, “chuffed” is a synonym of happy, not an antonym.But more importantly:The reason “chuffed” is there is because it’s a way that British people say “happy,” just as “economise” is a way British people spell “economize.”Change the spelling and you get

waste is to economize as happy is to glad

Non-semantic properties of words matter to word2vec.They matter a lot.Which brings us to diction.

Word2Vec distance keeps track of diction

Lots of non-semantic stuff is going on in natural language.Like diction, which can be high or low, formal or informal, flowery or concrete.Look at the nearest neighbors of “pugnacity”:

Some of these are close semantically to pugnacity, but others, like “wonkishness,” “eloquence”, and “sangfroid,” are really just the kind of elevated-diction words the kind of person who says “pugnacity” would also say.

“geeked” is a pretty good synonym, but “bummed” is an antonym.You may also note that contexts where “psyched” is common are also fertile ground for “pysched.”This leads me to one of my favorite classes of examples:

Now let’s come back to the more philosophical question.Should the effectiveness of word2vec at solving analogy problems make us think that the space of words really has linear structure?

I don’t think so.Again, I learned something important from the work of Levy and Goldberg.When word2vec wants to find the word w which is to x as y is to z, it is trying to find w maximizing the dot product

w . (x + y – z)

But this is the same thing as maximizing

w.x + w.y – w.z.

In other words, what word2vec is really doing is saying

“Show me words which are similar to x and y but are dissimilar to z.”

This notion makes sense applied any notion of similarity, whether or not it has anything to do with embedding in a vector space.For example, Levy and Goldberg experiment with minimizing

log(w.x) + log(w.y) – log(w.z)

instead, and get somewhat superior results on the analogy task.Optimizing this objective has nothing to do with the linear combination x+y-z.

None of which is to deny that the analogy engine in word2vec works well in many interesting cases!It has no trouble, for instance, figuring out that Baltimore is to Maryland as Milwaukee is to Wisconsin.More often than not, the Milwaukee of state X correctly returns the largest city in state X.And sometimes, when it doesn’t, it gives the right answer anyway:for instance, the Milwaukee of Ohio is Cleveland, a much better answer than Ohio’s largest city (Columbus — you knew that, right?)The Milwaukee of Virginia, according to word2vec, is Charlottesville, which seems clearly wrong.But maybe that’s OK — maybe there really isn’t a Milwaukee of Virginia.One feels Richmond is a better guess than Charlottesville, but it scores notably lower.(Note:Word2Vec’s database doesn’t have Virginia_Beach, the largest city in Virginia.That one I didn’t know.)

Another interesting case:what is to state X as Gainesville is to Florida?The answer should be “the location of the, or at least a, flagship state university, which isn’t the capital or even a major city of the state,” when such a city exists.But this doesn’t seem to be something word2vec is good at finding.The Gainesville of Virginia is Charlottesville, as it should be.But the Gainesville of Georgia is Newnan.Newnan?Well, it turns out there’s a Newnan, Georgia, and there’s also a Newnan’s Lake in Gainesville, FL; I think that’s what’s driving the response.That, and the fact that “Athens”, the right answer, is contextually separated from Georgia by the existence of Athens, Greece.

The Gainesville of Tennessee is Cookeville, though Knoxville, the right answer, comes a close second.

Why?You can check that Knoxville, according to word2vec, is much closer to Gainesville than Cookeville is.

>>> model.similarity(‘Cookeville’,’Gainesville’)

0.5457580604439547

>>> model.similarity(‘Knoxville’,’Gainesville’)

0.64010456774402158

But Knoxville is placed much closer to Florida!

>>> model.similarity(‘Cookeville’,’Florida’)

0.2044376252927515

>>> model.similarity(‘Knoxville’,’Florida’)

0.36523836770416895

Remember:what word2vec is really optimizing for here is “words which are close to Gainesville and close to Tennessee, and which are not close to Florida.”And here you see that phenomenon very clearly.I don’t think the semantic relationship between ‘Gainesville’ and ‘Florida’ is something word2vec is really capturing.Similarly:the Gainesville of Illinois is Edwardsville (though Champaign, Champaign_Urbana, and Urbana are all top 5) and the Gainesville of Indiana is Connersville.(The top 5 for Indiana are all cities ending in “ville” — is the phonetic similarity playing some role?)

Just for fun, here’s a scatterplot of the 1000 nearest neighbors of ‘Gainesville’, with their similarity to ‘Gainesville’ (x-axis) plotted against their similarity to ‘Tennessee’ (y-axis):

The Pareto frontier consists of “Tennessee” (that’s the one whose similarity to “Tennessee” is 1, obviously..) Knoxville, Jacksonville, and Tallahassee.

Bag of contexts

One popular simple linear model of word space is given by representing a word as a “bag of contexts” — perhaps there are several thousand contexts, and each word is given by a sparse vector in the space spanned by contexts: coefficient 0 if the word is not in that context, 1 if it is. In that setting, certain kinds of analogies would be linearized and certain kinds would not. If “major city” is a context, then “Houston” and “Dallas” might have vectors that looked like “Texas” with the coodinate of “major city” flipped from 0 to 1. Ditto, “Milwaukee” would be “Wisconsin” with the same basis vector added. So

“Texas” + “Milwaukee” – “Wisconsin”

would be pretty close, in that space, to “Houston” and “Dallas.”

On the other hand, it’s not so easy to see what relations antonyms would have in that space. That’s the kind of relationship the bag of contexts may not make linear.

The word2vec space is only 300-dimensional, and the vectors aren’t sparse at all. But maybe we should think of it as a random low-dimensional projection of a bag-of-contexts embedding! By the Johnson-Lindenstrauss lemma, a 300-dimensional projection is plenty big enough to preserve the distances between 3 million points with a small distortion factor; and of course it preserves all linear relationships on the nose.

Perhaps this point of view gives some insight into which kind of word relationships manifest as linear relationships in word2vec. “flock:birds” is an interesting example. If you imagine “group of things” as a context, you can maybe imagine word2vec picking this up. But actually, it doesn’t do well:

The answers “school” and “pack” don’t appear here. Part of this, of course, is that “flock,” “school”, and “pack” all have interfering alternate meanings. But part of it is that the analogy really rests on information about contexts in which the words “flock” and “birds” both appear. In particular, in a short text window featuring both words, you are going to see a huge spike of “of” appearing right after flock and right before birds. A statement of the form “flock is to birds as X is to Y” can’t be true unless “X of Y” actually shows up in the corpus a lot.

Challenge problem: Can you make word2vec do a good job with relations like “flock:birds”? As I said above, I wouldn’t have been shocked if this had actually worked out of the box, so maybe there’s some minor tweak that makes it work.

Boys’ names, girls’ names

Back to gender-flipping.What’s the “male version” of the name “Jennifer”?

There are various ways one can do this.If you use the analogy engine from word2vec, finding the closest word to “Jennifer” + “he” – “she”, you get as your top 5:

Which is a better list of “male analogues of Jennifer?”Matthew is certainly closer to Jennifer in word2vec distance:

>>> model.similarity(‘Jennifer’,’Matthew’)

0.61308109388608356

>>> model.similarity(‘Jennifer’,’David’)

0.56257556538528708

But, for whatever, reason, “David” is coded as much more strongly male than “Matthew” is; that is, it is closer to “he” – “she”.(The same is true for “man” – “woman”.)So “Matthew” doesn’t score high in the first list, which rates names by a combination of how male-context they are and how Jennifery they are.A quick visit to NameVoyager shows that Matthew and Jennifer both peaked sharply in the 1970s; David, on the other hand, has a much longer range of popularity and was biggest in the 1950s.

Let’s do it again, for Susan.The two methods give

David, Robert, Mark, Richard, John

Robert, Jeffrey, Richard, David, Kenneth

And for Edith:

Ernest, Edwin, Alfred, Arthur, Bert

Ernest, Harold, Alfred, Bert, Arthur

Pretty good agreement!And you can see that, in each case, the selected names are “cultural matches” to the starting name.

Sidenote:In a way it would be more natural to project wordspace down to the orthocomplement of “he” – “she” and find the nearest neighbor to “Susan” after that projection; that’s like, which word is closest to “Susan” if you ignore the contribution of the “he” – “she” direction. This is the operation Ben Schmidt calls “vector rejection” in his excellent post about his word2vec model trained on student evaluations.

If you do that, you get “Deborah.”In other words, those two names are similar in so many contextual ways that they remain nearest neighbors even after we “remove the contribution of gender.”A better way to say it is that the orthogonal projection doesn’t really remove the contribution of gender in toto.It would be interesting to understand what kind of linear projections actually make it hard to distinguish male surnames from female ones.

Google News is a big enough database that this works on non-English names, too.The male “Sylvie”, depending on which protocol you pick, is

Alain, Philippe, Serge, Andre, Jean-Francois

or

Jean-Francois, Francois, Stephane, Alain, Andre

The male “Kyoko” is

Kenji, Tomohiko, Nobuhiro, Kazuo, Hiroshi

or

Satoshi, Takayuki, Yosuke, Michio, Noboru

French and Japanese speakers are encouraged to weigh in about which list is better!

Update: Even a little more messing around with “changing the gender of words” in a followup post.

Hey I keep saying this and now Allison Schrager has written an article about it for Bloomberg. Tenure is a form of compensation. If you think tenure is a bad way to pay teachers, and that compensation is best in the form of dollars, that’s fine; but if California pretends that the elimination of tenure isn’t a massive pay cut for teachers, they’re making a basic economic mistake.

New “hot hand” paper by Brett Green and Jeffrey Zweibel, about the hot hand for batters in baseball. They say it’s there! And they echo a point I make in the book (which I learned from Bob Wardrop) — some of the “no such thing as the hot hand” studies are way too low-power to detect a hot hand of any realistic size.

How sexual are you? (super important question)
How much fun are you? (people are surprisingly honest when asked this)
How awesome do you smell? (might need to invent technology for this one)
What bothers you more: the big bank bailout or the idea of increasing the minimum wage?
Do you like strong personalities or would you rather things stay polite?
What do you love arguing about more: politics or aesthetics?
Where would you love to visit if you could go anywhere?
Do you want kids?
Dog person or cat person?
Do you sometimes wish the girl could be the hero, and not always fall for the hapless dude at the end?

I gotta say, thinking back to when I was single, during the second Clinton administration, I don’t think these are the questions I personally would most want to ask of my prospective dates.

On the other hand, I think the questions provide a near-perfect portrait of Cathy! So let me offer my own suggestion: maybe profiles shouldn’t have any answers. Maybe they should just have questions. And you contact the person whose questions you’d like to answer.

What would your questions be?

Share this:

Like this:

The quality of streaming conference talks has improved a ton, to the point where it’s now really worthwhile to watch them, albeit not the same as being there. Our graduate students and I have been getting together and watching some of the talks from the soiree of the season, the MSRI perfectoid spaces conference. This has been great and I highly recommend it.

One good thing about watching at home is that you can stop the stream whenever anybody has a question, or whenever you want to expand on a point made by the speaker! We usually spend 90-100 minutes to watch an hour talk. One amusing phenomenon: when we have a question or don’t understand something, we stop and talk it out. Then, when we start the stream again, we usually see that the speaker has also stopped, because someone in the audience has asked the same question. This is very reassuring to the graduate students! What’s confusing to us is invariably also confusing to someone else, even to Brian Conrad, because we decided to always presume that the unseen, unheard questioner was Brian, which is pretty safe, right? (One time we could sort of hear the question and I’m pretty sure it was Akshay, though.)