In short:
from nltk import precision
In the long
It's complicated. The problem arose because NLTK was packaged. If we look at dir(nltk.metrics) , there is nothing inside it except alignment_error_rate
>>> import nltk >>> dir(nltk.metrics) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'alignment_error_rate']
BTW, in the NLTK version with a short release, alignment_error_rate moved to nltk.translate.metrics , see https://github.com/nltk/nltk/blob/develop/nltk/translate/metrics.py#L10 . The nltk.translate package nltk.translate bit unstable because it is still under development.
Returning to the metrics package, https://github.com/nltk/nltk/blob/develop/nltk/metrics/__init__.py , we see the following:
from nltk.metrics.scores import (accuracy, precision, recall, f_measure, log_likelihood, approxrand) from nltk.metrics.confusionmatrix import ConfusionMatrix from nltk.metrics.distance import (edit_distance, binary_distance, jaccard_distance, masi_distance, interval_distance, custom_distance, presence, fractional_presence) from nltk.metrics.paice import Paice from nltk.metrics.segmentation import windowdiff, ghd, pk from nltk.metrics.agreement import AnnotationTask from nltk.metrics.association import (NgramAssocMeasures, BigramAssocMeasures, TrigramAssocMeasures, ContingencyMeasures) from nltk.metrics.spearman import (spearman_correlation, ranks_from_sequence, ranks_from_scores)
basically, it means that the functions from the metrics package were manually encoded and nltk.metrics.__init__.py to nltk.metrics.__init__.py . Therefore, if import stops here, dir(metrics) , he would list all the indicators imported here.
But since at a higher level in nltk.__init__.py https://github.com/nltk/nltk/blob/develop/nltk/__init__.py#L131 , the packages were imported with:
from nltk.metrics import *
Now all metrics metrics have been imported to the top level, which you can do:
>>> from nltk import precision >>> from nltk import spearman_correlation >>> from nltk import NgramAssocMeasures
But you can still access any middleware modules that are inside nltk.metrics that are not imported into nltk.metrics.__init__.py . But you must use the correct namespaces as a save function in the appropriate directory. Note that they will not appear in dir(nltk.metrics) , but they are valid ways to import a function:
>>> from nltk.metrics import spearman >>> from nltk.metrics import paice >>> from nltk.metrics import scores <function precision at 0x7fb584a34938> >>> scores.precision >>> spearman.spearman_correlation <function spearman_correlation at 0x7fb5842b3230> >>> from nltk.metrics.scores import precision >>> precision <function precision at 0x7fb584a34938>