The Technology Behind Wolfram|Alpha

Øyvind Tafjord

Wolfram Alpha LLC

Outline

• What is Wolfram|Alpha?
• A brief history of Wolfram|Alpha
• Wolfram|Alpha and Mathematica
• Anatomy of a Wolfram|Alpha query
• Interpreting the input
• Generating the output
• Adding content and knowledge to Wolfram|Alpha
• Wolfram|Alpha weekly deployment
• The future of Wolfram|Alpha

Goal of the talk: Give a flavor of how Wolfram|Alpha actually works and how it draws on the diverse capabilities of Mathematica in a multitude of facets.

What is Wolfram|Alpha?

Wolfram|Alpha is a "computational knowledge engine". There are three core parts to this:

1) Wolfram|Alpha stores computational representations of the human knowledge gathered throughout history, from facts and real world data to sophisticated formulas and algorithms.

2) Wolfram|Alpha uses a free form input line as an accessible interface to this overwhelming amount of functionality.

3) Combining the interpretation of the input with the knowledge repository, Wolfram|Alpha can generate multiple relevant outputs to shed light on the query.

Let's see some examples of this:

• Facts and real world data: 
    electron mass      	
    population canada        
    weather lillehammer february 1994
    $150 in euros
    resistor black red green silver
    king of norway in 1984
    
• Formulas and algorithms: 
    mortgage $200000    
    4x^5 - 3x^3 + 2x^2 + 1 = 0
    3/4/2005 - 2/1/2006
    NACA 0012 airfoil at 30 degrees
    216.38859428824222
    g (n+1) = n^2+g (n)
    
• Free form input interface:
    Integrate[Sin[x],{x,0,3Pi}]
    int sinx from 0 to 3pi
    what is the integral from x=0 to 3π of sine (x) dx?
   
• Output multiple relevant outputs:
    [[all of the above]] 
    HDL vs vitamin D serum
    metals melting point vs density
    ford vs GM
    AAGCTAGCTAGC

Some other perspectives on Wolfram|Alpha:

• Wolfram|Alpha can apply this knowledge in performing computations without expert knowledge on the part of the user, and give back relevant information the user might not have directly asked for:

• The knowledge is complemented by real time world data (weather, finance, ...)

• From a Mathematica user's perspective: Free form syntax interface to Mathematica functionality

• Wolfram|Alpha addresses the problem of creating a system with ever expanding features, without bloating the user interface to something unusable with gazillions of menus/wizards/taskbars/etc (back to the command line!)

• Wolfram|Alpha hopes to help bring the world of knowledge, facts and computation to "everybody", not just the experts in each fields.

Progress in science and technology is achieved by "standing on the shoulders of giants", using the collective insights gathered by the generations that came before us. Wolfram|Alpha wants capture these insights in a way that is usable to everybody, empowering them to make their own use of this knowledge, perhaps helping in making it easier to keep building the tower of true knowledge.

A brief history of Wolfram|Alpha

First there was Mathematica... 
Mathematica is also a repository of human knowledge and data, but with strict input syntax and well defined output.

A precursor of Wolfram|Alpha was the Integrator website (integrals.wolfram.com) which allowed "sloppy" inputs like "sinx + cos x^2" and would return the integral of that function.

Around the time of Mathematica 6, the idea came up to make a more general version of the Integrator site, where one important component was thinking of this as a "sloppy input interface" to Mathematica.

Wolfram|Alpha started its life in the NKS "Special Projects" group, at first as an experimental project of limited scope. But as progress was made and the paradigm seemed to fit more and more types of content, it quickly started growing in all kinds of ways.

After reasonable initial proof-of-concept success with math and dates, we moved to units, datapaclets, formulas and beyond.

We tried to release Wolfram|Alpha at a "sweet spot" in the development.  Although it wasn't "finished", we also wanted user feedback to help guide future development (partly to prioritize the unlimited ideas and plans for improvements we have generated for ourselves). The hope was that we launched something that the world would find useful, and that seems to be the case.

Wolfram|Alpha and Mathematica

The code base of Wolfram|Alpha is basically all related to Mathematica and other Wolfram Research products. The core computational engine is essentially a gigantic Mathematica application package which gets called from webMathematica. The development environment for the code is Wolfram Workbench.


In addition, Mathematica is also used throughout the support processes involved in making the complete product:
  • Content gathering and management
  • User interfaces for curating data
  • Analysis and processing of difficult disambiguation tasks
  • Example generation
  • Testing interfaces, both for generating tests and for analyzing results
  • Analysis and reporting on the web site query logs, feeding back into development

In return, Wolfram|Alpha has been a rigorous test for Mathematica and webMathematica. 

The current Wolfram|Alpha website is running pretty much an out-of-the box Mathematica 7.0.1.

Wolfram|Alpha and Mathematica functionality will continue to feed off each other.

Anatomy of a Wolfram|Alpha query

• Users enter their input in a browser (through the input field and assumptions). E.g., "convert 17 pounds to kg".

• webMathematica receives the input and feeds it to the Wolfram|Alpha parser.

Parse["convert 17 pounds to kg", options...]

• The output of the parser is a Mathematica symbolic representation of the input, together with various metadata (about assumptions, etc):

HoldComplete[ConvertUnits[Quantity[17,Unit[Pounds]],Quantity[None,Unit[Kilograms]]]]

• The parse is evaluated:

ConvertUnits[Quantity[17,Unit[Pounds]],Quantity[None,Unit[Kilograms]]]

• All the information is passed to result "scanners" which can generate additional results (extra unit conversions, etc).

• The results are formatted for presentation using a heavily overloaded TraditionalForm:

TraditionalForm[HoldForm[ConvertUnits[Quantity[17,Unit[Pounds]],Quantity[None,Unit[Kilograms]]]]]

TraditionalForm[ConvertUnits[Quantity[17,Unit[Pounds]],Quantity[None,Unit[Kilograms]]]]

• The formatted results are packaged up by webMathematica and sent to the user's browser (using AJAX for parallel CPU usage).

• If no parse or results are found, instead generate "fall through" content ("Did you mean...", dynamic examples "animal casa").

Interpreting the input

Principles:

• Flexible, modular overall parser, allowing multiple parsing paradigms to mix (chart parsing, shift-reduce parsing, bag-of-words, arbitrary token generation, ...)

• Allow extreme ambiguity throughout parse (try all possibilities)

• Resolve ambiguity by pruning and ranking throughout the parse, as well as at the end. Generate appropriate assumptions.

• Allow more aggressive sloppiness if no direct interpretation is found.

• If more information is needed to generate a result, ask user specific questions (extra input fields)

• Use metadata like user's location to generate better results ("Springfield", C vs F in output)

The flexible programming paradigms in Mathematica makes it very suitable for developing code of this sort. A brand new subparser can be written and plugged in with little effort. 


The unifying power of everything being represented by a Mathematica symbolic expressions cannot be overstated.

Generating the output

Principles:

• Fast dispatch to individual "scanners" based on patterns in the symbolic expression from the parse, as well as the evaluated version.

• Use well defined internal functions that naturally preserve enough structure to allow evaluation chains of nested queries (all part of the pattern matching paradigms of DownValues etc in Mathematica).

• Use centralized well-defined frameworks for handling large classes of outputs, such as the various datapaclets. It takes experience to make the "correct" frameworks.

• Use of TimeConstrained and other techniques to limit the amount of computation attempted on each part of the output.

• Use of heuristics and logic to determine relevance and validity of possible results.

• Heavy overloading of TraditionalForm/InputForm formatting rules to generate the output for the site.

Quantity[123456789,Unit[Meters]]//TraditionalForm

Quantity[123456789,Unit[People]]//TraditionalForm

And it's all basically just Mathematica:

PropertyClassPod[ElementData,"Iron","Material"]

Adding content and knowledge to Wolfram|Alpha

The "frameworks": Units, formulas, datapaclets, math, ad hoc, ...

• Getting and curating data. Notebook interfaces to processing and cleaning up data, flows through a database to deployed product.

• Textbooks and handbooks get processed into relevant formulas, grammar rules, output code

Dynamic interplay between adding content into existing frameworks and improving them or adding new ones.

The details of the knowledge representation data structure go to the heart of Wolfram|Alpha functionality, and ripples through to details in the input parsing and output generation code.

Some of the knowledge is stored in datapaclet-like structures:

AstronomicalData["Mercury","Mass"]

but within a larger unified structure:

DisplayData[AstronomicalData,"Mercury","Mass"]//TraditionalForm

and with extra bells and whistles that we are still rapidly developing.

Other types of knowledge ends up directly in Mathematica functions:

UnitLookup[Furlongs, "UnitValue"]

FormulaLookup["OhmsLaw","SolveFunction"]

and then there is of course all the Mathematica functions written to represent algorithms and calculations of various types.

Wolfram|Alpha weekly deployment

In addition to the near-continuous stream of data updates, a new Wolfram|Alpha code base has been deployed to the website every week since two weeks after the launch. This relies on a determined release team that is responsible for building, testing and deploying the new code. 

Testing Wolfram|Alpha is particularly challenging, due to the wide variety of possible inputs and the somewhat unstable nature of the output.

The future of Wolfram|Alpha

There are a lot of things on the horizon, both in terms of challenges and opportunities:

We want to significantly improve the quality of the input interpretation code - both through incremental and dramatic changes in the code base. This is a major ongoing R&D project.

Similarly, we are working on deeper and more general designs for computational data representation, storage and retrieval, to open up more types of queries and dealing with more kinds of data (inhomogenous, messy, multi-source, ...).

New deployment channels for the core Wolfram|Alpha engine (API, iPhone app, corporate data, widgets, ...).

Keep plugging in more knowledge and data and improving the frameworks for doing so.


What is Wolfram|Alpha doing in 5 years? It is very hard to tell...