【问题标题】:Modifying warnings that seems to come from nowhere修改似乎不知从何而来的警告
【发布时间】:2018-08-06 11:29:09
【问题描述】:

我派生了一个名为 rasa_nlu 的存储库来处理我要修改的部分代码:在文件 model.py 中的函数 train(...) 内有一个函数 component.train(...),这似乎会触发警告而没有提供起源,我想找到触发它的原因。

基本上它将此函数应用于组件列表:

[<rasa_nlu.utils.spacy_utils.SpacyNLP object at 0x7f3abbfbd780>, <rasa_nlu.tokenizers.spacy_tokenizer.SpacyTokenizer object at 0x7f3abbfbd710>, <rasa_nlu.featurizers.spacy_featurizer.SpacyFeaturizer object at 0x7f3abbfbd748>, <rasa_nlu.featurizers.regex_featurizer.RegexFeaturizer object at 0x7f3abbd1a630>, <rasa_nlu.extractors.crf_entity_extractor.CRFEntityExtractor object at 0x7f3abbd1a748>, <rasa_nlu.extractors.entity_synonyms.EntitySynonymMapper object at 0x7f3abbd1a3c8>, <rasa_nlu.classifiers.sklearn_intent_classifier.SklearnIntentClassifier object at 0x7f3abbd1a240>]

似乎最后一个触发了警告。

我尝试在存储库的components.py 文件中修改函数train(),但它没有改变任何东西,所以我怀疑它不是正确的。

无论如何这里是文件model.py中的代码train(...)

...

import rasa_nlu
from rasa_nlu import components, utils, config
from rasa_nlu.components import Component, ComponentBuilder
from rasa_nlu.config import RasaNLUModelConfig, override_defaults
from rasa_nlu.persistor import Persistor
from rasa_nlu.training_data import TrainingData, Message
from rasa_nlu.utils import create_dir, write_json_to_file

...

class Trainer(object):
    """Trainer will load the data and train all components.

    Requires a pipeline specification and configuration to use for
    the training."""

    # Officially supported languages (others might be used, but might fail)
    SUPPORTED_LANGUAGES = ["de", "en"]

    def __init__(self,
                 cfg,  # type: RasaNLUModelConfig
                 component_builder=None,  # type: Optional[ComponentBuilder]
                 skip_validation=False  # type: bool
                 ):
        # type: (...) -> None

        self.config = cfg
        self.skip_validation = skip_validation
        self.training_data = None  # type: Optional[TrainingData]

        if component_builder is None:
            # If no builder is passed, every interpreter creation will result in
            # a new builder. hence, no components are reused.
            component_builder = components.ComponentBuilder()

        # Before instantiating the component classes, lets check if all
        # required packages are available
        if not self.skip_validation:
            components.validate_requirements(cfg.component_names)

        # build pipeline
        self.pipeline = self._build_pipeline(cfg, component_builder)

    ...

    def train(self, data, **kwargs):
        # type: (TrainingData) -> Interpreter
        """Trains the underlying pipeline using the provided training data."""
        self.training_data = data

        context = kwargs  # type: Dict[Text, Any]

        for component in self.pipeline:
            updates = component.provide_context()
            if updates:
                context.update(updates)

        # Before the training starts: check that all arguments are provided
        if not self.skip_validation:
            components.validate_arguments(self.pipeline, context)

        # data gets modified internally during the training - hence the copy
        working_data = copy.deepcopy(data)
        for i, component in enumerate(self.pipeline):
            logger.info("Starting to train component {}"
                        "".format(component.name))
            component.prepare_partial_processing(self.pipeline[:i], context)
            print("before train")
            updates = component.train(working_data, self.config,
                                      **context)
            logger.info("Finished training component.")
            print("before updates")
            if updates:
                context.update(updates)
        return Interpreter(self.pipeline, context)

输出是

before train
before updates
before train
before updates
before train
before updates
before train
before updates
before train
before updates
before train
before updates
before train
Fitting 2 folds for each of 6 candidates, totalling 12 fits
/home/mike/Programming/Rasa/myflaskapp/rasaenv/lib/python3.5/site-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)
/home/mike/Programming/Rasa/myflaskapp/rasaenv/lib/python3.5/site-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)
/home/mike/Programming/Rasa/myflaskapp/rasaenv/lib/python3.5/site-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)
/home/mike/Programming/Rasa/myflaskapp/rasaenv/lib/python3.5/site-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)
/home/mike/Programming/Rasa/myflaskapp/rasaenv/lib/python3.5/site-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)
/home/mike/Programming/Rasa/myflaskapp/rasaenv/lib/python3.5/site-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)
[Parallel(n_jobs=1)]: Done  12 out of  12 | elapsed:    0.1s finished
before updates
trainer.persist:

你可以在这里看到我想要捕捉和修改的警告以了解来源UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples.

因此,您能看到这些警告来自哪里吗?什么需要sklearn/metrics/classification.py

【问题讨论】:

    标签: python-3.x warnings rasa-nlu


    【解决方案1】:

    这是 Rasa NLU 存储库中记录的问题。我建议您关注这些问题或在那里添加您的 cmets 以解决问题。一个被标记为需要帮助,这意味着他们正在寻找社区贡献来解决它。

    关于为什么从上面链接的第一个问题中出现警告的 tl:dr:

    所以警告只是一个警告。这表明一个/一些意图的训练示例太少。添加更多示例将解决此问题(这就是为什么添加重复项会删除此警告,但实际上您应该添加不同的示例)。

    如果您希望警告消失,请添加更多训练数据。使用evaluation.py 脚本查找缺少的意图。

    从警告消息中可以看出它是从sklearn/metrics/classification.py 生成的,即这个文件here

    【讨论】:

    • 感谢您的参考。听起来很酷,我绝对想显示缺少足够训练示例但仍未找到触发的意图名称classification.py
    • 我会看这里,它正在训练意图分类,它正在使用 sklearn github.com/RasaHQ/rasa_nlu/blob/master/rasa_nlu/classifiers/…
    • 是的,没错,似乎是_create_classifier 函数中的GridSearchCV 是罪魁祸首。当我们调用它的fit 函数时,它会发出警告。我将尝试根据意图捕捉警告
    猜你喜欢
    • 2017-04-04
    • 1970-01-01
    • 2020-06-21
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    • 2017-08-31
    • 2015-12-01
    相关资源
    最近更新 更多