title: Show label probability/confidence in NLTK
body: <p>I'm using the MaxEnt classifier from the Python NLTK library. For my dataset, I have many possible labels, and as expected, MaxEnt returns just one label. I have trained my dataset and get about 80% accuracy. I've also tested my model on unknown data items, and the results are good. However, for any given unknown input, I want to be able to print/display a ranking of all the possible labels based on some internal criteria MaxEnt used to select the one, such as confidence/probability. For example, suppose I had <code>a,b,c</code> as possible labels and I use <code>MaxEnt.classify(input)</code>, I get currently one label, let's say <code>c</code>. However, I want to be able to view something like <code>a (0.9), b(0.7), c(0.92)</code>, so I can see why <code>c</code> was selected, and possibly choose multiple labels based on those parameters. Apologies for my fuzzy terminology, I'm fairly new to NLP and machine learning.</p>
  
  <p><strong>Solution</strong></p>
  
  <p>Based on the accepted answer, here's a skeleton code example to demonstrate what I wanted and how it can be achieved. More classifier examples on the <a href="http://www.nltk.org/book/ch06.html" rel="nofollow">NLTK website</a>.</p>
  
  <pre><code>import nltk
  
  contents = read_data('mydataset.csv')
  data_set = [(feature_sets(input), label) for (label, input) in contents] # User-defined feature_sets() function
  train_set, test_set = data_set[:1000], data_set[1000:]
  labels = [label for (input, label) in train_set]
  maxent = nltk.MaxentClassifier.train(train_set)
  maxent.classify(feature_sets(new_input)) # Returns one label
  multi_label = maxent.prob_classify(feature_sets(new_input)) # Returns a DictionaryProbDist object
  for label in labels:
      multi_label.prob(label)
  </code></pre>