NLP and Knowledge Statistics

Semantics is a funny thing. All professionals come to know that communication with their peers and outside audiences requires accuracy in how to express things. Yet, even with such attentiveness, communications sometimes go awry. It turns out that background, perspective and context can all act to switch circuits at the point of communication. Despite, and probably because of, our predilection as a species to classify and describe things, all from different viewpoints, we can often exhort in earnest a thought that is communicated to others as something different from what we intended. Alas! This reality is why, I suspect, we have embraced as a species things like dictionaries, thesauri, encyclopedias, specifications, standards, sacred tracts, and such, in order to help codify what our expressions mean in a given context. So, yes, while sometimes there is sloppiness in language and elocution, many misunderstandings between parties are also a result of difference in context and perspective. It is important when we process information in order to identify relations or extract entities, to type them or classify them, or to fill out their attributes, that we have measures to gauge how well our algorithms and tests work, all attentive to providing adequate context and perspective. These very same measures can also tell us whether our attempts to improve them are working or not. These measures, in turn, also are the keys for establishing effective gold standards and creating positive and negative training sets for machine learning. Still, despite their importance, these measures are not always easy to explain or understand. And, truth is, sometimes these measures may also be mis-explained or mis-calculated. Aiding the understanding of important measures in improving the precision, completeness, and accuracy of communications is my purpose in this article. Some Basic Statistics as Typically Described The most common scoring methods for gauging the “accuracy” of natural language communications involves statistical tests based on the nomenclature of negatives and positives, true or false. Sometimes it can be a bit confusing about how to interpret these terms, a confusion which can be made all the more difficult in what kind of statistical environment is at play. Let me try to first confuse, and then more simply explain these possible nuances. Standard science is based on a branch of statistics known as statistical hypothesis testing. This is likely the statistics that you were taught in school. In hypothesis testing, we begin with a hypothesis about what might be going on with respect to a problem or issue, but for which we do not know the cause or truth. After reviewing some observations, we formulate a hypothesis that some factor A is affecting or influencing factor B. We  then formulate a mirror-image null hypothesis that specifies that factor A does not affect factor B; this is what we will actually test. The null hypothesis is what we assume the world in our problem context looks like, absent our test. If the test of our formulated hypothesis does not affect that assumed distribution, then we reject our alternative (meaning our initial hypothesis fails, and we keep the null explanation). We make assumptions from our sample about how the entire population is distributed, which enables us to choose a statistical model that captures the shape of assumed probable results for our measurement sample. These shapes or distributions may be normal (bell-shaped or Gaussian), binomial, power law, or many others. These assumptions about populations and distribution shapes then tell us what kind of statistical test(s)</a> to perform. (Misunderstanding the true shape of the distribution of a population is one of the major sources of error in statistical  analysis.) Different tests may also give us more or less statistical power</a> to test the null hypothesis, which is that chance results will match the assumed distribution. Different tests may also give us more than one test statistic to measure variance from the null hypothesis. We then collect and measure our sample from the population, with random</a> or other statistical sampling</a> important so as not to skew results, and compare the distribution of these results to our assumed model and test statistic(s). The null hypothesis is confirmed or not by whether the shape of our sampled results matches the assumed distribution or not. The significance</a> of the variance</a> from the assumed shape, along with a confidence interval</a> based on our sample size and the test at hand, provides the information necessary to either accept or reject the null hypothesis. Rejection of the null hypothesis generally requires both significant difference from the expected shape in our sample and a high level of confidence. Absent those results, we likely need to accept the null hypothesis, thus rejecting the alternative hypothesis that some factor A is affecting or influencing factor B. Alternatively, with significant differences and a high level of confidence, we can reject the null hypothesis, thereby accepting the alternative hypothesis (our actual starting hypothesis, which prompted the null) that factor A is affecting or influencing factor B. This is all well and good except for the fact that either the sampling method or our test may be in error. There are two types of errors</a> that are possible: Type I errors, where a positive result corresponds to rejecting the null hypothesis; and Type II errors, where a negative result corresponds to not rejecting the null hypothesis. We can combine all of these thoughts into what is the standard presentation for capturing these true and false, positive and negative, results [1]</a>: Clear as mud, huh? Let’s Apply Some Simplifications Fortunately, there are a couple of ways to sharpen this standard story in the context of information retrieval</a> (IR), natural language processing</a> (NLP) and machine learning</a> (ML) — the domains of direct interest to us at Structured Dynamics</a> — to make understanding all of this much simpler. Statistical tests will always involve a trade off between the level of false positives (in which a non-match is declared to be a match) and the level of false negatives (in which an actual match is not detected) [1]</a>. Let’s see if we can simplify our recognition and understanding of these conditions. First, let’s start with a recent explanation from the KDNuggets Web site [2]</a>: “Imagine there are 100 positive cases among 10,000 cases. You want to predict which ones are positive, and you pick 200 to have a better chance of catching many of the 100 positive cases. You record the IDs of your predictions, and when you get the actual results you sum up how many times you were right or wrong. There are four ways of being right or wrong:<ol><li>TN / True Negative: case was negative and predicted negative</li><li>TP / True Positive: case was positive and predicted positive</li><li>FN / False Negative: case was positive but predicted negative</li><li>FP / False Positive: case was negative but predicted positive.”</li></ol> The use of ‘case’ and ‘predictions’ help, but are still a bit confusing. Let’s hear another explanation from Benjamin Roth from his recently completed thesis [3]</a>: “There are two error cases when extracting training data: false positive and false negative errors. A false positive match is produced if a sentence contains an entity pair for which a relation holds according to the knowledge base, but for which the sentence does not express the relation. The sentence is marked as a positive training example for the relation, however it does not contain a valid signal for it. False positives introduce errors in the training data from which the relational model is to be generalized. For most models false positive errors are the most critical error type, for qualitative and quantitative reasons, as will be explained in the following. “A false negative error can occur if a sentence and argument pair is marked as a negative training example for a relation (the knowledge base does not contain the argument pair for that relation), but the sentence actually expresses the relation, and the knowledge base was incomplete. This type of error may negatively influence model learning by omitting potentially useful positive examples or by negatively weighting valid signals for a relation.” In our context, we can see a couple of differences from traditional scientific hypothesis testing. First, the problems we are dealing with in IR, NLP and ML are all <a href="http://en.wikipedia.org/wiki/Statistical_classification">statistical classification</a> problems, specifically in <a href="http://en.wikipedia.org/wiki/Binary_classification">binary classification</a>. For example, is a given text token an entity or not? What type amongst a discrete set is it? Does the token belong to a given classification or not? This makes it considerably easier to posit an alternative hypothesis and the shape of its distribution. What makes it binary is the decision as to whether a given result is correct or not. We now have a different set of distributions and tests from more common normal distributions. Second, we can measure our correct ‘hits’ by applying our given tests to a “<a href="http://en.wikipedia.org/wiki/Gold_standard_%28test%29">gold standard</a>” of known results. This gold standard provides a representative sample of what our actual population looks like, one we have characterized in advance whether all results in the sample are true or not for the question at hand. Further, we can use this same gold standard over and over again to gauge improvements in our test procedures. Combining these thoughts leads to a much simpler matrix, sometimes called a <a href="http://en.wikipedia.org/wiki/Confusion_matrix">confusion matrix</a> in this context, for laying out the true and false, positive and negative characterizations: As we can see, ‘positive’ and ‘negative’ are simply the assertions (predictions) arising from our test algorithm of whether or not there is a match or a ‘hit’. ‘True’ and ‘false’ merely indicate whether these assertions proved to be correct or not as determined by gold standards or training sets. A false positive is a false alarm, a “crying wolf”; a false negative is a missed result. Thus, all true results are correct; all false are incorrect. Key Information Retrieval Statistics Armed with these four characterizations — true positive, false positive, true negative, false negative — we now have the ability to calculate some important statistical measures. Most of these IR measures also have exact analogs in standard statistics, which I also note. The first metric captures the concept of coverage. In standard statistics, this measure is called <a href="http://en.wikipedia.org/wiki/Sensitivity_and_specificity">sensitivity</a>; in IR and NLP contexts it is called <a title="Precision and recall" href="http://en.wikipedia.org/wiki/Precision_and_recall#Definition_.28classification_context.29">recall</a>. Basically it measures the ‘hit’ rate for identifying true positives out of all potential positives, and is also called the <a href="http://en.wikipedia.org/wiki/True_positive_rate">true positive rate</a>, or TPR:<dl><dd><img src="http://upload.wikimedia.org/math/1/3/4/13435a42931645fb999e06c9d62629f6.png" alt="\mathit{TPR} = \mathit{TP} / P = \mathit{TP} / (\mathit{TP}+\mathit{FN})"></dd></dl> Expressed as a fraction of 1.00 or a percentage, a high recall value means the test has a high “yield” for identifying positive results. <a title="Precision and recall" href="http://en.wikipedia.org/wiki/Precision_and_recall">Precision</a> is the complementary measure to recall, in that it is a measure for how efficient whether positive identifications are true or not:<dl><dd><img src="http://upload.wikimedia.org/math/0/5/c/05c24c4d7ffa993d678081d8243d9ac8.png" alt="\text{precision}=\frac{\text{number of true positives}}{\text{number of true positives}+\text{false positives}}"></dd></dl> Precision is something, then, of a “ quality ” measure, also expressed as a fraction of 1.00 or a percentage. It provides a <a title="Positive predictive value" href="http://en.wikipedia.org/wiki/Positive_predictive_value">positive predictive value</a>, as defined as the proportion of the true positives against all the positive results (both true positives and false positives). So, we can see that recall gives us a measure as to the breadth of the hits captured, while precision is a statement of whether our hits are correct or not. We also see, as in the Roth quote above, why false positives need to be a focus of attention in test development, because they directly lower precision and efficiency of the test. This recognition that precision and recall are complementary and linked is reflected in one of the preferred overall measures of IR and NLP statistics, the F-score, which is the adjusted (beta) mean of precision and recall. The general formula for positive real β is:<dl><dd><img src="http://upload.wikimedia.org/math/2/7/5/275f55f1ad01fc85820bf09fd9ab2831.png" alt="F_\beta = (1 + \beta^2) \cdot \frac{\mathrm{precision} \cdot \mathrm{recall}}{(\beta^2 \cdot \mathrm{precision}) + \mathrm{recall}}">.</dd></dl> which can be expressed in terms of TP, FN and FP as:<dl><dd><img src="http://upload.wikimedia.org/math/f/c/1/fc1144ad3f2f554928f245022bac403e.png" alt="F_\beta = \frac {(1 + \beta^2) \cdot \mathrm{true\ positive} }{(1 + \beta^2) \cdot \mathrm{true\ positive} + \beta^2 \cdot \mathrm{false\ negative} + \mathrm{false\ positive}}\,"></dd></dl> In many cases, the <a title="Harmonic mean" href="http://en.wikipedia.org/wiki/Harmonic_mean#Harmonic_mean_of_two_numbers">harmonic mean</a> is used, which means a beta of 1, which is called the F1 statistic:<dl><dd><img src="http://upload.wikimedia.org/math/9/9/1/991d55cc29b4867c88c6c22d438265f9.png" alt="F_1 = 2 \cdot \frac{\mathrm{precision} \cdot \mathrm{recall}}{\mathrm{precision} + \mathrm{recall}}"></dd></dl> But F1 displays a tension. Either precision or recall may be improved to achieve an improvement in F1, but with divergent benefits or effects. What is more highly valued? Yield? Quality? These choices dictate what kinds of tests and areas of improvement need to receive focus. As a result, the weight of beta can be adjusted to favor either precision or recall. Two other commonly used F measures are the F2 measure, which weights recall higher than precision, and the F0.5 measure, which puts more emphasis on precision than recall <a href="http://www.mkbergman.com/#stat4">[4]</a>. Another metric can factor into this equation, though <a href="http://en.wikipedia.org/wiki/Accuracy_and_precision">accuracy</a> is a less referenced measure in the IR and NLP realm. Accuracy is the statistical measure of how well a <a title="Binary classification" href="http://en.wikipedia.org/wiki/Binary_classification">binary classification</a> test correctly identifies or excludes a condition:<dl><dd><img src="http://upload.wikimedia.org/math/8/5/f/85fb106488e3cb8c02e397c917222ad4.png" alt="\text{accuracy}=\frac{\text{number of true positives}+\text{number of true negatives}}{\text{number of true positives}+\text{false positives} + \text{false negatives} + \text{true negatives}}"></dd></dl> An accuracy of 100% means that the measured values are exactly the same as the given values. All of the measures above simply require the measurement of false and true, positive and negative<a href="http://en.wikipedia.org/wiki/Statistical_population">, as do a variety of</a><a href="http://en.wikipedia.org/wiki/Positive_and_negative_predictive_values">predictive values</a> and <a href="http://en.wikipedia.org/wiki/Likelihood_ratios_in_diagnostic_testing">likelihood ratios</a>. <a href="http://en.wikipedia.org/wiki/Relevance">Relevance</a>, <a href="http://en.wikipedia.org/wiki/Prevalence">prevalence</a> and <a href="http://en.wikipedia.org/wiki/Sensitivity_and_specificity">specificity</a> are some of the other notable measures that depend solely on these metrics in combination with <a href="http://en.wikipedia.org/wiki/Statistical_population">total population</a>. By bringing in some other rather simple metrics, it is also possible to expand beyond this statistical base to cover such measures as <a href="http://en.wikipedia.org/wiki/Entropy_estimation">information entropy</a>, <a href="http://en.wikipedia.org/wiki/Statistical_inference">statistical inference</a>, <a href="http://en.wikipedia.org/wiki/Pointwise_mutual_information">pointwise mutual information</a>, <a href="http://en.wikipedia.org/wiki/Variation_of_information">variation of information</a>, <a href="http://en.wikipedia.org/wiki/Uncertainty_coefficient">uncertainty coefficients</a>, <a href="http://en.wikipedia.org/wiki/Information_gain_ratio">information gain</a>, <a href="http://en.wikipedia.org/w/index.php?title=Area_under_the_curve&redirect=no"> AUC</a>s and <a href="accuracy_primer.html#%20%20http://en.wikipedia.org/wiki/Receiver_operating_characteristic"> ROC</a>s. But we’ll leave discussion of some of those options until another day. Bringing It All Together Courtesy of one of the major templates in Wikipedia in the statistics domain <a href="http://www.mkbergman.com/#stat5">[5]</a>, for which I have taken liberties, expansions and deletions, we can envision the universe of statistical measures in IR and NLP, based solely on population and positives and negatives, true and false, as being: Please note that the order and location of TP, FP , FN and TN differs from my simple layout presented in the confusion matrix above. In the confusion matrix, we are gauging whether the assertion of the test is correct or not as established by the gold standard. In this current figure, we are instead using the positive or negative status of the gold standard as the organizing dimension. Use the shorthand identifiers of TP, etc., to make the cross reference between “correct” and “condition”. Relationships to Gold Standards and Training Sets These basic measures and understandings have two further important roles beyond informing how to improve the accuracy and peformance of IR and NLP algorithms and tests. The first is gold standards. The second is training sets. Gold standards that themselves contain false positives and false negatives, by definition, immediately introduce errors. These errors make it difficult to test and refine existing IR and NLP algorithms, because the baseline is skewed. And, because gold standards also often inform training sets, errors there propagate into errors in machine learning. It is also important to include true negatives in a gold standard, in the likely ratio expected by the overall population, so that this complement of the accuracy measurement is not overlooked. Once a gold standard is created, you then run your current test regime against it when you run your same tests againt unknowns. Preferably, of course, the gold standard only includes true positives and true negatives (that is, the gold standard is the basis for judging “correctness'; see confusion matrix above). In the case of running an entity recognizer, your results against the gold standard can take one of three forms: you either have open slots (no entity asserted); slots with correct entities; or slots with incorrect entities. Thus, here is how you would create the basis for your statistical scores:<ul><li> TP = test identifies the same entity as in the gold standard</li><li> FP = test identifies a different entity than what is in the gold standard (including no entity)</li><li> TN = test identifies no entity; gold standard has no entity, and</li><li> FN = test identifies no entity, but gold standard has one.</li></ul> As noted before, these measures are sufficient to calculate the precision, recall, F-score and accuracy statistics. Also note that the F v T and P v N correspond to the gold standard “correctness” and what is asserted by the test(s), per the confusion matrix. We can apply this same mindset to the second additional, important role in creating and evaluating training sets. Both positive and negative training sets are recommended for machine learning. Negative training sets are often overlooked. Again, if the learning is not based on true positives and negatives, then significant error may be introduced into the learning. Clean, vetted gold standards and training sets are thus a critical component to improving our knowledge bases going forward <a href="http://www.mkbergman.com/#stat6">[6]</a>. The very practice of creating gold standards and training sets needs to receive as much attention as algorithm development because, without it, we are optimizing algorithms to fuzzy objectives. The virtuous circle that occurs between more accurate standards and training sets and improved IR and ML algorithms is a central argument for <a href="http://www.mkbergman.com/category/kbai/">knowledge-based artificial intelligence</a> (KBAI). Continuing to iterate better knowledge bases and validation datasets is a driving factor in improving both the yield and quality from our rapicly expanding knowledge bases.<hr style="margin: 15px 0px;" align="left" size="1" width="33%"> <a id="stat1" name="stat1"></a>[1] See <a href="http://en.wikipedia.org/wiki/Type_I_and_type_II_errors#Type_II_error">http://en.wikipedia.org/wiki/Type_I_and_type_II_errors</a>. <a id="stat2" name="stat2"></a>[2] Tilmann Bruckhaus, 2015. “<a href="http://www.kdnuggets.com/faq/precision-recall.html">How Are Precision and Recall Calculated</a>?” from the KDNuggets Web site, retrieved May 10, 2015. <a id="stat3" name="stat3"></a>[3] Benjamin Roth, 2014. “<a href="http://scidok.sulb.uni-saarland.de/volltexte/2015/5983/pdf/thesis_finale_fassung.pdf">Effective Distant Supervision for End-To-End Knowledge Base Population Systems</a>,” D Engineering Thesis, Saarland University ; quote is on p 33. <a id="stat4" name="stat4"></a>[4] See <a href="http://en.wikipedia.org/wiki/F1_score">http://en.wikipedia.org/wiki/F1_score</a>. <a id="stat5" name="stat5"></a>[5] See <a href="http://en.wikipedia.org/wiki/Template:DiagnosticTesting_Diagram">http://en.wikipedia.org/wiki/Template:DiagnosticTesting_Diagram.</a> <a id="stat6" name="stat6"></a>[6] Some would also argue for adequate gold standards in the ontology realm. See Dellschaft, Klaas, and Steffen Staab. “<a href="http://www.researchgate.net/profile/Steffen_Staab/publication/220017530_On_How_to_Perform_a_Gold_Standard_Based_Evaluation_of_Ontology_Learning/links/004635241364e6eeec000000.pdf">On how to perform a gold standard based evaluation of ontology learning</a>.” In T he Semantic Web-ISWC 2006 , pp. 228-241. Springer Berlin Heidelberg, 2006. For ontologies, they state it “. . . is apparent that there does not exist a canonical way of performing gold-standard based evaluations of ontology learning. Moreover, we argue in this paper that existing gold-standard based evaluations are faulty and that a well-founded evaluation model is largely missing.”